Encyclopedia of fire safety

Driving in a line with a steering wheel in ev3. Line tracking with two light sensors. An example of the algorithm

In this lesson, we will continue to explore the use of the color sensor. The material presented below is very important for further study of the robotics course. After we learn how to use all the Lego mindstorms EV3 sensors in solving many practical problems, we will build on the knowledge gained in this lesson.

6.1. Color Sensor - Reflected Light Intensity Mode

So, we are starting to study the next mode of operation of the color sensor, which is called "Brightness of Reflected Light". In this mode, the color sensor directs a beam of red light at a nearby object or surface and measures the amount of reflected light. Darker objects will absorb light, so the sensor will read a lower value than lighter surfaces. The sensor value range is measured from 0 (very dark) to 100 (very bright). This mode of operation of the color sensor is used in many tasks in robotics, for example, to organize the movement of the robot along a given route along a black line drawn on a white coating. When using this mode, it is recommended to place the sensor in such a way that the distance from it to the surface under study is approximately 1 cm (Fig. 1).

Rice. one

Let's move on to practical training: The color sensor is already installed on our robot and is directed down to the surface of the pavement that our robot will walk on. The distance between the sensor and the floor is as recommended. The color sensor is already connected to the port "2" EV3 Brick. Let's load the programming environment, connect the robot to the environment, and use the color stripe field we made to complete the tasks in Section 5.4 of Lesson #5 to take measurements. Install the robot so that the color sensor is located above the white surface. "Hardware page" programming environments switch to the mode "View ports" (Fig. 2 pos. 1). In this mode, we can observe all the connections we have made. On the Rice. 2 ports connected displayed "B" and "C" two large motors, and to the port "2" - color sensor.

Rice. 2

To select the option for displaying sensor readings, click on the sensor image and select desired mode (Fig. 3)

Rice. 3

On the Rice. 2 pos. 2 we can see that the value of the color sensor reading above the white surface is 84 . In your case, you may get a different value, because it depends on the material of the surface and the lighting inside the room: part of the light, reflected from the surface, hits the sensor and affects its readings. Having installed the robot in such a way that the color sensor is located above the black strip, we fix its readings (Fig. 4). Try to measure the reflected light values ​​above the remaining color bands yourself. What values ​​did you get? Write your answer in the comments to this lesson.

Rice. four

Let's now solve practical problems.

Task number 11: it is necessary to write a program for the movement of the robot, which stops when it reaches the black line.

Solution:

The experiment showed us that when crossing the black line, the value of the color sensor in the mode "Brightness of Reflected Light" equals 6 . So, in order to fulfill Tasks #11 our robot should move in a straight line until the desired value of the color sensor becomes smaller 7 . Let's use the program block already familiar to us "Expectation" Orange palette. Let us choose the mode of operation of the program block required by the condition of the problem "Waiting" (Fig. 5).

Rice. 5

You must also configure the program block parameters "Expectation". Parameter "Type of comparison" (Fig. 6 pos. 1) can take the following values: "Equals"=0, "Not equal"=1, "More"=2, "More or equal"=3, "Less"=4, "Less or equal"=5. In our case, we set "Comparison Type" into meaning "Less". Parameter "Threshold" set equal to 7 (Fig.6 pos. 2).

Rice. 6

As soon as the color sensor value is set to less than 7 , what happens when the color sensor is above the black line, we will need to turn off the motors, stopping the robot. Problem solved (Fig. 7).

Rice. 7

To continue our studies, we will need to make a new field, which is a black circle with a diameter of about 1 meter, applied to a white field. The thickness of the circle line is 2 - 2.5 cm. For the base of the field, you can take one sheet of paper measuring A0 (841x1189 mm), glue together two sheets of paper measuring A1 (594x841 mm). On this field, mark the line of the circle and paint over it with black ink. You can also download the layout of the field, made in Adobe Illustrator format, and then order its printing on banner fabric in a printing house. The layout size is 1250x1250 mm. (You can view the layout downloaded below by opening it in Adobe Acrobat Reader)

This field will be useful to us for solving several classical tasks of the robotics course.

Task number 12: it is necessary to write a program for a robot moving inside a circle bordered by a black circle according to the following rule:

  • the robot moves forward in a straight line;
  • reaching the black line, the robot stops;
  • the robot moves back two revolutions of the motors;
  • the robot turns to the right by 90 degrees;
  • the movement of the robot is repeated.

