Skip to main content

IMUs / Gyros

What even is an IMU?

An IMU is an acronym for Internal Measurement Unit. In laymans terms, a gyro.

A ev3 gyro

You may recognise this gyro from Lego Mindstorms!

IMUs can measure the speed of your robot, the acceleration of it, and the orientation.

How do we find the orientation of our robot?

The tricky thing is, all of the depends on how your Control Hub is set up.

We recommend that you try all 3 functions out before implementing them in your program, due to the fact that the function returns different values based on how the control hub is on the robot.

To find the rotational data, we first have to establish a RevImu object, which is used to find the rotation of the robot.

We first have to include the IMU.

// Add this to the top of your code.
import org.ftc17191.ftclayer.hardware.imu.RevImu;

Then, we create a RevImu function. This is used as our imu in the program.

RevImu imu = new RevImu(hardwareMap, "imu");

IMPORTANT! Rev Hub IMUS always exist on I2C port 0. Meaning you have to set up the IMU on port 0 of the I2C menu.

Now we can use the following functions to get orientation

double heading = imu.getHeading();
double pitch = imu.getPitch();
double roll = imu.getRoll();

// Radian equivalents
double heading = imu.getHeadingRadians();
double pitch = imu.getPitchRadians();
double roll = imu.getRollRadians();