### Robotics and AI with Quarky

GETTING STARTED
ROBOTICS
Fun with Robots
Line Following Robot
TAKING LEARNING TO THE REAL WORLD
Robot Pet
CAPSTONE PROJECT

# ACTIVITY: Making a Line Follower Robot

## Making a Line Follower Robot – Overview

We now know all about line following robots – what they are and why they’re useful. Now, it’s time to make one of our own! We’ll first lay out the track, understand the logic, and then make a script in PictoBlox to watch it in action. Let’s begin.

## Laying Out the Track

Place the track on the ground. You will notice 3 perpendicular black lines on the track. We will use these in upcoming lessons as checkpoints.

## Understanding the Logic

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.
5. 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.
6. 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 it 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 moves forward. But if both are moving at the same speed, then the robot 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.

Now, let’s make the script for Quarky based on this logic.

## Let’s Code!

Let’s continue with the previous script that we have made while calibrating the IR Sensors. 1. Go to the My Blocks palette and create a block named LED Feedback. Two types of blocks will be created – one hat block and one stack block.

2. Drag and drop the two if-else blocks from the existing script under the LED Feedback hat block. 3. Place the LED Feedback stack block inside the forever block of the remaining script. Note: As the environmental factors like lights changes now and then, you need to calibrate the IR Sensors again and update the threshold values accordingly.
4. Add an if-else block below the LED Feedback stack block.
5. Go to the Operators palette and drop a () and () block inside the white diamond-shaped space of the block. This block will ensure that the blocks under the if arm will run only if both conditions are true.
6. Add an is () IR sensor active? block in the first and the second white spaces of the () and () block. Select IR-L and IR-R options in the first and the second block. 7. Now add stop robot block in the if branch as we want the robot to stop when this happens. 8. Add another if-else block under the else arm of the first if-else block.
9. In the if condition add is () IR sensor active? block and select IR-L as we want to check if the left sensor is active. 10. According to the logic, in this condition, we must move Quarky, a little towards its left. So, under the if arm, add two run () motor () with () % speed blocks. Change the motor to right in the first block and speed to 40% (T1).
11. In the second block for the left motor, change the direction to backward and reduce to speed to 25% (T2). Reducing the speed will ensure that the motor moves only a little left enough to get back on track. 12. Add another if-else block under the else arm of the second if-else block.
13. In the if condition add is () IR sensor active? block and select IR-R as we want to check if the right sensor is active.
14. According to the logic, in this condition, we must move Quarky, a little towards its right. So, under the if arm, add two run () motor () with () % speed blocks. Change the motor to left in the first block and speed to 40% (T1).
15. In the second block for the right motor, change the direction to backward and reduce to speed to 25% (T2). Reducing the speed will ensure that the motor moves only a little right enough to get back on track. 16. Next, under the else arm, add go () at ()% speed blocks and choose the direction as forward and speed as 40% (F). Now, place your robot on the track and run the script by clicking the green flag. ## Calibrating the Robot

The robot might not perform well with the speeds which we have set. That is where the calibration of the robot comes in.

We have to calibrate the F, T1, and T2 speeds in the robot 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.

×

Cart