IMU
Providing rotational information about your robot
Resources
Implementation
Robot Class
public abstract class Robot extends LinearOpMode {
// Gyro and Angles
public IMU gyro;
public void initHardware() throws InterruptedException {
// Hubs
List<LynxModule> allHubs;
allHubs = hardwareMap.getAll(LynxModule.class);
for (LynxModule hub : allHubs) {
hub.setBulkCachingMode(LynxModule.BulkCachingMode.MANUAL);
}
// add your parameters are needed (process described in the FTC docs)
gyro = hardwareMap.get(IMU.class, "imu");
gyro.resetYaw();
}
//Get the robot's current heading
public double getAngleImu() {
//We choose to normalize the IMU's angle reading but you don't need to.
return normalize(
getRobotYawPitchRollAngles().getYaw(AngleUnit.DEGREES));
}
// Remaps the given angle into the range (-180, 180].
public static double normalize(double degrees) {
double normalized_angle = Angle.normalizePositive(degrees);
if (normalized_angle > 180) {
normalized_angle -= 360;
}
return normalized_angle;
}
// BULK-READING FUNCTIONS
public void resetCache() {
// Clears cache of all hubs
for (LynxModule hub : allHubs) {
hub.clearBulkCache();
}
}
@Override
public abstract void runOpMode() throws InterruptedException;
}OpMode
Anti-Tip
Last updated