Giter Club home page Giter Club logo

cardemo's Introduction

CarDemo

Processing sketches to simulate a robotic car.

API for the Car object

Car has the following methods that may be useful:

Car(int x, int y, float theta)

This constructor method allows you to place a car on the canvas pointing in the direction of angle. The directions work with 0 as directly up and move in in a clockwise manner.

void setLeftSpeed(int s)

Set the speed of the left motor to an integer from 0 to 255.

void setRightSpeed(int s)

Set the speed of the left motor to an integer from 0 to 255.

void LEDSense()

Have the readings of the left and right sensors loaded into sensorValueRight and sensorValueLeft.

void show()

Draw the car on the canvas.

void move()

Compute the new position of the car based on the motor settings.

DriveSystem

DriveSystem is basically an abstract class that needs to be subclassed to create a strategy for how the car is to move. This set up is to emulate an autonomous car.

There is one main method, void drive(). Below is a sample drive method. In this case we want to have the car move forward and then turn to the right, and then repeat those actions.

void drive() {
    //override me.
    if (noSense==0) {
      if (approach==0) {
        myCar.setLeftSpeed(30);
        myCar.setRightSpeed(30);
        approach=1;
        setNoSense(40);        
      } 
      else if (approach==1) {
        myCar.setLeftSpeed(5);
        myCar.setRightSpeed(-5);
        setNoSense(30);
        approach=0;
      }
    }
    noSense--;
  }

approach is a class variable that allows you to indicate which settings you would like to employ.

setNoSense is a way to create a delay before the drive function determines another action. Basically actions are only taken when noSense is equal to 0.

In general you should use this template for your drive

class MyDrive extends DriveSystem{
  
  MyDrive(Car mCar) {
    super(mCar);
  }
  
  void drive() {
    //override me.
    if (noSense==0) {
      if (approach==0) {
        // Put some stuff here for what to do first.
        
        // setNoSense to make it so that state continues for some period of time
        setNoSense(40);        
      } 
      else if (approach==1) {
        // Put some stuff here for what to do at another time indicated by approach 0.
        
        // setNoSense to make it so that state continues for some period of time
        setNoSense(30);
        
      }
    }
    noSense--;
  }
}

cardemo's People

Contributors

mbardoe avatar

Watchers

 avatar  avatar

cardemo's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.