Follow a line/fi

From wikiluntti
Revision as of 22:25, 14 September 2020 by Mol (talk | contribs) (Created page with "=== Anturit ===")

<languages/>

Introduction

Viivanseurantaan on hyvin paljon erilaisia tapoja eli algoritmeja. Tässä näytämme kaksi yksinkertaista menetelmää, jotka kummatkin voidaan koodata usealla eri tavalla. Menetelmät ovat nimeltään zig zag ja verrannollinen viivanseuranta.

Viivan voit piirtää isolle paperille tai vetämällä esimerkiksi teipillä viivan lattiaan. Helpoin viiva algoritmeille on sileä (tasainen), mutta viivassa voi tietenkin olla myös teräviä käännöksiä. Nämä algoritmit eivät huomaa, jos viiva leikkaa itseään.

Robotti

Lähes mikä tahansa liikkuva robotti toimii.

Anturit

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.

The Zig Zag algorithm.

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.

Zigzag algorithm

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.

The proportional Line Follower code. The code is much shorter and perhaps easier to understand, if the maths can be understood.

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.


Meet and Code I: Ev3-G