Follow a line
<languages/> <translate>
Introduction
There a multiple different methods (algorithms) to follow a line. We show two simplest methods (which can be coded with a huge variety), also zig zag linefollower and proportional line follower. See the linked pages for more references. The line can be drawn on a huge paper, or made by using black (or colored) tape. The easiest line is smooth, but it might contain very sharp turns. However, the line should not cut itself.
Robot
Any robot (with tires or treads, perhaps walking robots too) will work.
Sensors
One light sensor or color sensor is needed. Some of the exercises requires two sensors.
Example Videos
Theory
These algorithms follow the border of the line, not the line.
Calibration
The color sensor should be calibrated, either in the program using black and light reflectances, or by calibrating the values from the sensor. See the linked page for more information.
Zig Zag
Zig zag algorithm turns to right if sees white, and to left if the sensor is on the black. Or vice versa. The algorithm is easy to program using only one if block. The speed and turning value need to be considered and adjusted.
Proportional
The proportional line follower steers according to the value read from the color sensor. The sensor is assumed to be calibrated, so that at value the robot will go straight. Define a steering function
.
It is clearly seen, that
Does | ||
---|---|---|
0 | -100 | Steer left |
50 | 0 | Go straight |
100 | 100 | Steer right |
The coefficient is which makes the robot steer rapidly. You might wish to have smaller or larger steering effect depending on the path. The steering function can be generalized easily to
which allows to test different steering coefficients . This is easy to implement in Ev3-G programming language.
Example Code
Zig Zag
Zig Zag never drives straight. Either it turns to left or right. However, it can be made very fast, and reliable---of course depending on the line. The turning part is coded into if else block which is in the loop.
Proportional
The proportional code reads the reflected light intensity, and if it exactly 50 the robot drives forward. Otherwise it turns to left or right. There is a proportional constant to determine the speed of the turn.
Exercises
- Use the other side of the line to follow the line
- Make the robot to change the side of the line during the line following: Thus, after following the line e.g. 2 wheel rotations, use the other side of the line
- Make a robot with two color sensors, and use the information from the other sensor to stop the robot when the other sensor recognizes black line.
- Make a robot with two color sensors, and make the robot to follow a line that is in between the two sensors.
- Make a robot with two color sensors, and make the robot to follow first the line with left sensor, then after two wheel rotations use the other sensor to follow the line to the end.
This course is supported by Meet and Code. The course is made in collaboration with Robotiikka- ja tiedekasvatus ry.
</translate>