Line Following 101 Pro Preview

When you hear the task “program the robot to follow a black line,” you’ll most likely imagine a program that works like this:

  • If the color sensor detects black (meaning the robot is over the line), the robot moves forward.
  • If the color sensor detects a different color (meaning the robot is not over the line), the robot turns toward the line.

To access the full video please subscribe to FLLCasts.com

Subscribe

  • #852
  • 30 Mar 2018

This program may seem logical and will probably work—at least at first. The first part, where the sensor detects black and the robot moves forward, is simple:

On the Line

However, the second part—when the sensor is no longer over the black line—is quite difficult, if not impossible to implement directly. Let's say the robot is to the right of the line:

Right of the Line

In this case, the robot needs to turn left to return to the line. Now, if the robot is on the left side of the line:

Left of the Line

It must turn right to return. That’s all good, but here’s the problem: the sensor values on both sides of the line (left and right) are very similar—sometimes even identical. So, the robot cannot tell which way to turn.

That’s why, when we say we're programming the robot to “follow the line,” we’re actually simplifying the truth. What the robot really does is follow one of the edges of the line.

Line with Edges The edge is an imaginary boundary between the black line and the background (shown here as red dashed lines). Every line has two edges—one on the left and one on the right.

When following an edge using only one color sensor, the robot can determine if it's on the left or right side of that edge. For example, if the robot is following the right edge of the black line:

  • If the sensor reads black, the robot is too far to the left of the edge and should turn right:

    On the Edge - Turn Right

  • If the sensor reads white, the robot is too far to the right and should turn left:

    Right of the Edge - Turn Left

So, the proper logic for following a black line should be: if the sensor reads black, turn right; otherwise, turn left. This decision-making process is continuously repeated in a loop.

Continue to the next exercises and try it out—see if your robot can follow the line correctly!

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Instructors Remote Training
  • 183
  • 280:11
  • 156
Image for Switch
  • 7
  • 0
  • 7
  • 3d_rotation 1
Image for Robotics with LEGO - Level 1.5 - Spy games
  • 56
  • 12:47
  • 136
Image for Instructors Remote Training
  • 183
  • 280:11
  • 156
Image for Competition programming
  • 7
  • 0
  • 8
  • 3d_rotation 1
Image for Level B2. "Military Technologies". Robotics with LEGO
  • 37
  • 6:37
  • 111
Image for Level B2. "Military Technologies". Robotics with LEGO
  • 37
  • 6:37
  • 111
Image for Lesson 6 - Line Following
  • 5
  • 3
  • 9
  • 3d_rotation 1
Image for Build, Code, Play: Your First Adventures with SPIKE Prime
  • 4
  • 0:33
  • 27