Movement along a line with two light sensors. International Robot Competition - Rules - Robot Examples - LEGO EV3 Trajectory Robot Line Motion with One ev3 Sensor

One of the basic movements in light construction is following the black line.

General theory and specific examples The creation of the program is described on the website wroboto.ru

I will describe how we implement this in the EV3 environment, since there are differences.

The first thing the robot needs to know is the meaning of the “ideal point” located on the border of black and white.

The location of the red dot in the figure corresponds exactly to this position.

The ideal calculation option is to measure the black and white values ​​and take the arithmetic average.

You can do this manually. But the disadvantages are immediately visible: over even a short period of time, the illumination may change, and the calculated value will be incorrect.

So, you can get a robot to do it.

During the experiments, we found out that it is not necessary to measure both black and white. Only white can be measured. And the ideal point value 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 movement is the rotation coefficient. The larger it is, the more sharply the robot reacts to changes in illumination. But too much great importance 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. Increasing the speed of movement leads to an increase in the robot's response time 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 into variables.

Turn 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 arrange it in the form of a separate block.

Implementation of the algorithm

This is exactly the algorithm that was implemented in the robot for middle category WRO 2015

The text of the work is posted without images and formulas.
Full version work is available in the "Work Files" tab in PDF format

Lego Mindstorms EV3

Preparatory stage

Program creation and calibration

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.

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

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

Goal: Learn to program the robot to move in a straight line.

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

    Write programs for the robot to move in a straight line at 30 cm, 1 m 30 cm and 2 m 17 cm.

    Mindstorms EV3 constructor.

Construction parts - 601 pcs., servo motor - 3 pcs., color sensor, touch motion sensor, infrared sensor and touch sensor. The EV3 microprocessor unit is the brain LEGO constructor Mindstorms.

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

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

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

    Preparatory stage.

    Creation of a technical field.

Let's apply markings to the robot's work area, using electrical tape and a ruler to create three lines 30 cm long - green Line, 1 m 15 cm - red and 2 m 17 cm - black lines.

    Necessary calculations:

The diameter of the robot wheel is 5 cm 7 mm = 5.7 cm.

One revolution of the robot wheel is equal to the length of a circle with a diameter of 5.7 cm. We find the circumference using 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.

Let's calculate the number of revolutions required to drive:

N = 30: 17.9 = 1.68.

    1 m 30 cm = 130 cm

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 the program using the following algorithm:

Algorithm:

    Select a movement block in the Mindstorms EV3 program.

    Turn on both motors in the given direction.

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

    Turn off the motors.

We load the finished program into the robot control unit. We place the robot on the field and press the start button. EV3 drives across the field and stops at the end of a given line. But in order to achieve an accurate finish, you have to perform calibration, since the movement is influenced by external factors.

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

    In calculating the number of revolutions, we had to round the numbers, and therefore, by changing hundredths in 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, in technical specifications robotics competitions, all dimensions of movement are indicated. They are necessary so that the program is not overloaded with logical conditions, loops and other complex control blocks.

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

Working with the designer is very interesting. By learning more about its capabilities, you can solve any technical problem. And in the future, perhaps, create your own interesting models 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/

This problem is classic, 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 examples of a robot will be analyzed based on the main educational model of Robot Educator.

To begin with, let's collect basic model educational robot Robot Educator, for this you can use the instructions in software MINDSTORMS EV3.

Also, for examples, we will 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 surrounding light. For this sensor, in the programs we will use the reflected light mode, in which the amount of reflected light from the red backlight of the sensor is estimated. The limits of sensor readings are 0 - 100 units, for “no reflection” and “total reflection”, respectively.

As an example, we will look at 3 examples of programs for moving along black trajectory depicted on a flat, light background:

· One sensor, with P regulator.

· One sensor, with PC regulator.

· Two sensors.

Example 1. One sensor, with P regulator.

Design

The light sensor is installed 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 of the sensor illumination beam with a black line, the readings returned by the sensor vary gradiently. The robot maintains the position of the light sensor on the border of the black line. By converting input data from the light sensor, the control system generates a value for the robot's turning speed.


