Lego EV3. black line movement

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 way of programming that even children in grades 2-3 will 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 on any route of the track in 15-30 minutes (taking into account the phased verification and adjustment of some features of the trajectory).

This method was tested at municipal and regional competitions in robotics in the Surgut region and Khanty-Mansi Autonomous Okrug-Yugra and brought our school first places. There I was 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 problem. You need to start by designing a robot for a specific track. In the next article, I'll show you how to do it. Well, since the movement along the line is very common, I'll start with programming.

Consider the version of the robot with two light sensors, as it is more understandable to elementary 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).
An important point. For the best operation of such a circuit, it is desirable to select a pair of sensors according to the parameters. Otherwise, it will be necessary to introduce a block for correcting the values ​​of the sensors.
Installation of sensors on the chassis according to the classical scheme (triangle), approximately as in the figure.

The program will consist of a small number of blocks:


1. Two blocks of light sensor;
2. Four blocks of "Mathematics";
3. Two blocks of motors.

The robot is controlled by two motors. The power of each is 100 units. For our scheme, we will take the average value of the motor power equal to 50. That is, the average speed when moving in a straight line will be equal to 50 units. When deviating from rectilinear motion, the power of the motors will increase or decrease proportionally, depending on the angle of deviation.

Now let's figure out how to connect all the blocks, set up the program and what will happen in it.
Let's expose two light sensors and assign them ports 2 and 3.
We take a block of mathematics and select "Subtraction".
Let's connect the light sensors from the "Intensity" outputs with tires to the math block to the "A" and "B" inputs.
If the robot 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 "Multiply" in it.
To calculate the coefficient, you need to measure the level of "white" and "black" using the NXT unit.
Suppose: white -70, black -50.
Next, we calculate: 70-50=20 (difference between white and black), 50/20=2.5 ​​(we set the average power value when moving in a straight line in the blocks of mathematics to 50. This value plus the added power when adjusting the movement should be equal to 100)
Try setting the value to 2.5 on the "A" input, and then pick it up more accurately.
Connect the "Result" output of the previous "Subtraction" math block to the "B" input of the "Multiplication" math block.
Next comes a pair - a block of mathematics (Addition) and motor B.
Math block setup:
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.
Following the steam is the math block (Subtraction) and motor C.
Math block setup:
Input "A" is set to 50.
Input "B" is connected by a bus to the output "Result" of the block of mathematics "Multiplication".
The output of the "Result" block is connected by a bus to the "Power" input of the motor C.

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

Since all this will work in a cycle, we add the "Cycle", select and transfer it all to the "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 are the same, which means that the output of the "Subtract" block will be 0. The output of the "Multiplication" block also gives the value 0. This value is fed in parallel to the motor control pair. Since the value 50 is set in these blocks, adding or subtracting 0 does not affect the power of the motors. Both motors run at the same power of 50 and the robot rolls in a straight line.

Suppose 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, since it moves to a white field, and the illumination of sensor 3 decreases. Suppose the values ​​of these sensors become: sensor 2 - 55 units, and sensor 3 - 45 units.
The "Subtractions" block will determine the difference between the values ​​of the two sensors (10) and feed it to the correction block (multiplication by a factor (10 * 2.5 = 25)) and then to the control blocks
motors.
In the math block (Addition) of motor B control to the average speed value of 50
25 will be added and a power value of 75 will be applied to motor B.
In the math block (Subtraction) of controlling motor C, 25 will be subtracted from the average speed value of 50 and a power value of 25 will be applied to motor C.
Thus, the deviation from a straight line will be corrected.

If the track turns sharply to the side and sensor 2 is on white and sensor 3 is on 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 the two sensors (20) and feed it to the correction block (20 * 2.5 = 50) and then to the motor control blocks.
Now in the block of mathematics (Addition) controlling motor B, the power value 50 +50 =100 will be applied to motor B.
In the math block (Subtraction) of motor C control, a power value of 50 - 50 = 0 will be applied to motor C.
And the robot will make a sharp turn.

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

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

In the "Block Builder" 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 the line.

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.

Decision.

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.

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.



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. Tracing a Line in Reflected Light Mode with Two Sensors Sometimes 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 have 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, для движения по черной линии, с одним и двумя датчиками цвета

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 pieces, servo motor - 3 pieces, 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 we will 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/

Loading...Loading...