Nothing Special   »   [go: up one dir, main page]

Line Follower

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

A little bit of theory: Basic line following

How can we make a robot follow a black line on a white background?


There are several solutions, but with only one Color sensor (used as a Light sensor) the simplest solution is probably
to make it follow one of the edges of the line. Because the line has thickness, we can program the robot to follow the
line in such a way that when the sensor sees white, the robot makes a point turn (a turn with a stopped wheel)
towards black, and when it sees black it does the opposite turn. This algorithm is called a two-step simple line
follower because it only has two actions. In addition, it demonstrates how the combination of small local movements,
apparently nonsense (turns to the right or to the left), imply a global movement with a very special sense, in this case
following the line. To program this algorithm, we just need a Switch block set to Color sensor mode (to make the robot
turn to each side), inside a Loop.

Two-step simple line following algorithm


If we study how a two-step simple line follower works, as shown in the image below, we can ask ourselves how many
times the program passes through each one of the switch options before changing the option, while the time loop of
our example lasts.

Two-step simple line


follower with one color sensor, with Motor blocks

Two-step simple line follower


with one color sensor, with Move Tank block
In the previous examples the motors are configured with 30% power, to avoid swerve movements, and the time loop
runs for 10 seconds. The Switch block is associated with the Color sensor in the Compare Reflected Light Intensity
mode. In the next example, the Color sensor uses the Measure Color mode to measure the color.

Two-step simple line follower


with one color sensor, with Measure Color mode
Tip: When using the Color sensor with the Measure Color mode to measure the color, it is important to select the
Switch default case, for example, the white color. We can also select No Color as default in such a way that any
detected color by the Color sensor not being black will execute this case. How will the robot behave if we do not
configure the No Color case as default? Well, since you need to select a default case, the only other option will be to
select the black color case, thus the program will always execute this branch, even while detecting white, because any
detected color is different from No Color! It is important that the students make tests to understand how the Switch
block works.
At this point it is important to make the students give their opinion about whats happening inside the Loop and, for
example, make them replicate the robot behavior with their body. We will see that the majority of them do not clearly
understand how the algorithm operates. For example, they may not fully appreciate that as the robot moves from one
color to the other, the program will execute the same option or branch of the Switch many times, until the robot moves
onto the other side many faster than the robots apparent physical execution of the Loop. The following exercises
show how the Switch inside the Loop algorithm works for the two-step simple line follower with one Color sensor.

You might also like