Since on a real trajectory the sensor generates values ​​throughout its entire operating range (0-100), 50 is selected as the value to which the robot strives. In this case, the values ​​transmitted to the rotation functions are formed in the range -50 - 50, but these values ​​are not enough for a steep turning the trajectory. Therefore, the range should be expanded one and a half times to -75 - 75.

As a result, in the program, the calculator function is a simple proportional controller. The function of which ( (a-50)*1.5 ) in the operating range of the light sensor generates rotation values ​​in accordance with the graph:

Example of how the algorithm works

Example 2. One sensor, with PK regulator.

This example is based on the same construction.

You probably noticed that in the previous example the robot swayed excessively, which did not allow it to accelerate enough. Now we will try to improve this situation a little.

To our proportional controller we are also adding a simple cube controller, which will add some bending to the controller function. This will reduce the swaying of the robot near the desired boundary of the trajectory, as well as make stronger jerks when far away from it.

In order to make the robot move smoothly along the black line, you need to force it to 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 white and black - that we will use to calculate the speed of movement.

First, let’s introduce the concept of “Ideal trajectory point.”

Light sensor readings range from 20 to 80, most often on white the readings are approximately 65, on black about 40.

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

Here the location of the point is fundamental - between white and black. It will not be possible to set it exactly on white or black for mathematical reasons; why will become 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 there is a deviation in any direction, the robot must return to that point.

Let's compose mathematical description tasks.

Initial data.

Ideal point.

Current light sensor readings.

Result.

Motor rotation power V.

Motor rotation power C.

Solution.

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

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

In a situation where the robot enters 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 creating such a regulator is a rather difficult task, and it is not always required in its entirety.

Therefore, we decided to limit ourselves to only the P-regulator, which adequately responds to deviations from the black line.

In mathematical language it will be written like this:

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

Base – a certain base power of the motors that determines the speed of the robot. It is selected experimentally, depending on the design of the robot and the sharpness of turns.

Itek – current readings of the light sensor.

Iid – calculated ideal point.

k – proportionality coefficient, selected experimentally.

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

This is how a person sees the line:

This is how the robot sees it:


We will use this feature when designing and programming a robot for the “Trajectory” competition category.

There are many ways to teach a robot to see a line and move along it. There are complex programs and very simple ones.

I want to talk about a programming method that even children in grades 2-3 can master. At this age, it is much easier for them to assemble structures according to instructions, and programming a robot is a difficult task for them. But this method will allow the child to program the robot to any route of the track in 15-30 minutes (taking into account step-by-step testing and adjustment of some features of the trajectory).

This method was tested at municipal and regional robotics competitions in the Surgut region and Khanty-Mansi Autonomous Okrug-Yugra and brought our school first places. There I became convinced that this topic is very relevant for many teams.

Well, let's get started.

When preparing for this type of competition, programming is only part of the solution to the task. You need to start by designing a robot for a specific route. In the next article I will tell you how to do this. Well, since movement along a line occurs very often, I’ll start with programming.

Let's consider the option of a robot with two light sensors, as it is more understandable to primary school students.

Light sensors are connected to ports 2 and 3. Motors to ports B and C.
The sensors are placed at the edges of the line (try experimenting with placing the sensors at different distances from each other and at different heights).
Important point. For better work For such a scheme, it is advisable to select a pair of sensors according to the parameters. Otherwise, it will be necessary to introduce a block for adjusting sensor values.
Installation of sensors on the chassis according to the classic pattern (triangle), approximately as in the figure.

The program will consist of a small number of blocks:


1. Two light sensor units;
2. Four blocks of “Mathematics”;
3. Two motor blocks.

Two motors are used to control the robot. The power of each is 100 units. For our scheme, we will take the average value of motor power equal to 50. That is, the average speed when moving in a straight line will be equal to 50 units. If you deviate from rectilinear movement The power of the motors will increase or decrease proportionally, depending on the angle of deflection.

