User Tools

Site Tools


marvin:lab5

This is an old revision of the document!


Lab report 5

Date: October 3rd 2008
Duration of activity: 8-?.??
Participants: Kasper, Bent and Johnny

The purpose of this exercise is to make a line following robot to compete int eh robot race.

Design

picture_of_whiteboard_design
We wanted to produce a stable car that would be able to react fast to changes in the course.
The stability, we decided, could be achieved by building the car as a tripod, based on the standard Lego car.
The motors will be placed on the two front wheels, and the passive turning wheel will be placed in the back.
the idea is to build the car with three light sensors placed in front of the car. One in center, and two placed just outside the track (when it is straight).
This placement will enable us to use a strategy much like the homing strategy.

Building the car

picture_of_the_built_car
maale_armen1maale_armen2
We did not have three NXT light sensors available, so we decided to use the one that we did have for the center sensor, and then use two RCX light sensors for the ones on the sides.

Programming

TODO: Insert the code here.

public class Racer {
  private static RCXLightSensor ls_left; 
  private static RCXLightSensor ls_right; 
  private static LightSensor ls_center; 
 
  //  private static final int blue_nxt = 38;
  //  private static final int blue_rcx = 26;
  private static final int blue_nxt = 39;
  private static final int blue_rcx = 27;
  private static final int black_nxt = 33;
  private static final int black_rcx = 22;
  private static final int white_nxt = 50;
  private static final int white_rcx = 30;
  private static final int threshold = 5;
  private static final int bthreshold = 2;
 
  private static final int speed = 100;
  private static final int zspeed = 0;
 
  private static final int LEFT = -1;
  private static final int FORWARD = 0;
  private static final int RIGHT = 1;
  private static int direction = FORWARD;
 
  private static void init()
  {
    ls_left = new RCXLightSensor(SensorPort.S1);
    //    ls_left.setFloodlight(true);
 
    ls_center = new LightSensor(SensorPort.S2);
    ls_center.setFloodlight(true);
 
    ls_right = new RCXLightSensor(SensorPort.S3);
    //    ls_right.setFloodlight(true);
  }
 
  private static boolean isBlueNXT(int value)
  {
    return value > blue_nxt - bthreshold && value < blue_nxt + bthreshold;
  }
 
  private static boolean isBlueRCX(int value)
  {
    return value > blue_rcx - bthreshold && value < blue_rcx + bthreshold;
  }
 
  private static boolean isBlackNXT(int value)
  {
    return value > black_nxt - threshold && value < black_nxt + threshold;
  }
 
  private static boolean isBlackRCX(int value)
  {
    return value > black_rcx - threshold && value < black_rcx + threshold;
  }
 
  private static boolean isWhiteNXT(int value)
  {
    return value > white_nxt - threshold && value < white_nxt + threshold;
  }
 
  private static boolean isWhiteRCX(int value)
  {
    return value > white_rcx - threshold && value < white_rcx + threshold;
  }
 
  private static void panic()
  {
    LCD.drawString("AAAAAAAAARGH!", 0, 0);
  }
 
  private static void driveLeft()
  {
    LCD.drawString("driving left", 0, 0);
    if(direction == LEFT) Car.left(speed);
    else Car.forward(speed, 0);
    //Car.left(speed);
    direction = LEFT;
  }
 
  private static void driveRight()
  {
    LCD.drawString("driving right", 0, 0);
    if(direction == RIGHT) Car.right(speed);
    else Car.forward(0, speed); 
    //Car.right(speed);
    direction = RIGHT;
  }
 
  private static void driveForward()
  {
    LCD.drawString("driving forward", 0, 0);
    Car.forward(speed, speed);
    direction = FORWARD;
  }
 
  private static void driveStop()
  {
    LCD.drawString("stop", 0, 0);
    Car.stop();
  }
 
  public static void main(String [] args)  throws Exception {
    LCD.drawString("Lets RACE...!", 0, 0);
 
    int left = 0;
    int center = 0;
    int right = 0;
 
    init();
 
    while (! Button.ESCAPE.isPressed()) {
 
      // Read value from ligth sensors
      left = ls_left.readValue();
      center = ls_center.readValue();
      right = ls_right.readValue();
 
      // Print 'em
      LCD.drawInt(left, 0, 1);
      LCD.drawInt(center, 0, 2);
      LCD.drawInt(right, 0, 3);
 
      // Figure out where to go next
      if(isBlueRCX(left) && isBlueNXT(center) && isBlueRCX(right)) driveStop();
      else if(isBlackRCX(left) && isBlackNXT(center) && isBlackRCX(right)) panic();
      else if(isBlackRCX(left) && isBlackNXT(center)) driveLeft();
      else if(isBlackNXT(center) && isBlackRCX(right)) driveRight();
      else if(isBlackNXT(center)) driveForward();
      else if(isBlackRCX(left)) driveLeft();
      else if(isBlackRCX(right)) driveRight();
 
      //Thread.sleep(200);
      LCD.clear();
    }
    Car.stop();
 
  }
}

Test1

small wheels. movie of first run. First time trial, 31,8 sec

Test2

Larger wheels First time trial, 25,0 sec

Test3

Reduced lengt of the sensor arm. Caused Marvin to turn to late and crash into the wall. Therefore we maintain original length of the sensor arm.

Conclusion

marvin/lab5.1223030585.txt.gz · Last modified: 2008/10/03 12:43 by deva