Follow a line: Difference between revisions
(Marked this version for translation) |
|||
Line 2: | Line 2: | ||
<translate> | <translate> | ||
=== Introduction === | === Introduction === <!--T:1--> | ||
<!--T:2--> | |||
There a multiple different methods (algorithms) to follow a line. We show two simplest methods (which can be coded with a huge variety), also [[Viivanseuraaja zigzag ev3-g |''zig zag'' linefollower]] and [[Viivanseuraaja verrannollinen ev3-g | | There a multiple different methods (algorithms) to follow a line. We show two simplest methods (which can be coded with a huge variety), also [[Viivanseuraaja zigzag ev3-g |''zig zag'' linefollower]] and [[Viivanseuraaja verrannollinen ev3-g | | ||
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. | 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 === | === Robot === <!--T:3--> | ||
<!--T:4--> | |||
Any robot (with tires or treads, perhaps walking robots too) will work. | Any robot (with tires or treads, perhaps walking robots too) will work. | ||
=== Sensors === | === Sensors === <!--T:5--> | ||
<!--T:6--> | |||
One light sensor or color sensor is needed. | One light sensor or color sensor is needed. | ||
Some of the exercises requires two sensors. | Some of the exercises requires two sensors. | ||
=== Example Videos === | === Example Videos === <!--T:7--> | ||
<!--T:8--> | |||
<youtube>DN2prlLoyPo</youtube> | <youtube>DN2prlLoyPo</youtube> | ||
<!--T:9--> | |||
<youtube>kVce9k_e6OI</youtube> | <youtube>kVce9k_e6OI</youtube> | ||
=== Theory === | === Theory === <!--T:10--> | ||
<!--T:11--> | |||
These algorithms follow the border of the line, not the line. | These algorithms follow the border of the line, not the line. | ||
==== Calibration ==== | ==== Calibration ==== <!--T:12--> | ||
<!--T:13--> | |||
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. | 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 ==== <!--T:14--> | ||
<!--T:15--> | |||
''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. | ''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. | ||
<!--T:16--> | |||
[[File:Zigzag.png|thumb|''The Zig Zag'' algorithm.]] | [[File:Zigzag.png|thumb|''The Zig Zag'' algorithm.]] | ||
==== Proportional ==== | ==== Proportional ==== <!--T:17--> | ||
<!--T:18--> | |||
[[File:LinefollowerProp.png|thumb]] | [[File:LinefollowerProp.png|thumb]] | ||
<!--T:19--> | |||
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 <math>c=50</math> the robot will go straight. Define a steering function | 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 <math>c=50</math> the robot will go straight. Define a steering function | ||
<!--T:20--> | |||
<math>s(c) = 2c - 100</math>. | <math>s(c) = 2c - 100</math>. | ||
<!--T:21--> | |||
It is clearly seen, that | It is clearly seen, that | ||
{| class="sortable" | {| class="sortable" | ||
Line 58: | Line 71: | ||
The coefficient is <math>2</math> 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 | The coefficient is <math>2</math> 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 | ||
<!--T:22--> | |||
<math>s(c) = k(c-50)</math> | <math>s(c) = k(c-50)</math> | ||
<!--T:23--> | |||
which allows to test different steering coefficients <math>k</math>. This is easy to implement in Ev3-G programming language. | which allows to test different steering coefficients <math>k</math>. This is easy to implement in Ev3-G programming language. | ||
=== Example Code === | === Example Code === <!--T:24--> | ||
==== Zig Zag ==== | ==== Zig Zag ==== <!--T:25--> | ||
<!--T:26--> | |||
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. | 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. | ||
<!--T:27--> | |||
[[File:Zigzag.png|thumb|Zigzag algorithm]] | [[File:Zigzag.png|thumb|Zigzag algorithm]] | ||
==== Proportional ==== | ==== Proportional ==== <!--T:28--> | ||
<!--T:29--> | |||
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 <math>c</math> to determine the speed of the turn. | 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 <math>c</math> to determine the speed of the turn. | ||
<!--T:30--> | |||
[[File:Proportional.png|thumb|The proportional Line Follower code. The code is much shorter and perhaps easier to understand, if the maths can be understood.]] | [[File:Proportional.png|thumb|The proportional Line Follower code. The code is much shorter and perhaps easier to understand, if the maths can be understood.]] | ||
=== Exercises === | === Exercises === <!--T:31--> | ||
<!--T:32--> | |||
* Use the other side of the line to follow the line | * 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 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 | ||
Line 88: | Line 108: | ||
<!--T:33--> | |||
This course is supported by [https://meet-and-code.org/ Meet and Code]. The course is made in collaboration with [http://www.fllsuomi.org/ Robotiikka- ja tiedekasvatus ry]. | This course is supported by [https://meet-and-code.org/ Meet and Code]. The course is made in collaboration with [http://www.fllsuomi.org/ Robotiikka- ja tiedekasvatus ry]. | ||
[[File:MeetAndcodeLogo.png|thumb]] | [[File:MeetAndcodeLogo.png|thumb]] |
Latest revision as of 21:21, 14 September 2020
<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>