In this video tutorial, we would do a few experiments with the coefficients for the Integral compensation. There are actually two coefficients - "c" and "b"

**#659**- 10 Jan 2018
- 5:26

- LEGO MINDSTORMS
- Math, EV3, Datalog, Experiment, Gyro Sensor, Sensors, Physics, FLL, Programming
- K.Mitov, I.Bozhilov

### Adding gyro sensor value to the integral

The first coefficient is "c". On every loop, the value of the gyro sensor is added to the integral. The coefficient controls this process and the influence of the gyro sensor value over the integral part.

### Integral to steering

The second coefficient is "b". This coefficient controls how much of the integral part is applied to the steering block. The greater the coefficient, the greater the steering.

### Spreadsheet files for plotting the Gyro Sensor Behaviour

In this spreadsheet, we have the values for the Integral part and the Gyro sensor for moving straight with the robot.

### Program for returning to the Straight line after the Robot makes an error (Integral compensating)

This is an EV3-G project that contains two programs implementing an Integral compensation - integral part of the PID algorithm. The first program is for a Five Minute Bot and the second program is for Box Robot. The things that you should be careful when using the program for your robot are the direction of the motors in the steering block; whether the motors in the steering block are written as "B+C" or "C+B" and the coefficients in the two math blocks. The coefficients that we've chosen should work for most of the robots, but will probably not work for some of them. If they don't work, write to us, comment below in the comment section or drop us an email.

### English

This is the last discussion of the program for the integral part for moving forward before we actually implement the final program. And I would like to discuss something that we have as an end result. These are the different coefficients in our program. And in the end we'll have like 3 coefficients. We'll have this 'c', 'b' and this 'c' here. And these are different coefficients we can use. Most important are the 'c' and the 'b' and it is important to understand them because the program as you download it from our site might not directly work with your robot and you might have it depends on where is the gyro sensor, the wheels, the tires, the power - many things. And it will probably work in most of the cases but you can always improve this by modifying some of the coefficients. So, let's do a few experiments and discuss them. First, we'll do a number of experiments with the Box Robot and the Five Minute Bot with different values for the coefficients and you can watch them in the recordings and then we can discuss them.

The first coefficient - this one here 'c' gives us the following control. We have the integral part and the integral part is the error that was accumulated while the robot was moving. And the integral part tells us how far away we are from the line. So, when we make a new sample we would like to add this new sample and this sample is with the gyro sensor so we take the value of the gyro sensor and we add this value to the integral part. But do we add it directly to the integral part or we multiply this by a certain percentage? And this is important because we don't want to add to the integral part the whole value of the gyro sensor and we must normalize this, we must move it in a range that's appropriate for us. So, we just multiply by 0.25 to reduce the control that the gyro sensor has over the integral part. And this is specifically for the Box Robot and for our robot. So, we found out that 0.25 is kind of like okay but it might be 0.20 or 0.30 so it's worth experimenting but 0.25 means that we add the current error to the old error so we have this integral part that's the accumulated error. So, we add this new error to the accumulated error but not directly. We first reduce this by a certain percentage and we add just 25% of the gyro sensor value to the integral part. The next coefficient that's important is this one here at almost the end of our program where we set the value for the steering and this value is calculated in a certain way and we take the integral part and we do some calculation and this calculation involves multiplying the integral part by 1 in our case and we apply this directly to the steering. And we might want the integral part to have more control over the steering and if you want to have more control and then we must multiply by 2. And in this way a value of 10 for the integral part will mean a steering of 20. So, it will steer more. Or if we multiply by 0.5, it will steer less. And you saw some changes in this like multiplying it by 1, by 2, by 4 in the recordings below. So, we found out that 1 is kind of like okay and it works for about 2 meters, probably after 2 meters it will not work that well but in most cases we have the fields like for 2 meters and something. So, this is the next important coefficient and if the robot is behaving strangely, try to modify this coefficient. And first try to lower it and then try to rise it and see what are the edge conditions and then you should choose a value for your coefficient. And basically the program is quite simple as you understand the values and the control that these two coefficients have and from now on we are ready to implement the whole program from scratch and this is something that we'll do in the next video.

## Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

### Moving Straight with LEGO Mindstorms EV3 robots

One of the most controversial topics when it comes to LEGO Mindstorms robots is how to make them move in a straight line. This is a problem that has caused a lot of confusion among teachers, parents, rookie teams and students. The robot makes about 2-3 centimetres error for every meter, which is about an inch for every 3-4 feets. In this course, I would like to discuss the different ways in which you can improve the behaviour of the robot and how you could make it move in a straight line with the help of the LEGO Mindstorms EV3 Gyro Sensor.

- 24
- 102:09
- 3

### PID Algorithm for Moving Straight with Gyro Sensor. Integral Part

The integral part "remembers" the errors that the robot has made in the past and we can compensate for those errors. This will make the robot return back to the line that we would like to keep it aligned.

- 5
- 0
- 0
*3d_rotation*1