User Tools

Site Tools


marvin:lab5

Lab report 5

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

The purpose of this exercise is to make a line following robot to compete in the robot race.

Design

lab5-schema.jpg
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

lab5-arm1.jpglab5-arm2.jpg
The base of the car is the LEGO 9797 car as described in LEGO Mindstorms Education NXT Base Set 9797 building instruction page 32 to page 34 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

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. First time trial, 31,8 sec

Here is a video showing the test run:
lab6-1.jpg

Test2

lab5-bigwheels.jpg
Larger wheels First time trial, 25,0 sec

Test3

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

Conclusion

We need to do some measurements on the motors in order to examine how to make different types of turns. Next time we will try to do countersteering by making one motor go forward and the other one backward. Also try to implement a memory of the last samples, so we will be able to take advantage of a more graduated steering control.

marvin/lab5.txt · Last modified: 2008/10/10 11:54 by deva