The knowledge gained in the previous lessons will help you create a program on your own, decisive task №12.

Solution of problem No. 12

  1. Start straight ahead (Fig. 8 pos. 1);
  2. Wait for color sensor to cross black line (Fig. 8 pos. 2);
  3. Move back 2 turns (Fig. 8 pos. 3);
  4. Turn right 90 degrees (Fig. 8 pos. 4); the value of the angle of rotation is calculated for the robot assembled according to the instruction small-robot-45544 (Fig. 8 pos. 5);
  5. Repeat commands 1 - 4 in an endless loop (Fig. 8 pos. 6).

Rice. eight

To the operation of the color sensor in the mode "Brightness of Reflected Light" we will return many times when we consider algorithms for moving along the black line. In the meantime, let's analyze the third mode of operation of the color sensor.

6.2. Color Sensor - Ambient Light Intensity Mode

Color Sensor Mode "Ambient Light Brightness" very similar to the mode "Brightness of Reflected Light", only in this case the sensor does not emit light, but measures natural light environment. Visually, this mode of operation of the sensor can be determined by a weakly glowing blue LED. Sensor readings vary from 0 (lack of light) to 100 (the brightest light). When solving practical problems that require measuring ambient light, it is recommended to position the sensor so that the sensor remains as open as possible and is not obstructed by other parts and structures.

Let's attach the color sensor to our robot the same way we attached the touch sensor in Lesson #4 (Fig. 9). Connect the color sensor with a cable to the port "2" EV3 Brick. Let's move on to solving practical problems.

Rice. 9

Task #13: it is necessary to write a program that changes the speed of our robot depending on the intensity of external lighting.

To solve this problem, we need to learn how to get the current value of the sensor. And the Yellow palette of program blocks, which is called "Sensors".

6.3. Yellow palette - "Sensors"

The yellow palette of the Lego mindstorms EV3 programming environment contains programming blocks that allow you to get current sensor readings for further processing in a programme. Unlike, for example, the program block "Expectation" Orange palette, yellow palette program blocks immediately transfer control to the following program blocks.

The number of programming blocks in the Yellow Palette is different in the home and educational versions of the programming environment. In the home version of the programming environment, there are no programming blocks for sensors that are not included in the home version of the constructor. But, if necessary, they can be connected independently.

The educational version of the programming environment contains programming blocks for all sensors that can be used with the Lego mindstorms EV3 constructor.

Let's get back to the decision. Tasks #13 and see how you can receive and process color sensor readings. As we already know: the range of values ​​of the color sensor in the mode "Ambient Light Brightness" is within the range of 0 before 100 . The parameter that regulates the power of the motors has the same range. Let's try to adjust the power of the motors in the program block by reading the color sensor "Steering".

Solution:


Rice. ten

Let's load the resulting program into the robot and run it for execution. Did the robot move slowly? Turn on the LED flashlight and try to bring it to the color sensor on different distance. What's going on with the robot? Let's close the color sensor with the palm of our hand - what happened in this case? Write the answers to these questions in the comments to the lesson.

Task - Bonus

Load into the robot and run the task shown in the figure below. Repeat the experiments with the LED flashlight. Share your impressions in the comments to the lesson.

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 better work such a scheme, 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 deflection.

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.

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 start, we collect base model educational robot Robot Educator, for this you can use the instructions in software MINDSTORMS EV3.

Also, for examples, we need EV3 light-color sensors. These light sensors, like no other, the best way suitable 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. Limits of sensor readings 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 saves the position of the light sensor on the border 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 sufficiently. Now we will try to improve this situation a little.

To our proportional controller we also add a simple cube controller that will add some 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 achievement best result try changing the steering and power values.

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 color- moving 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.
Full version work is available in the "Files of work" 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.

Per last years advances in robotics and automated systems changed personal and business sphere our life. Robots are widely used in transport, in Earth and space research, in surgery, in the military industry, in carrying out laboratory research, in the field of security, in the mass production of industrial goods 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 a touch sensor. microprocessor unit EV3 is the brain LEGO constructor Mindstorms.

A large servo motor 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 the robot perform an action with computer program EV3. 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. Can be programmed to move a certain amount 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.

On the next step acquaintance with the Lego Mindstorms EV3 robot will have to 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 tasks. 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/

Similar posts