PID controller ev3 movement along the line. Proportional integral differential PID controller in Lego Mindstorms robotics. Proportional controller. Robot control language

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.

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

Robotics is a new interesting direction, which, apparently, will be further developed within the framework of school courses in computer science and technology. The boom of robotics is largely due to the fact that it allows you to answer the question: "Why do we actually learn programming?". In addition, in the course of robotics, you can get acquainted with the elementary concepts of the theory of automatic control.

This page presents the simulators for programming and Arduino boards developed by the author. They can help in cases where for some reason it is not possible to use real hardware.

The trainers use HTML5 features, so they will only work in modern browsers (it's best to use Google Chrome or Mozilla Firefox).

News now in the Telegram channel

November 27, 2015
The “germ” track has been added to the simulators ( M.V. Lazarev, Orekhovo-Zuevo).

October 13, 2015
Now in the simulators for the LEGO robot, you can upload your tracks (fields for the robot). How to do it? See.
Added new simulators - LEGO robots with two , three , four light sensors.

Robot control language

To control robots in simulators, a simple programming language is used, which received the working title SiRoP (Simple Robot Programming).

Robot control with light sensor

The light sensor allows the robot to navigate on the table surface, for example, to move along the border between the white and black areas (along the edge of the black line). The photodiode illuminates the surface, the photodetector "catches" the reflected rays and measures their intensity.

The most popular task of this type is moving along a line. With the help of the simulator, you can study various control laws - relay, proportional, and even PID control (proportional-integral-derivative).

Examples of programs for a robot with a light sensor

While 1 ( if sensor > 128 ( motor = 100 motor = 0 ) else ( motor = 0 motor = 100 ) wait(10) )

KP = 0.2 while 1 ( u = kP*(sensor-128) motor = 50 + u motor = 50 - u wait(20) )

Main ( while 1 ( while sensor > 128 ( motor = 100 motor = 100 wait(10) ) back() turn() ) ) back ( motor = -100 motor = -100 wait(260) ) turn ( motor = -50 motor = 50 wait(50) )

Robot control with two light sensors

Two light sensors allow the robot to better navigate and follow a thin line. They are brought forward a little and parted to the sides. As for tasks with a single sensor, using this simulator, you can study various control laws.

Example programs for a robot with three light sensors

Robot control with four light sensors

Four light sensors allow the robot to better detect sharp turns. Internal sensors are used for fine adjustment, proportional control is used for them. Two external sensors are placed a little forward and separated to the sides. They are used when there is a sharp turn. The gain factor for control according to the readings of the sensors of the outer pair is selected larger than for the inner pair (see Fig. L.Yu. Ovsyanitskaya et al., Algorithms and programs for the movement of the Lego Mindstorms EV3 robot along the line, M.: "Pero", 2015).

Example programs for a robot with four light sensors

While 1 ( d0 = encoder > 128 d1 = encoder > 128 d2 = encoder > 128 d3 = encoder > 128 if d1 & !d2 ( motor = 100 motor = 0 ) if! d1 & d2 ( motor = 0 motor = 100 ) if d1 == d2 ( motor = 100 motor = 100 ) if d0 & !d3 ( motor = 30 motor = 0 ) if! d0 & d3 ( motor = 0 motor = 30 ) wait(10) )

K1 = 0.2 k2 = 0.4 while 1 ( u1 = sensor - sensor u2 = sensor - sensor motor = 50+k1*u1+k2*u2 motor = 50-k1*u1-k2*u2 wait(10) )

Controlling a robot with a distance sensor (sonar)

The distance sensor (sonar) allows you to determine the distance to the nearest obstacle while the robot is moving. It emits an ultrasonic signal and receives the reflected signal. The longer the time between the transmitted and received signals, the greater the distance.

Using a distance sensor, a robot can be programmed to automatically navigate a maze of known shape but unknown size.

Details Author: Konovalov Igor The proportional controller is an improvement. The main disadvantage of the relay is that it does not care how much the current values ​​differ from the normal value of the sensor. It has only two states - either try to increase the sensor values ​​by a certain constant number if they are less than the normal value, or increase it. Because of this, oscillations with a constant amplitude occur, which is very inefficient.
It is much more logical to determine how "far" the current readings are from normal, and change the amplitude depending on this. To make it more clear, let's look at an example. The example is the same as in the previous article: a robot from Lego Mindstorms EV3 drives along a black line using one color sensor in light mode.

The robot tries to drive along the border between white and black, and there the sensor shows approximately 50% illumination. And the farther it is from the normal position, the more effort the robot makes to return to 50%.
To write a program, we will use the terms "error", "control action". Error - the difference between the current reading of the sensor and the normal one. In our case, if now the robot sees 20% of the illumination, then the error is 20-50= -30%. The error sign indicates in which direction the robot should turn in order to get rid of the error. Now we need to tell the motors which way to turn the robot, at what speed and how sharply. It is necessary to exert a control effect on the motors, which means how abruptly it should return to its normal position. The control action (UP) is calculated as the error (error) multiplied by the proportionality factor (k). This factor is used to increase or decrease the influence of the error on the control action. The control action is fed into the steering, where the average speed of the robot is set.
How to set the aspect ratio? Empirically select values, for the passage of the trajectory it can be, for example, from 0.2 to 1.5, depending on the speed and design of the robot. If the coefficient is too large, then the robot will wag strongly, if it is small, it will drive smoothly, but at some point on the turn, move out due to insufficient control input. Let's write two versions of the program - with variables (for those who have already studied them) and without.


But this regulator can also be strengthened by introducing a proportional and integral component, the description will be in the following articles. See you soon!

Similar articles

2022 parki48.ru. We are building a frame house. Landscaping. Construction. Foundation.