All gyros drift over time. The gOS
My Block measures this drift and the resulting bias error in the rate of the Gyro Sensor. As a FIRST LEGO League tournament host, one of the largest complaints about the EV3 Gyro Sensor I hear about is the drift in the sensor readings. If you look at the HiTechnic sensor block, you may notice an input for a bias offset. Even after using the Gyro Sensor reset block, the Gyro Sensor may still not read 0. If you change the mode of the Gyro Sensor while it is perfectly still, it will reset to 0, but that is not done in the Gyro Boy program. The gOS
My Block compensates for this bias. You can think of this as a DC offset that you may see in electrical signals.
The gOS
My Block measures the Gyro offset and then subtracts this value from the calculations used later to keep Gyro Boy balanced. The robot needs to be completely stationary while the offset is determined. This could be fixed by adding a one-time delay at the start of the program. A delay of two seconds after the button is pressed would be enough to allow the robot to be at rest (no wobbling) when the Gyro offset is initially determined. However the way the program is written, you need to be gentle when pushing the brick button to start the program. Any wobbling can prevent the robot from determining the Gyro offset, and thus the robot never wakes up. In the following screenshot, you can see the entire gOS
My Block. Again, the bugbear of a long horizontal program prevents us from easily understanding the entire program at a quick glance.
I have tried to rearrange the program in such a way that is visually easier to understand. However, I have had to split the program into two sections (left and right) as you can see in the following two screenshots. The OSL
Loop block is the offset loop block. The goal of this block is twofold. The first goal is to determine the average value of the Gyro rate, and second is to measure the variation in the Gyro rate over a period of time. If there is minimal variation (thus making the Gyro rate constant), then we know the average bias level and the block can terminate. Remember that these are measurements of the rotational speed or rate of the Gyro, not the absolute Gyro angular position value.
There are several new variable blocks in the gOS
My Block. The gMn
variable block stores the minimum measured Gyro value. The gMx
variable block stores the maximum measured Gyro value. The gSum
variable block is used to add up 200 Gyro rates for the purpose of finding an average value. The gyro
variable block is used to store the current Gyro rate during an individual iteration of the
gChk
loop block.
The OSL
Loop begins by defining extreme values for gMn
and gMx
. These values are beyond the maximum range of the Gyro Sensor, which is about 400 degrees/second. gMx
is negative and gMn
is positive so that we are guaranteed to get the real minimum and maximum values later. gSUM
is set to 0
because it is the first iteration. The gChk
Loop block, the Gyro check loop, will average the value of the Gyro rate for about 1 second. The Gyro check loop will run for 200 iterations, with a Wait block of 0.004 seconds inserted to give some time between samples.
Once inside the gChk
loop block, the value of the Gyro Sensor block is stored to the gyro
variable block. The sum of the previous gSum
value and the current Gyro rate are stored to the gSum
variable block. Next, the program reduces the limits of the gMx
and gMn
variables. The variable names are confusing here because the gMn
has positive numbers and the gMx
has negative values. A compare block determines if the value of the Gyro Sensor is greater than gMx
(which starts out at -1000). If this is true, then a logic switch block updates gMx
by writing the value of the gyro
variable block to the gMx
variable block. Next, the inverse happens where the gMn
variable block is updated in a similar manner. If the value of the gyro
variable block is less than gMn
, then gMn
is replaced by the value of the gyro
variable block.
After 200 iterations, the gChk
loop block terminates and next the program tests to see how far apart gMn
and gMx
are as we can see in the following screenshot. A Math block calculates the difference between gMn
and gMx
. If the difference is less than 2 degrees/second, then the OSL
loop can terminate. If the difference is greater than 2, this means there is still considerable variation in the Gyro rate and the robot was not perfectly still. Thus, the entire process is run again. Upon termination of the OSL
loop, a Math block divides the value of the gSUM
variable block by 200. This is because we added the Gyro rate up over 200 iterations. By dividing it by 200, we are calculating the average value on the consistent Gyro offset bias. This value is stored to the gOS
variable block for use in the main program and in other My Blocks.
18.224.59.231