The Gyro sensor in LEGO Mindstorms EV3 sets is new for the sets and we answer basic questions about its usage. The sensor detect when the whole constructions turns at a particular angle, but there are a number of gotchas in using it.
- 01 Jan 2017
The Gyro Sensor could be attached and be useful in almost any robot construction. Using it during a FIRST LEGO League (FLL) or World Robotics Olympiad (WRO) competition is also possible and with a little programing could solve many challenges.
The sensor detects Angle on which it has rotate or the Rate at which it is rotating. Knowing the angle of rotation is a precision way to know where the robot is in space.
Instructions for building the EasyBot are available at:
In this series of video tutorials we'll do a short introduction into the EV3 Mindstorms gyro sensor. How you can use it, what's the purpose and how you program this sensor.
Again it will be a very basic introduction so do not expect especially from this course any more advanced stuff. But we'll enter into more advanced stuff in the next videos. Gyro sensor, so with the gyro sensor first you have to do is to add this sensor to the robot. I'll now remove the light sensor, from previous tutorials and I'll add the gyro sensor. Of course you can add it in many different ways, I'll just add it on this attachment and I'll attach the cable to the gyro sensor. In my case the gyro sensor is attached to port 3. Now what the gyro sensor does is it can tell you several things. The thing that we are interested in now is that the gyro sensor can give you the angle of rotation, how much have you rotated he robot. If this is 0 when you rotate the robot, this will 90 degrees, this will be 180 and this will be one full turn. You might remember that when you program the robot and you set the number of rotations that you want one of the motors to turn if the motor turns for one rotation or 360 degrees, this does not mean that the whole robot will turn 360 degrees it will be only the motor and it might, depending on the size of the wheel and the construction of the robot, turning the motor for 360 degrees might turn the robot, but in most of the cases it won't turn the robot for one full rotation. This is something that we'll use the gyro sensor, to tell us when have we reached 90 degrees, so that we are sure that we can turn the robot to a 90 degrees angle. Let's check out the program. In the program what I would like to do is to turn the robot with motor A. I'll configure it to turn forward. This will make our robot turn left. We are turning motor A, but we are turning it just on, not for a certain number of rotations, just on. This motor turns and the whole robot turns with the motor. Then we are waiting until as with the other sensors, until something happens. Until an event happens. In this case we are waiting for the gyro sensor to reach an angle of exactly 90 degrees. So we are waiting for the gyro sensor to reach an angle of 90 degrees. It's not a good practice to set this comparison to equal so we want to set it to greater than, or equal, because it might be 91 degrees depending on the configuration of the sensor.
That's why we are setting it to greater than or equal to 90 degrees. Again, we are turning with motor A until the gyro sensor detects that the whole robot has turned to a 90 degree angle and then we stop with motor A.
Something that you should notice is again that the gyro sensor is attached to port 3 that's the default port for the gyro sensor. Download and run the program. Start.
Now what you see here is that the program is actually not correct. We are turning with motor A and we would expect to stop at 90 degrees. Again, we start the program.
Something in our very simple program is not working and that something that most of the rookie teams and students that are introduced to the EV3 software are wondering around and the problem is that this sensor detects the angle of turning, but this angle can be positive or negative. When we are turning in this direction then angle that the sensor detects is negative and when we are turning in this direction the sensor detects a positive angle of turning. That's quite of distinction because here the sensor returns negative numbers, as an angle of turning, we can't actually stop our program because we are expecting for something greater than 90 degrees, but it's always a negative. I'll show it on the software. Download and run the program. Let's just set the angle to 0 and I'll now run the program.
What you'll notice is that right here, when we detect the value for the sensor
we see that the value is minus 4 hundred and something. While the robot is turning the angle returned from the sensor is negative. Let's turn it again.
It turns, I'll stop the program, zoom it and the value is negative. In order to detect a 90 degrees angle, we must turn in the other direction. What you have to remember from this video is the gyro sensor returns the angle of turning of the whole construction in space, the angle space and it has a positive value and a negative value depending on the direction in which we are turning. If we are turning in this direction it has a negative value. If we are turning in this direction it has a positive value.