Inspiring Mindstorms EV3 Programming for FLL Part 11: EV3 Gyro Move Straight

When a robot is not balanced, or the map is not even, or it is moving over a field model, it may be tilted to one direction and  cannot stay moving straight. In these cases, we can use a Gyro Sensor to guide our robot in moving straight forward. Also, if our robot needs to move long distance,  say three feet, we will use Gyro Move Straight also.

In this post, we will show you how to program a robot to move in a straight line using a Gyro Sensor. Additionally, we’ll provide instructions on creating a reusable EV3 Gyro Move Straight My Block.

For example, for FLL City Shaper Black Circle mission, our load is on the left side of the robot. Without Gyro guiding, our robot will tilt to the left. We used a Gyro Move Straight program to help our robot move straight.

The following picture show the three possible ways when a robot moves forward.

1. Robot moves straight and there is no need for correction.

2. Robot tilts to the left. You want to turn your robot to the right by increasing the Motor B power and decreasing the Motor C power.

3. Robot tilts to the right. You want to turn your robot to the left by increasing the Motor C power and decreasing Motor B power.

EV3 Move Straight with Gyro
How EV3 Moving Straight with Gyro Works

We can use a Gyro Sensor to measure angle. If the Gyro’s angle measurement is negative, our robot is tilting to the left. If the Gyro’s angle measurement is positive, our robot is tilting to the right. And if the Gyro’s angle measurement is 0, our robot is moving straight.

Furthermore, the bigger the angle deviation, the more the power adjustment. This is called the proportional adjustment. As such, the power adjustment can be calculated as the following:

Power Adjustment = Kp * Angle Deviation

Where Kp is the proportional constant. It should be tuned for every robot. The bigger Kp, the higher will be the turning when there is an error. For our robot, we used -0.8 as the proportional constant. The power adjustment will be:

Motor B Power = Base Power + Power Adjustment = Base Power + Kp * Angle Deviation
Motor C Power = Base Power – Power Adjustment = Base Power – Kp * Angle Deviation

The angle deviation can be measured by using Gyro Sensor block‘s Measure – Angle mode as shown below:

Gyro Measure Angle
Gyro Measure Angle

The following is the EV3 Gyro Move Straight Program based on above description. The MyCheckDistance My Block is described in our previous post.

Unregulated Motor Block is used for driving the robot. The Unregulated Motor block does not include automatic motor control, like the normal Medium Motor block and the Large Motor block. This means that no automatic regulation on motor power will be included. The specified Power input is what is used to control the motor.

EV3 Gyro Move Straight Program
EV3 Gyro Move Straight Program

Creating EV3 Gyro Move Straight My Block

To make the blocks in the Loop block reusable, we can create a EV3 Gyro Move Straight My Block. First select those blocks, then select Tools → My Block Builder menu item as shown below.

Gyro Move Straight My Block
a) Gyro Move Straight My Block

Now enter the My Block’s name, description, and select an icon.

b) Gyro Move Straight My Block

Add the parameter for the Base Power.

Gyro Move Straight My Block
c) Gyro Move Straight My Block

Add the parameter for the distance to move forward.

Gyro Move Straight My Block
d) Gyro Move Straight My Block

At last, connect all the Parameters. Done!

Gyro Move Straight My Block
e) Gyro Move Straight My Block

Using the EV3 Gyro Move Straight My Block

The following program uses the EV3 Move Straight Gyro My Block we just created.

Using Gyro Move Straight My Block