• Secondary
  • Lesson 28: Line Following Robot Part 2

Lesson 28: Line Following Robot Part 2

Lesson Description

In this lesson, you will learn: the logic behind line following robots, how to code for them, how to calibrate them and how to use checkpoints.

LOGIC OF LINE FOLLOWING

The logic behind the working of a line-following robot is simple:

  1. First, we will set the left and right IR sensor threshold.
  2. If both the sensors are active, it means that the robot is at a crossroad and therefore must stop.
  3. If only the left sensor is active, this means that the robot is drifting towards its right and we need to bring it back on track. Therefore, we must make it move a little towards the left.
  4. If only the right sensor is active, this means that the robot is drifting towards its left. Therefore, we must make it move a little towards the right.
  1. If none of the sensors is active, it means that the black line is in between them and the robot is going in the right direction. Therefore, it should keep moving forward.
  2. Repeat steps 2-5.

There are 3 important things we will use in a line following robot:

  1. F: The speed with which the robot will move forward when it has not detected a black line.
  2. T1 & T2: When the robot is following the line and if one of the sensors say the left one, detects the black line, then the robot is off track and has to turn left in order to get back on the track. And we know how to turn the robot left. The left motor moves backward and the right move forward. But if both are moving at the same speed, then the robot’s motion will become jerky and inefficient. Hence, we will have two speeds for turning T1 and T2, where,
    • T1 will be the speed with which the motor will move forward and
    • T2 will be the speed with which the motor will move backward.
  3. We will have to set F, T1, and T2 during the programming and calibrate it for effective line following.

CODE FOR LINE FOLLOWER

  1. Create a New file in PictoBlox App.
  2. Connect Quarky to PictoBlox.
  3. Add a green flagblock in the scripting area and two set () IR sensor threshold to () blocks and set the left and right IR sensor thresholds.
  4. Go to the Robot palette and drag and drop a set parameter F (), T1 (), T2 () Set the parameters as default.
  5. Add a foreverblock below the set parameter F (), T1 (), T2 ()
  6. Now, from the Robotpalette, add a do line following block inside the forever block. This block will take care of ALL the line following conditions that we had to check individually in our previous script.
  7. Next, add a stoprobot block inside the do line following
  8. Now, place your robot on the track and run the script by clicking the green flag.

CALIBRATING THE ROBOT

We have to calibrate the robot’s F, T1, and T2 speeds to make it work efficiently. Let’s see what happens with the change of each parameter:

  1. F: This controls how fast the robot moves forward. If the robot is overshooting and does not follow the line, then decrease the value.
  2. T1 & T2: This controls how much the robot turns to get back on track. If they are less, then the robot might not get time to get back on track and if they are high then the robot will jerk a lot. You can see how the robot is turning too much in this case. You can keep the T2 speed between 0-20 and change the T1 to get the most appropriate result.

Calibrate the F, T1, and T2 parameters and remember them as well will use them in the coming lessons.

WHAT HAPPENS AT THE CHECKPOINTS?

As you would have noticed, the robot detects the checkpoints in the line follower block, we can do whatever we want at that checkpoint. Like in the previous code we made the robot stop on the checkpoint.

You can make the robot go forward as well to have it moving on the track without interruption like this:

Table of Contents