Now let's figure out how to connect all the blocks, configure the program and what will happen in it.
Let's set up two light sensors and assign ports 2 and 3 to them.
Take the math block and select “Subtraction.”
Let's connect the light sensors from the "Intensity" outputs by buses to the mathematics block to the inputs "A" and "B".
If the robot's sensors are installed symmetrically from the center of the track line, then the values ​​of both sensors will be equal. After subtraction we get the value – 0.
The next block of mathematics will be used as a coefficient and you need to set “Multiplication” in it.
To calculate the coefficient, you need to measure the “white” and “black” levels using the NXT block.
Let's assume: white -70, black -50.
Next, we calculate: 70-50 = 20 (the difference between white and black), 50/20 = 2.5 (we set the average power value when moving in a straight line in the math blocks to 50. This value plus the added power when adjusting the movement should be equal to 100)
Try setting the value to 2.5 at input “A”, and then select it more accurately.
To the input “B” of the mathematics block “Multiplication”, connect the output “Result” of the previous mathematics block “Subtraction”.
Next comes a pair - a math block (Addition) and motor B.
Setting up a math block:
Input “A” is set to 50 (half the motor power).
The output of the “Result” block is connected by a bus to the “Power” input of motor B.
The next pair is a math block (Subtraction) and motor C.
Setting up a math block:
Input “A” is set to 50.
Input “B” is connected by a bus to the “Result” output of the “Multiplication” mathematics block.
The output of the “Result” block is connected by a bus to the “Power” input of motor C.

As a result of all these actions you will get the following program:

Since all this will work in a cycle, we add “Cycle”, select it and move it all to “Cycle”.

Now let's try to figure out how the program will work and how to configure it.


While the robot is moving in a straight line, the values ​​of the sensors coincide, which means that the output of the “Subtraction” block will be the value 0. The output of the “Multiplication” block also gives the value 0. This value is supplied in parallel to the motor control pair. Since these blocks are set to 50, adding or subtracting 0 does not affect the power of the motors. Both motors operate at the same power of 50, and the robot rolls in a straight line.

Let's assume that the track makes a turn or the robot deviates from a straight line. What will happen?

The figure shows that the illumination of the sensor connected to port 2 (hereinafter referred to as sensors 2 and 3) increases, as it moves onto the white field, and the illumination of sensor 3 decreases. Let's assume that the values ​​of these sensors become: sensor 2 – 55 units, and sensor 3 – 45 units.
The “Subtraction” block will determine the difference between the values ​​of two sensors (10) and feed it to the correction block (multiplying by a coefficient (10*2.5=25)) and then to the control blocks
motors.
In the mathematics block (Addition) of motor control B to the average speed value of 50
25 will be added and a power value of 75 will be supplied to motor B.
In the mathematics block (Subtraction) for controlling motor C, 25 will be subtracted from the average speed value of 50 and a power value of 25 will be supplied to motor C.
In this way, the deviation from the straight line will be corrected.

If the track turns sharply to the side, sensor 2 turns out to be white, and sensor 3 is black. The illumination values ​​of these sensors become: sensor 2 - 70 units, and sensor 3 - 50 units.
The “Subtraction” block will determine the difference between the values ​​of two sensors (20) and feed it to the correction block (20*2.5=50) and then to the motor control units.
Now in the mathematics (Addition) block of motor B control, a power value of 50 +50 =100 will be supplied to motor B.
In the mathematics block (Subtraction) of motor C control, a power value of 50 – 50 = 0 will be supplied to motor C.
And the robot will make a sharp turn.

On white and black fields, the robot must drive in a straight line. If this does not happen, try to select sensors with the same values.

Now let's create a new block and use it to move the robot along any route.
Select the cycle, then in the “Edit” menu select the “Create my block” command.

In the “Block Designer” dialog box, give a name to our block, for example, “Go”, select an icon for the block and click “DONE”.

Now we have a block that can be used in cases where we need to move along a line.