Encyclopedia of fire safety

Proportional controller.  Proportional integral differential PID controller in Lego Mindstorms robotics. Proportional controller Robot control with two light sensors

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 action. 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!

A proportional controller is a device that exerts a control action u(t) on an object in proportion to its linear deviation e(t) from a given state x0(t);

e(t)=x0(t)-x(t), where x(t) is the state in this moment time;

u(t)=ke(t), where k is the amplifying factor.
That is, the further the robot deviates from the set course, the more actively the motors should work, leveling it.

Walking in a line with one light sensor using a P controller

Movement along the border of black and white can also be built on the P-regulator. Although outwardly the task seems to be solved only with the help of a relay controller, since there are only two states visible to the human eye in the system: black and white. But the robot sees everything differently, for it there is no sharp border between these colors. We can say that he is short-sighted and sees a gradient transition of shades of gray.

This is what will help to build a P-regulator.
Defining the state of work as the readings of the light sensor, we will learn how to provide a proportional control effect on the motors according to the following law:
e=s1-grey, where s1 is the current sensor reading and gray is the set value.

Coefficient k (equal to this example 2) must be small enough (from 1 to 3). Such a controller works effectively only for small deflection angles, so the robot must be placed in the direction of movement so that the sensor is on the left side of the black line. It is easy to see that the movement along the line on the P-regulator is smooth. and in some areas of work it moves almost rectilinearly or exactly repeating the bends of the line.

Sensor calibration

Let's look at the number 48 used in the formula. This is the arithmetic average of the light sensor reading on black and white, for example (40+56)/2=48. However, the readings of the sensors often change according to different reasons: a different surface, a change in the general illumination in the room, a slight modification of the structure, etc. Therefore, we will calibrate the robot manually by determining the readings of the light sensor on white and black.

Line tracking with two light sensors using a P controller
It is quite difficult to drive through an intersection correctly with one light sensor. If you want to do this at a fast enough speed, you need at least two sensors spaced at least two line widths apart (or wider).
There are four states of the sensor when moving:

  • both on white - straight ahead;
  • left (s1) not black, right (s2) on white - move to the left;
  • left on white, right on black - movement to the right;
  • both on black - go straight.
That. if the sensor readings are equal (both white or both black), the robot goes straight. Before starting the robot, we will auto-calibrate both sensors. Then the algorithm of movement along the line with the P-controller will look like:

The coefficient k can vary in a fairly wide range (from 1 to 20 or more) depending on the curvature of the line, the maneuverability of the robot and the difference between black and white on the field.
Important condition. Autocalibration should be carried out on a single-color surface and preferably at the illumination that will occupy the largest part of the path. For example, if the robot moves along the black line on a white field, then it is necessary to calibrate on a white one. Those. the position of the robot at the start should be like this:


And another note. There are sensors whose readings differ by 10-20%. It is advisable not to pair them with a regulator with a large coefficient, since with a sharp change in the overall illumination, even on a uniform white field, the deviations may turn out to be different, which will lead to unexpected consequences.

Robotics is an interesting new direction, which, apparently, will continue to develop within the framework of school courses informatics 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.

Trainers use HTML5 features, so they will only work in modern browsers(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 carried a little forward and parted 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.

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

General theory and concrete examples the creation of the program is 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 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. 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

Similar posts