User Tools

Site Tools


marvin:lab5

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
marvin:lab5 [2008/10/03 12:41] riepermarvin:lab5 [2008/10/03 12:52] rieper
Line 1: Line 1:
 ===== Lab report 5===== ===== Lab report 5=====
 **Date:** October 3rd 2008\\ **Date:** October 3rd 2008\\
-**Duration of activity:** 8-?.??\\+**Duration of activity:** 8-13\\
 **Participants:** Kasper, Bent and Johnny\\  **Participants:** Kasper, Bent and Johnny\\ 
  
Line 21: Line 21:
 ====Programming==== ====Programming====
 TODO: Insert the code here. TODO: Insert the code here.
 +<code java>
 +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();
 +
 +  }
 +}
 +</code>
 ====Test1==== ====Test1====
 small wheels. small wheels.
Line 31: Line 171:
 First time trial, 25,0 sec First time trial, 25,0 sec
  
-====Test2====+====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. 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====
 +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