Lab 2: Line Following Hints

How to:

Method 1 (Hug the right boundary) :

  1. Build a differential drive robot using two motors - one for each wheel.
  2. Attach the LEGO NXT light sensor so that it faces down towards the ground.
  3. Write a program that does the following :
      i) If the sensor reading indicates a white line, move right.
      ii) If the sensor reading doesn't indicate a white line, move left.

Method 2 (Course correction) :

  1. Build a differential drive robot using two motors - one for each wheel.
  2. Attach the LEGO NXT light sensor so that it faces down towards the ground.
  3. Write a program that does the following :
      i) If the sensor reading doesn't indicate a white line stop.
        a) Rotate left inplace until a white line is found or for a specified time period. If a line is found goto (ii).
        b) Rotate right inplace until a white line if found or for twice the time period. If a line is found goto (ii).
        c) Otherwise, the robot has gone too far away from the line and must do something else to get back or just give up.
      ii) Drive straight.

Other tips:

  1. Consider starting your program with a sensor calibration where you can input your desired light / dark cutoff value. The ambient lighting will be constant and directional lighting will be such that issue like the robots shadow will be minimized. The starter code includes a function for this.
  2. Make sure that the light sensor is polled frequently and the PID update interval is small (around 10 - 20 ms) or else the robot may lose sight of the line and never get back.
  3. Don't make the robot move too fast.
  4. Enable motor teaming to make the robot go straight if needed.
  5. Go for a simple but solid design as this robot can also be used for the next four labs with minor modifications.
  6. Make the robot smaller than 6' x 6' not including the sensor if you plan on using the same design for labs 5 and 6.

Sample starter code: Code fragment for method 1 written in RobotC.


Last Updated : 10/16/07 by Kaushik Viswanathan
(c) 1999-2007: Howie Choset, Carnegie Mellon