Advanced Techniques for EV3 Classroom FLL Programming Part 4: Gyro Turn

In our previous posts (1, 2), we described what pivot turn and spin turn are and how to create programs for these two types of turns. In this post we will tell you how to write an EV3 classroom Gyro Turn program 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 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. Additionally, we can compare the rotation angle or rate to a specific threshold and obtain a result using logic compare operator. 

The programs shown in following sections assume that the gyro sensor is connected to port 2 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 Gyro Angle block, which is illustrated in the following screenshot:

EV3 Classroom Gyro Angle Block

In this post, we use Gyro Angle block to make turns. The following screenshot shows how to spin turn right for 90 degrees.

EV3 Classroom Gyro Spin Turn

The following screenshot shows how to pivot turn left for 90 degrees.

EV3 Classroom Gyro Pivot Turn

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.9. For example, 90 * 0.9 = 81. What does it mean? It means that our robot will turn 90 degrees when Gyro Sensor measures angle change of 81 degrees. You may wonder why? It is because Gyro Sensor reading lags the true measurements.  The adjustment factor reduces the amount of angle to turn to compensate for the lag.

The number 0.9 works fine for our robot. You may use another number for your robot. To find the right number, you can start with 0.9 and try to make your robot to turn 90 degrees. If your robot turns 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 Classroom Gyro Turn My Block

We can turn the Gyro turn program into a reusable EV3 Classroom Gyro Turn My Block as shown below.

EV3 Classroom Gyro Turn My Block Step 1

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 both spin turn and pivot turn.

The finished My Block is shown as the following.

EV3 Classroom Gyro Turn My Block Step 2

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:

Using EV3 Classroom 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 FLL CITY SHAPER, REPLAY, and CARGO CONNECT seasons. 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.