Turning with the Gyro Sensor on a specified angle and stopping there have never been easy. It is not going to get any better. However, this is not a problem of the Gyro sensor. The problem is in the way we develop our programs.
- 01 Jan 2017
No matter what your robot is when you turn at 90 degrees with the LEGO Mindstorms EV3 Gyro sensor it would almost always stop at 90+ or 90- degrees. This makes using the sensor difficult and error prone. The solution requires you to understand how sensors work. Not only this, but also the Touch, Color, Ultrasonic sensors.
Previous video tutorials:
Instructions for building the EasyBot are available at:
In the previous video we tried to build a program for turning the robot to 90 degrees but we couldn't, because the sensor was returning negative values. In this video we'll search for ways to overcome these negative values and to handle them.
The first very obvious solution would be just to turn in the opposite direction. Not to turn in this direction, but in the opposite direction, turn right. Let's program it and see if the program works. I'll change the motor form A to D This will be our left motor. So we'll be turning right, the robot will be turning right. Download and run the program.
The robot turns and it stops at about 90 degrees. I'll try to align it on the camera, so that we can see the angle.
It's not precisely 90 degrees but we'll also look for why this happens. Looking at the program and running it.
The motor turns, the whole robot turns, but at the end of the program the value detected by the sensor is not 90 degrees, it's 97 degrees. What happened here is that after we stop the motor, the robot continues for very small distance, but it's enough for the sensor to detect 97 so it stops at precisely 90 degrees but after we stop, the whole robot continues because of the inertia and because of the calibration of the sensor it returns not exactly 90 degrees, but slightly more than 90 degrees. What can we do? We can try to turn the robot back to return it a few degrees. So if it is 95, we'll return the robot, 5 degrees back. How can we do this? We can add a new block, it's again motor block. We'll turn it in reverse direction -10% of the power
and we'll be turning until the gyro sensor detects an angle of exactly 90 degrees and then we stop with motor D.
How does the program behave? Let's check at the software.
Again, at the end of the program you can see that the sensor returns a value of 96 so the program is not working as we would expect. I'm entering into these details because it's not intuitive but very logical and I've seen students that are looking at such programs and are wondering why this happens and why is it so non intuitive so I'll first show you the problem, this one that the sensor is not returning the correct value. Then we'll search for ways why. Let's see on the camera what happens with the robot. Running the same program.
The robot turns to more than 90 degrees but it does not return back.
Turning but although we've add the blocks for turning motor D in reverse and we would expect something like this to happen and to align to 90 degrees the robot is not returning. This is something that we'll solve in the next video.