International Robot Competition - Rules - Sample Robots - Lego EV3 Trajectory Robot. Lego EV3. Black line movement Line movement with steering wheel in ev3

15.01.2012, 18:51

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.

Therefore, it is a good idea to equip the robot with two sensors at once, which are located on opposite sides of the line and, accordingly, would help the robot respond more quickly to a change in direction of movement.
Now it is necessary to determine how such a design change will affect the program. For simplicity, we should again start with the simplest relay controller, and therefore, first of all, we are interested in the possible positions of the sensors relative to the line:

In fact, one more acceptable state can be singled out - on difficult routes it will be the intersection of an intersection or some kind of thickening on the path.
Other positions of the sensors will not be considered, because they are either derived from those shown above, or these are the positions of the robot when it left the line and will no longer be able to return to it using information from the sensors. As a result, all of the above provisions can be reduced to the following classification:
  • the left sensor, as well as the right one, is above a light surface
  • left sensor above light surface, right sensor above dark
  • left sensor above dark surface, right sensor above light
  • both sensors are above the dark surface
If at a certain point in time the program on the robot detects one of these positions, it will have to react accordingly:
    If both sensors are above the white surface, then this is a normal situation in which the line is between the sensors, so the robot must go straight. If the left sensor is still above the light surface, and the right sensor is already above the dark one, then the robot drove its right side onto the line, which means he needs to turn to the right so that the line is again between the sensors. If the left sensor is above the dark surface, and the right one is still above the light one, then the robot needs to turn to the left to align. If both sensors are above the dark surface, then in the general case, the robot again keeps going straight.

The diagram above immediately shows how exactly the behavior of the motors should change in the program. Now, writing a program should not be difficult. You should start by choosing which sensor will be polled first. It doesn't really matter, so let it be left. It is necessary to determine whether it is over a light or dark surface:
This action does not yet allow you to say in which direction the robot should go. But it will divide the states listed above into two groups: (I, II) for the upper branch and (III, IV) for the lower. Each of the groups now has two states, so you need to select one of them. If you look closely at the first two states I and II, they differ in the position of the right sensor - in one case it is above a light surface, in the other - above a dark one. This is what will determine the choice of what action to take:
Now you can insert blocks that define the behavior of the motors according to the tables above: the upper branch of the nested condition defines the combination "both sensors on light", the upper one - "left on light, right on dark":
The lower branch of the main condition is responsible for another group of states III and IV. These two states also differ from each other in the level of illumination that the right sensor picks up. So it will determine the choice of each of them:
The resulting two branches are filled with movement blocks. The upper branch is responsible for the "left on dark, right on light" state, and the lower branch is responsible for "both sensors on dark".
It should be noted that this design only determines how to turn on the motors depending on the readings of the sensors in a certain place in the field, naturally, after a moment, the program must check whether the readings have changed in order to correct the behavior of the motors accordingly, and after a moment again, again, and so on. .d. Therefore, it should be placed in a loop that will provide this repeated check:

Such a rather simple program will provide a fairly high speed of the robot moving along the line without overshooting its limits, if you correctly set the maximum speed when moving in states I and IV, and also set the optimal method of braking in states II and III - the steeper the turns on the track , the "harder" the braking should be - the speed should drop faster, and vice versa - with smooth turns, it is quite possible to apply braking through turning off the energy or even through a slight drop in speed.

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.



In order to make the robot move smoothly along the black line, you need to make it calculate the speed of movement itself.

A person sees a black line and its clear boundary. The light sensor works a little differently.

It is this property of the light sensor - the inability to clearly distinguish between the border of white and black - that we will use to calculate the speed of movement.

First, let's introduce the notion “Ideal point of the trajectory”.

The readings of the light sensor range from 20 to 80, most often on white, the readings are about 65, on black, about 40.

The ideal point is a conditional point approximately in the middle of white and black colors, following which the robot will move along the black line.

Here, the location of the dot is fundamental - between white and black. It will not be possible to set it exactly on white or black for mathematical reasons, why - it will be clear later.

Empirically, we have calculated that the ideal point can be calculated using the following formula:

The robot must move strictly along the ideal point. If a deviation occurs in either direction, the robot must return to that point.

Let's compose mathematical description of the problem.

Initial data.

Perfect point.

The current readings of the light sensor.

Result.

Motor power B.

Motor rotation power C.

Solution.

Let's consider two situations. First: the robot deviated from the black line towards the white.

In this case, the robot must increase the rotation power of motor B and decrease the power of motor C.

In a situation where the robot drives into the black line, the opposite is true.

The more the robot deviates from the ideal point, the faster it needs to return to it.

But the creation of such a regulator is a rather difficult task, and it is not always required in its entirety.

Therefore, we decided to confine ourselves to a P-regulator that adequately responds to deviations from the black line.

In the language of mathematics, this would be written as:

where Hb and Hc are the total powers of motors B and C, respectively,

Hbase - a certain base power of the motors, which determines the speed of the robot. It is selected experimentally, depending on the design of the robot and the sharpness of the turns.

