Advanced algorithm for moving along the line. Line motion with two light sensors Smooth line motion 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.



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

The text of the work is placed without images and formulas.
The full version of the work is available in the "Job Files" tab in PDF format

Lego Mindstorms EV3

Preparatory stage

Creating and calibrating a program

Conclusion

Literature

1. Introduction.

Robotics is one of the most important areas of scientific and technological progress, in which the problems of mechanics and new technologies come into contact with the problems of artificial intelligence.

In recent years, advances in robotics and automated systems have changed the personal and business areas of our lives. Robots are widely used in transportation, earth and space exploration, surgery, military industry, laboratory research, security, mass production of industrial and consumer goods. Many devices that make decisions based on data received from sensors can also be considered robots - such, for example, elevators, without which our life is already unthinkable.

The Mindstorms EV3 constructor invites us to enter the fascinating world of robots, immerse ourselves in the complex environment of information technology.

Objective: To learn how to program a robot to move in a straight line.

    Get acquainted with the Mindstorms EV3 constructor and its programming environment.

    Write programs for the movement of the robot in a straight line for 30 cm, 1 m 30 cm and 2 m 17 cm.

    Mindstorms EV3 constructor.

Designer parts - 601 pcs, servo motor - 3 pcs, color sensor, motion sensor, infrared sensor and touch sensor. The EV3 microprocessor block is the brain of the LEGO Mindstorms.

A large servomotor is responsible for the movement of the robot, which connects to the EV3 Brick and makes the robot move: go forward and backward, turn around and drive along a given trajectory. This servomotor has a built-in rotation sensor, which allows you to very accurately control the movement of the robot and its speed.

You can make a robot perform an action using the EV3 software. The program consists of various control blocks. We will work with the movement block.

The motion block controls the motors of the robot, turns it on, turns it off, makes it work in accordance with the tasks. You can program the movement to a certain number of revolutions, or degrees.

    Preparatory stage.

    Creation of a technical field.

We will mark the robot’s work field, using electrical tape and a ruler, create three lines 30 cm long - a green line, 1 m 15 cm - red and 2 m 17 cm - black lines.

    Necessary calculations:

Robot wheel diameter - 5 cm 7 mm = 5.7 cm.

One revolution of the robot wheel is equal to the circumference of a circle with a diameter of 5.7 cm. The circumference is found by the formula

Where r is the radius of the wheel, d is the diameter, π = 3.14

l = 5,7 * 3,14 = 17,898 = 17,9.

Those. For one revolution of the wheel, the robot travels 17.9 cm.

Calculate the number of revolutions required to pass:

N=30: 17.9=1.68.

    1m 30cm = 130cm

N=130: 17.9=7.26.

    2 m 17 cm = 217 cm.

N = 217: 17.9 = 12.12.

    Creation and calibration of the program.

We will create a program according to the following algorithm:

Algorithm:

    Select a motion block in the Mindstorms EV3 software.

    Turn on both motors in the given direction.

    Wait for the rotation sensor reading of one of the motors to change to the specified value.

    Turn off motors.

The finished program is loaded into the robot control unit. We put the robot on the field and press the start button. EV3 drives across a field and stops at the end of a given line. But in order to achieve an accurate finish, you have to calibrate, since external factors influence the movement.

    The field is installed on student desks, so a slight deflection of the surface is possible.

    The surface of the field is smooth, so poor adhesion of the robot's wheels to the field is not ruled out.

    In calculating the number of revolutions, we had to round the numbers, and therefore, by changing the hundredths of the revolutions, we achieved the required result.

5. Conclusion.

The ability to program a robot to move in a straight line will be useful for creating more complex programs. As a rule, all dimensions of movement are indicated in the terms of reference for robotics competitions. They are necessary so that the program is not overloaded with logical conditions, loops and other complex control blocks.

At the next stage of acquaintance with the Lego Mindstorms EV3 robot, you will learn how to program turns at a certain angle, movement in a circle, spirals.

It is very interesting to work with the designer. Learning more about its capabilities, you can solve any technical problems. And in the future, perhaps, create your own interesting models of the Lego Mindstorms EV3 robot.

Literature.

    Koposov D. G. "The first step into robotics for grades 5-6." - M.: Binom. Knowledge Laboratory, 2012 - 286 p.

    Filippov S. A. "Robotics for children and parents" - "Science" 2010

    Internet resources

    http://lego. rkc-74.ru/

    http://www.9151394.ru/projects/lego/lego6/beliovskaya/

    http://www. lego. com/education/

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 ratio. 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

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 instructions 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.

Example 1. One sensor, with P regulator.

Design

The light sensor is mounted on a beam conveniently located on the model.


Algorithm

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:

An example of the algorithm

Example 2. One sensor, with PK controller.

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 enough. 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.