If you adhere to proper nutrition, then avocados are probably in ...
![Avocado Sandwiches: Recipes and Ingredients](https://i2.wp.com/glamusha.ru/uploads/articles/21/pp_buterbrody_s_avokado_na_zavtrak.jpg)
Control algorithms for a mobile LEGO robot. Line tracking with two light sensors
Teacher of additional education
Kazakova Lyubov Alexandrovna
Line movement
Algorithm for moving along the black line without a proportional controller
The movement is organized by changing the power of one of the motors
Example of a program for moving along the black line without a P-controller
The movement is organized by changing the angle of rotation
Line tracking with one sensor
Crossings
When using two light sensors, it is possible to organize traffic on more difficult routes
Algorithm for driving along a highway with intersections
The principle of operation of the P-regulator
Position of sensors
O=O1-O2
Algorithm for moving along the black line with a proportional controller
SW \u003d K * (C-T)
Until now, in articles about algorithms used when moving along a line, such a method was considered when the light sensor, as it were, followed its left or right border: as soon as the robot moved to the white part of the field, the controller returned the robot to the border, the sensor began to move deep into the black lines - the regulator straightened it back.
Despite the fact that the picture above is for a relay controller, the general principle of the movement of a proportional (P-regulator) will be the same. As already mentioned, the average speed of such a movement is not very high, and several attempts were made to increase it by slightly complicating the algorithm: in one case, "soft" braking was used, in the other, in addition to turns, forward movement was introduced.
In order to allow the robot to move forward in some areas, a narrow section was allocated in the range of values produced by the light sensor, which could be conditionally called "the sensor is on the border of the line." This approach has a small drawback - if the robot "follows" the left border of the line, then on the right turns it does not seem to immediately determine the curvature of the trajectory and, as a result, spends more time searching for the line and turning. Moreover, it is safe to say that the steeper the turn, the longer this search takes.
The following figure shows that if the sensor was located not on the left side of the border, but on the right side, then it would have already detected a curvature of the trajectory and would begin to make turn maneuvers.
![]() |
![]() |
A few separate words should also be said about the placement of sensors on the robot. Obviously, the same recommendations will apply to the location of these two sensors relative to the wheels as for one sensor, only the middle of the segment connecting the two sensors is taken as the vertex of the triangle. The very distance between the sensors should also be chosen from the characteristics of the track: the closer the sensors are located to each other, the more often the robot will level out (perform relatively slow turns), but if the sensors are spaced wide enough, then there is a risk of flying off the track, so you will have to perform tighter turns and slower movement on straights.
One of the basic movements in legoconstruction is following the black line.
The general theory and specific examples of creating a program are described on the site wroboto.ru
I will describe how we implement this in the EV3 environment, as there are differences.
The first thing the robot needs to know is the value of the “ideal point” located on the border of black and white.
The location of the red dot in the figure just corresponds to this position.
The ideal calculation option is to measure the value of black and white and take the arithmetic mean.
You can do it manually. But the cons are immediately visible: during even a short time, the illumination can change, and the calculated value will turn out to be incorrect.
So you can make a robot do it.
In the course of experiments, we found that it is not necessary to measure both black and white. Only white can be measured. And the value of the ideal point is calculated as the white value divided by 1.2 (1.15), depending on the width of the black line and the speed of the robot.
The calculated value must be written to a variable in order to access it later.
Calculation of the “ideal point”
The next parameter involved in the movement is the turn rate. The larger it is, the more sharply the robot reacts to changes in illumination. But too high a value will cause the robot to wobble. The value is selected experimentally individually for each robot design.
The last parameter is the base power of the motors. It affects the speed of the robot. An increase in the speed of movement leads to an increase in the response time of the robot to a change in illumination, which can lead to a departure from the trajectory. The value is also selected experimentally.
For convenience, these parameters can also be written to variables.
Steering ratio and base power
The logic of moving along the black line is as follows: the deviation from the ideal point is measured. The larger it is, the stronger the robot should strive to return to it.
To do this, we calculate two numbers - the power value of each of the motors B and C separately.
In formula form, it looks like this:
Where Isens is the value of the light sensor readings.
Finally, the implementation in EV3. It is most convenient to issue in the form of a separate block.
Implementation of the algorithm
This is the algorithm that was implemented in the robot for the middle category WRO 2015
This task is classical, ideologically simple, it can be solved many times, and each time you will discover something new.
There are many approaches to solve the line following problem. The choice of one of them depends on the specific design of the robot, on the number of sensors, their location relative to the wheels and each other.
In our example, three robot examples will be disassembled based on the main Robot Educator tutorial model.
To begin with, we assemble the basic model of the Robot Educator, for this you can use the instruction in the MINDSTORMS EV3 software.
Also, for examples, we need EV3 light-color sensors. These light sensors, like no other, are best suited for our task, when working with them, we do not have to worry about the intensity of the ambient light. For this sensor, in the programs we will use the reflected light mode, in which the amount of reflected light of the sensor's red illumination is estimated. The limits of the sensor readings are 0 - 100 units, for "no reflection" and "total reflection", respectively.
For example, we will analyze 3 examples of programs for moving along a black path depicted on an even, light background:
· One sensor, with P regulator.
· One sensor, with PK regulator.
· Two sensors.
The light sensor is mounted on a beam conveniently located on the model.
The operation of the algorithm is based on the fact that, depending on the degree of overlap, the sensor illumination beam with a black line, the readings returned by the sensor vary in a gradient. The robot keeps the position of the light sensor on the border of the black line. By converting the input data from the light sensor, the control system generates the value of the robot's turning speed.
Since on a real trajectory the sensor generates values in its entire operating range (0-100), the value to which the robot strives is 50. In this case, the values transmitted to the rotation function are formed in the range -50 - 50, but these values are not enough for a steep trajectory rotation. Therefore, the range should be expanded by one and a half times to -75 - 75.
Finally, in the program, the calculator function is a simple proportional controller. whose function ( (a-50)*1.5 ) in the operating range of the light sensor generates the rotation values in accordance with the graph:
This example is compiled on the same design.
You probably noticed that in the previous example, the robot swayed too much, which did not allow it to accelerate sufficiently. Now we will try to improve this situation a little.
To our proportional controller, we also add a simple cube controller, which will add a twist to the controller function. This will reduce the swinging of the robot near the desired boundary of the trajectory, as well as make stronger jerks at a great distance from it.
Let's consider the simplest algorithm for moving along a black line on a single color sensor on EV3.
This algorithm is the slowest, but the most stable.
The robot will not move strictly along the black line, but along its border, turning either to the left or to the right and gradually moving forward.
The algorithm is very simple: if the sensor sees black, then the robot turns in one direction, if white - in the other.
Implementation in the Lego Mindstorms EV3 environment
In both motion blocks, select the "enable" mode. The switch is set to the color sensor - measurement - color. At the bottom, don't forget to change "no color" to white. Also, you must correctly specify all ports.
Don't forget to add a loop, the robot won't go anywhere without it.
Check. For best results, try changing the steering and power settings.
Movement with two sensors:
You already know the algorithm for moving the robot along the black line using one sensor. Today we will consider the movement along the line using two color sensors.
The sensors must be installed in such a way that the black line runs between them.
The algorithm will be the following:
If both sensors see white, we move forward;
If one of the sensors sees white and the other black, we turn towards black;
If both sensors see black, we are at an intersection (for example, stop).
To implement the algorithm, we need to track the readings of both sensors, and only after that set the robot to move. To do this, we will use switches nested in another switch. Thus, we will poll the first sensor first, and then, regardless of the readings of the first, we will poll the second sensor, after which we will set the action.
Connect the left sensor to port #1, the right sensor to port #4.
Program with comments:
Do not forget that we start the motors in the "Enable" mode so that they work as long as necessary based on the readings of the sensors. Also, the need for a loop is often forgotten - without it, the program will immediately end.
http://studrobots.ru/
The same program for the NXT model:
Study the program of movement. Program the robot. Upload model test video