Itech - current readings of the light sensor.

I id - calculated ideal point.

k is the coefficient of proportionality, selected experimentally.

In the third part, we will look at how to program this in the NXT-G environment.

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 value of white 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 changes in illumination, which can lead to 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


To view a presentation with pictures, design, and slides, download its file and open it in PowerPoint on your computer.
Text content of presentation slides:
“Algorithm for moving along a black line with one color sensor” Circle on “Robotics” Teacher before Yezidov Ahmed Elievich At MBU DO “Shelkovskaya CTT” To study the algorithm for moving along a black line, a Lego Mindstorms EV3 robot with one color sensor will be used Color sensor Color sensor distinguishes 7 colors and can detect the absence of color. As in the NXT, it can work as a light sensor. Line S Robot Competition Field The proposed "S" shaped track will allow you to conduct another interesting test of the created robots for speed and reaction. Let's consider the simplest algorithm for moving along a black line on one 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 left and right and gradually moving forward The algorithm is very simple : if the sensor sees black, then the robot turns in one direction, if it sees white - in the other direction. Tracing a Line in Reflected Light Mode with Two SensorsSometimes the color sensor may not be able to distinguish between black and white very well. The solution to this problem is to use the sensor not in color detection mode, but in reflected light brightness detection mode. In this mode, knowing the values ​​of the sensor on a dark and light surface, we can independently say what will be considered white and what will be black. Now let's determine the brightness values ​​on the white and black surfaces. To do this, in the menu of the EV3 Brick we find the "Brick Applications" tab. Now you are in the port view window and you can see the readings of all sensors at the current moment. our sensors should glow red, which means they are in reflected light detection mode. If they shine blue, in the port view window on the desired port, press the center button and select the COL-REFLECT mode. Now we will place the robot so that both sensors are located above the white surface. We look at the numbers in ports 1 and 4. In our case, the values ​​are 66 and 71, respectively. These will be the white values ​​​​of the sensors. Now let's place the robot so that the sensors are located above the black surface. Again, let's look at the values ​​​​of ports 1 and 4. We have 5 and 6, respectively. These are the meanings of black. Next, we will modify the previous program. Namely, we change the settings of the switches. As long as they have Color Sensor -> Measurement -> Color installed. We need to set the Color Sensor -> Comparison -> Reflected Light Intensity Now we need to set the "comparison type" and "threshold value". The threshold value is the value of some "gray", the values ​​below which we will consider black, and more - white. For the first approximation, it is convenient to use the average value between the white and black of each sensor. Thus, the threshold value of the first sensor (port #1) will be (66+5)/2=35.5. Round up to 35. Threshold value of the second sensor (port #4): (71+6)/2 = 38.5. Let's round up to 38. Now we set these values ​​in each switch, respectively. That's all, the blocks with movements remain in their places unchanged, because if we put the sign " in the "comparison type"<», то все, что сверху (под галочкой) будет считаться черным, а снизу (под крестиком) – белым, как и было в предыдущей программе.Старайтесь ставить датчики так, чтобы разница между белым и черным была как можно больше. Если разница меньше 30 - ставьте датчики ниже. Это было краткое руководство по программированию робота Lego ev3, для движения по черной линии, с одним и двумя датчиками цвета

Control algorithms for a mobile LEGO robot. Line tracking with two light sensors

Teacher of additional education

Kazakova Lyubov Alexandrovna


Line movement

  • Two light sensors
  • Proportional controller (P controller)

Algorithm for moving along the black line without a proportional controller

  • Both motors spin with the same power
  • If the right light sensor hits the black line, then the power of the left motor (for example B) decreases or stops
  • If the left light sensor hits the black line, then the power of the other of the motors (for example, C) decreases (returns to the line), decreases or stops
  • If both sensors are on white or black, then there is a rectilinear movement

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


  • The proportional controller (P-controller) allows you to adjust the behavior of the robot, depending on how much its behavior differs from the desired one.
  • The more the robot deviates from the target, the more force is needed to return to it.

  • The P-controller is used to keep the robot in a certain state:
  • Hold the position of the manipulator Move along a line (light sensor) Move along a wall (distance sensor)
  • Holding the position of the manipulator
  • Line motion (light sensor)
  • Moving along a wall (distance sensor)

Line tracking with one sensor

  • The goal is to move along the border "white-black"
  • A person can distinguish the border of white and black. The robot cannot.
  • The target for the robot is on the gray color

Crossings

When using two light sensors, it is possible to organize traffic on more difficult routes



Algorithm for driving along a highway with intersections

  • Both sensors on white - the robot drives in a straight line (both motors spin with the same power)
  • If the right light sensor hits the black line, and the left one on the white line, then it turns right
  • If the left light sensor hits the black line, and the right one hits the white line, then it turns left
  • If both sensors are on black, then a rectilinear movement occurs. You can count intersections or perform some kind of action


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)

  • C - target values ​​(take readings from the light sensor on white and black, calculate the average)
  • T - current value - received from the sensor
  • K is the sensitivity coefficient. The more, the higher the sensitivity.