Lesson 12.1: Initializing the REV Hub Gyro and Setting Robot Orientation
Why Orientation Configuration Matters
The IMU inside the REV Control Hub is a physical chip soldered to the Hub's circuit board. It measures acceleration and rotation along its X, Y, and Z axes using its own internal frame of reference. Those internal axes are fixed to the chip, not to the robot. When the Hub is mounted flat on a robot with its logo facing up, the chip's Z-axis happens to point straight up, which aligns with how FTC defines the "turning" axis. But teams frequently mount the Control Hub on a side panel, at an angle, or upside down to fit their robot's geometry. In every one of those cases, the chip's internal axes no longer align with the field's axes, and without correction, every heading value the IMU reports will be mathematically wrong.
The SDK asks you to declare how the Hub is physically mounted, then performs the corresponding coordinate transformation internally. With the directions configured correctly, yaw represents rotation around the robot's vertical axis without requiring a custom mounting transform.
The RevHubOrientationOnRobot Class
Starting with FTC SDK version 8.1, physical mounting is declared using the RevHubOrientationOnRobot class. Its constructor takes two enum values:
LogoFacingDirection: which direction the REV logo on the face of the Hub is pointing.UsbFacingDirection: which direction the USB ports on the Hub are facing.
Together, these two perpendicular directions specify the Hub's orientation in three-dimensional space. Wrap the orientation object inside an IMU.Parameters object and pass it into imu.initialize(). A mounting declaration that does not match the physical robot can map yaw, pitch, and roll onto the wrong robot axes.
Valid direction values for both enums are: UP, DOWN, FORWARD, BACKWARD, LEFT, and RIGHT. "Forward" is defined as the direction the robot drives toward during normal operation.
- SDK classes and signatures: FTC RobotCore Javadocs
- Hardware mounting context: REV DUO Control System
If yaw changes when you tilt the robot, the Hub orientation is probably declared wrong. Put the robot on blocks, rotate it by hand, and verify yaw, pitch, and roll one axis at a time before tuning autonomous turns.
Annotated Code
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.IMU;
import com.qualcomm.hardware.rev.RevHubOrientationOnRobot;
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
@TeleOp(name="IMU_Init_Demo")
public class ImuInitDemo extends LinearOpMode {
private IMU imu;
@Override
public void runOpMode() {
imu = hardwareMap.get(IMU.class, "imu");
// Declare how the Control Hub is physically mounted on the robot.
// This example: Hub lying flat with logo facing up and USB ports facing forward.
RevHubOrientationOnRobot orientation = new RevHubOrientationOnRobot(
RevHubOrientationOnRobot.LogoFacingDirection.UP,
RevHubOrientationOnRobot.UsbFacingDirection.FORWARD
);
// Pass the orientation to the IMU through IMU.Parameters.
// Skipping this call will produce incorrect angle readings.
imu.initialize(new IMU.Parameters(orientation));
telemetry.addData("IMU", "Initialized successfully");
telemetry.update();
waitForStart();
while (opModeIsActive()) {
// Heading is readable immediately after initialization completes
double heading = imu.getRobotYawPitchRollAngles()
.getYaw(AngleUnit.DEGREES);
telemetry.addData("Heading (deg)", "%.1f", heading);
telemetry.update();
}
}
}
Fill-in-the-Blank Practice
- The class used to declare how the Control Hub is physically mounted on the robot is
__________. - To provide the mounting configuration to the IMU, you pass an orientation object into
imu.initialize(new IMU.__________(orientation)). - The two enum parameters required by
RevHubOrientationOnRobotareLogoFacingDirectionand__________.
Show answers
RevHubOrientationOnRobotParametersUsbFacingDirection
Simulator Challenge
Use the simulator below to complete the vertical Control Hub IMU configuration. The editor starts with incomplete starter code, so fill in the orientation object and initialization call before checking the 3D hub view.
Ready to move on?
Only mark complete if you genuinely understand the material. Your progress will be saved in this browser.
Stuck on this lesson?
Ask about anything on this page. It can see which lesson you have open and which part you are reading.