In our previous posts (1, 2), we described what pivot turn and spin turn are and how to create reusable My Blocks for these two type of turns. In this post we will tell you how to create a reusable EV3 Gyro Turn My Block or EV3 Gyro Sensor Turn My Block to make both pivot and spin turns using EV3 Gyro Sensor. We will also tell you when to use gyro turn and how to turn your robot 90 degrees consistently and accurately.
For SPIKE Prime Gyro Turn My Block, please check this post.
EV3 Gyro Sensor and Gyro Sensor Blocks
EV3 Gyro Sensor measures the robot’s rotational motion and changes in its orientation. According to online help, the Wait Block comes in handy when we need to pause and wait for the rotation angle or rate to hit a specific value, or for it to change by a certain amount. On the other hand, the Gyro Sensor Block enables us to measure the rotation angle and/or rate, and receive the readings on a Numeric data wire. Additionally, we can compare the rotation angle or rate to a specific threshold and obtain a result on a Logic data wire. We can also reset the rotation angle back to zero for accurate measurements.
The programs shown in following sections assume that the gyro sensor is connected to port 4 of the EV3 brick.
Make a Turn with Gyro Sensor
The Gyro Sensor does a good job of monitoring the overall rotation angle in degrees. This enables us to use the rotation angle to determine how much the robot has turned. If we want to stop the robot once it has turned a specific number of degrees, we can make use of the Wait – Gyro Sensor block, which is illustrated in the following screenshot:
In this post, we use Wait – Gyro Sensor block to make turns. The following screenshot shows how to pivot turn right for 90 degrees.
The following screenshot shows how to spin turn left for 90 degrees.
As you can see from the screenshots, we use Math Block to calculate the actual degrees the Gyro Sensor needs to detect. For our robot, the degree is multiplied by a scaling factor of 0.83. For example, 90 * 0.83 = 74.7. What does it mean? It means that our robot will turn 90 degree when Gyro Sensor measures angle change of 74.7 degrees. You may wonder why? It is because Gyro Sensor reading lags the true measurements. The scaling factor reduces the amount of angle to turn to compensate for the lag.
The number 0.83 works fine for our robot. You may use another number for your robot. To find the right number, you can start with 0.8 and try to make your robot to turn 90 degrees. If your robot turn more than 90 degrees, try to reduce number. If less than 90 degrees, try to increase the number. And try to make your turn 90 degrees again until with a number it can turn 90 degrees.
Reusable EV3 Gyro Turn My Block
We can turn the Gyro turn program into a reusable EV3 Gyro Turn My Block as shown below.
The Gyro Turn My Block has three input parameters: degree to turn, power for B Motor, and power for C Motor. Set either B or C Motor’s power to 0 for pivot turn. Set B and C Motors’ power to opposite sign for spin turn. As you can see, we can use a single My Block to make spin turn and pivot turn.
Using the EV3 Gyro Turn My Block
After creating the Gyro Turn My Block, we can use it again and again to make turns consistently. Check out the following screenshot for an example of how to use the EV3 Gyro Turn My Block:
When to Use Gyro Turn
We made extensive use of the EV3 pivot turn My Block and spin turn My Block for the CITY SHAPER season. These two My Blocks proved to be sufficient for most circumstances. However, if the surface is slippery or if the robot is unbalanced, the Gyro Turn will function more effectively.
The single Gyro Turn My Block can also perform both pivot and spin turns, which streamlines our program.
However, the Gyro sensor is susceptible to a “drifting” problem that can cause significant issues. As a result, we recommend avoiding using Gyro Turn when possible. In a separate post, we will delve further into Gyro Drifting and offer suggestions for dealing with the problem via Gyro Calibration.