Logging into a datalog file
We can not conduct an EV3-G experiment because we need to use the sensor. But we can do the following - write into the datalog file and then open the file with LibreOffice and plot a graph. In this way, we could see what is the value of the Gyro sensor and what is the value of the integral part and then understand how does the integral part affects the behaviour of the robot.
Compensating with the integral part
When the robot slightly moves to one side it makes an error. This error is added to the integral part and the integral part increases. As it increases to about 7-8 the robot start correcting for this error. This is the value of the steering and the robot turns slightly back to the line. You could see the graphic below where with Red you have the values of the integral part and with blue the values of the gyro sensor.
In this spreadsheet, we have the values for the Integral part and the Gyro sensor for moving straight with the robot.
This here is the final program for moving straight and for keeping the straight line with the Box Robot and this program includes the integral part. But first I would like to run it and to datalog the values of the gyro sensor and then discuss these values so that you could further understand the idea behind the integral part. So, let's run the program. First, we'll make sure that there is no datalog in the project and we empty the datalog.
Close and now we run.
Let's analyze the data. We go to the brick memory and we open the file that's called datalog2 in my case and we upload this file from the brick to the computer. Save and I'll save it on my desktop and then I'll open it with Libre. OK. And we have our values and these are the values that are detected from the gyro sensor while the robot is moving. And how many values do we have? We have about 40 values. So, they are more than 30, this means we can look at these values and try to come up with some conclusion. It's nice to have hundreds of values but for this run we have 40. And now if we plot the graphic and I would like to create a new chart and this chard will be line chart and I'll just finish. And what we can see on the chart are the values detected by the gyro sensor. And we can see that the robot has made a mistake here and we've returned the robot. And it made a mistake here and we turned the robot. Now, it is interesting to know that these are the values of the gyro sensor and as you can see we are keeping the orientation of the robot straight. But it's also interesting not only to know the orientation but to know the value of the integral part - the one that we are working on in this section of the course. So, we see that our program behaves at least as good as the proportional part because we keep the orientation of the robot straight and now we need to see if we can return the robot back to the position of the straight line. So, let's do another experiment and this time record the value of the integral part. This is our whole program and here we are recording the gyro sensor and at the end it pretty much looks like the proportional with a few more calculations but at the end we are setting a value for the steering of the block. And I would like to record this value. So, if I take a File Access and I would like to write our final calculation in a file called Integral.
And I'll just write this value here. So, we have the values of the gyro sensor and we also have the values of the integral calculation. And I'll remove the datalog so that the old data does not interfere with ours and we run the experiment again.
Let's see the data. In the software I would like to download the currently recorded 2 values. And we upload from the brick memory to the computer the datalog file
and again the integral part - the recordings for the integral. And they are currently on my desktop and we open the datalog and we open it like this and OK. We have the values for the datalog and we also need the values for the integral part. Open > OK and for the integral part we have 40 different samples. We copy them and for the gyro sensor we have again 40 different samples. So, this makes sense because every time we make a sample for the gyro sensor we also make a sample for the integral part. And now we plot this and let's see what the data will show us. I would like a line like this
and finish. This is the graphic and this graphic shows the behavior of our robot. What can we see on this plot? First, with the blue dots we see the values of the gyro sensor and we can see that the robot was moving slightly in our case to the left and then it started moving slightly to the right. So, this is to the left and this is to the right. So, we have the robot moving to the left and then to the right. But why? Why did we start moving to the right? This here is the point that we are trying to return back to the line. Because for about 3-4 seconds we were moving slightly to one side and the robot was accumulating an error and we can see this accumulation right here of the error and this is the integral part. And we are trying to apply and we are actually applying this error to the steering block. And as the value of the steerings becomes larger and larger and larger.. right here the robot will start to move in the reverse direction. So, it happens right here as the value for steering is between 7 and 9 and the robot starts to return back to the line. And we reach a maximum of the steering where the robot is actually at 0 and we continue to apply this value because the robot is facing forward but it still has to return back to the line. So, it moves to the other side and we can see this from the gyro sensor. And as the gyro sensor moves to the other side we can see that the error is reduced and the integral part is reduced and we are closer to the line. Perfectly will be at the line when both the integral part and the gyro sensor are close to 0. And this is the perfect case. Again, it might be a little complicated but it's the way you can understand the behavior of the program so let's go through it again. The blue dots are the gyro sensor and red dots are the integral part. As the robot is making a mistake and moves slightly to one side we can see this from the gyro sensor that the robot is moving slightly to one side we accumulate an error and we try to reverse the robot to move in the opposite direction but when the value is 4 this is quite small for our robot so it actually starts to happen when the value for the steering is about 7 right here. And the robot starts returning back to the line and we can see that it kind of straightens and right here when the value of the steering is maximum the robot moves forward but is away from the line and it starts returning back to the line. And the error for our integral part is reduced. And this is the basic idea of the integral part that it keeps track of the error that you've made and how away you are from the line and then you can return back to the line.