3.1. Line-follower


A line follower is a robot which is designed to follow a line on a given surface. Usually robots follow a:

  • black line on a white surface
  • white line on a black surface

There's a typical line-follower track seen in Figure 1.

Figure 1. Basic track

How does it work?

In order to follow a line the robot needs to be able to detect it first. That is achieved with an array of sensors, in our case infrared (IR) reflectance sensors.

How the line is detected?

Sensors measure the reflectance of the ground below them. Depending on the surface, more or less light is reflected. In other words the amount of light reflected differentiates the black line from the white background.

If the surface is:

  • white ⇒ more light reflected
  • black ⇒ less light reflected

After the robot detects the line it has to decide if it should turn left / right or drive straight.

If the robot loses sight of the line it should initiate a procedure to find the line again. Usually driving in an outward spiral should do it.

The 3pi robot comes with five IR sensors arranged in an arc with a radius equal to the distance between the center of rotation and the front of the robot.

To summarize the robot has to do three steps in a loop:

  1. detect line
  2. decide what to do
  3. turn left / right, drive straight / outward spiral

Simple algorithm

In our particular case we will follow a black line on a white surface.

The 3pi robot has five sensors (an array of sensors), which can be numbered from 0 to 4. The black line has the lowest reflectance so it’s easy to detect under which sensor the line is.

To be able to follow the line the robot has to:

  • read the array of sensors and detect under which sensor the line is
  • decide which way it has to go

In pseudo-code the program would look like this, assuming that read_sensors will return the sensor number under which the line is located.

   line_position = read_sensors();
   if( line_position == 0 || line_position  == 1)   /* if one of the left sensors detected the line turn left */
   if( line_position == 2 )                         /* if the line is under the middle sensor drive straight */
   if( line_position == 3 || line_position  == 4)   /* if one of the right sensors detected the line turn right */


roboticsisfun/chapter3/ch3_1_line_follower.txt · Last modified: 2012/11/12 02:35 by liviu.radoi