Line Following. Making it smoother Pro Preview

So far we have looked at an algorithm for line following that we will refer to as duck walking. Let us take a look at it and think about how many states it has.

To access the full video please subscribe to FLLCasts.com

Subscribe

  • #885
  • 30 Mar 2018

The line following program implementing the duck walking algorithm looks as follows:

and consists of two states:

  • If the color read is black - the robot turns to one side;
  • If the color read is white - the robot turns to the other side.

As you may imagine this is not very effective. The robot is constantly turning left or right and never going forward, even if the line is straight. This makes the algorithm slow and ineffective. Again, for the purposes of this example, we imagine that the robot is following the right edge of the line.

So, let us think about how we could add a state where the robot goes straight forward. The idea is to have three states:

  • turning left - when the robot is outside of the line:
  • turning right - when the robot is over the line:
  • going forward - when the robot is over the edge:

To achieve that, however, we cannot use the color mode of the color sensor, but instead, we need to use the reflected light mode. Let us say that we have measured the values the sensor reads on black, white and on the edge of the line and the values are as follows:

  • over the line -> 9
  • over the edge -> 32
  • outside of the line -> 55

The robot going straight forward only when the sensor reads 32 is pointless. That is why we will program the robot to go forward when the value read by the sensor is close to 32. Let us choose the acceptable error to be +/-5. So, when the value is between 27 and 37, the robot will go straight.

When the value is less than 27, the robot will turn right and when the value is greater than 37, it will turn left. So, having these thresholds, we can develop the following algorithm:

  • If the sensor reads a value less than 27, the robot is over the black line and needs to turn right;
  • If the sensor reads a value greater than 27, the robot is either over the edge or over white. To determine that, we need to make another evaluation by comparing the value to 37. If the value read is greater than 27 and less than 37, then the robot is over the edge and goes forward;
  • If the sensor reads a value greater than 37, the robot is over the white zone, so it needs to turn left;

Measure the values your robot reads over the three zones and try to implement the above algorithm. Try to split the task into simpler, smaller tasks.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Instructors Remote Training
  • 136
  • 280:11
  • 156
Image for Competition programming
  • 7
  • 0
  • 8
  • 3d_rotation 1
Image for Robotics with LEGO - Level 2.0 - Robots in Factories
  • 44
  • 15:01
  • 129
Image for Level C1. "Transportation". Robotics with LEGO
  • 33
  • 1:03
  • 110
Image for Robotics with LEGO - Level 2.0 - Robots in Factories
  • 44
  • 15:01
  • 129
Image for Lesson 5 - Robo Car
  • 6
  • 4
  • 11
  • 3d_rotation 1
Image for Stay @ Home SPIKE Prime Course
  • 4
  • 0:33
  • 27