Class IMUDevice

java.lang.Object
com.cdarobotics.cdalib.devices.Device
com.cdarobotics.cdalib.devices.sensors.IMUDevice

public class IMUDevice extends Device
A Device wrapping the universal IMU. The orientation is read once per update() and cached, so reading yaw/pitch/roll multiple times in a loop costs a single hardware read.

The IMU must be initialized (via imu.initialize(...) with your hub's orientation on the robot) before it is used — this wrapper does not initialize it. Getters reflect the value from the most recent update(), and return 0 before the first update.

  • Constructor Summary

    Constructors
    Constructor
    Description
    IMUDevice(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
    Resolves the IMU from the hardware map by configured name.
    IMUDevice(com.qualcomm.robotcore.hardware.IMU imu)
    Wraps an already-initialized IMU.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.qualcomm.robotcore.hardware.IMU
     
    double
    getPitch(org.firstinspires.ftc.robotcore.external.navigation.AngleUnit unit)
     
    double
    getRoll(org.firstinspires.ftc.robotcore.external.navigation.AngleUnit unit)
     
    double
    getYaw(org.firstinspires.ftc.robotcore.external.navigation.AngleUnit unit)
     
    void
    Resets the yaw so the current heading reads as zero.
    void
    Flush pending writes to, or refresh cached reads from, the underlying hardware.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • IMUDevice

      public IMUDevice(com.qualcomm.robotcore.hardware.IMU imu)
      Wraps an already-initialized IMU.
    • IMUDevice

      public IMUDevice(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
      Resolves the IMU from the hardware map by configured name. It must still be initialized separately.
  • Method Details

    • getYaw

      public double getYaw(org.firstinspires.ftc.robotcore.external.navigation.AngleUnit unit)
      Returns:
      the cached yaw (heading) in the requested unit.
    • getPitch

      public double getPitch(org.firstinspires.ftc.robotcore.external.navigation.AngleUnit unit)
      Returns:
      the cached pitch in the requested unit.
    • getRoll

      public double getRoll(org.firstinspires.ftc.robotcore.external.navigation.AngleUnit unit)
      Returns:
      the cached roll in the requested unit.
    • resetYaw

      public void resetYaw()
      Resets the yaw so the current heading reads as zero.
    • getImu

      public com.qualcomm.robotcore.hardware.IMU getImu()
      Returns:
      the wrapped SDK IMU, for operations not exposed here.
    • update

      public void update()
      Description copied from class: Device
      Flush pending writes to, or refresh cached reads from, the underlying hardware.
      Specified by:
      update in class Device