Class ImuSetup

java.lang.Object
com.crossbotics.ftchelper.hardware.ImuSetup

public final class ImuSetup extends Object
Starts the IMU (the hub's built-in turn sensor) in one line, and reads the heading.

The "heading" is which way the robot is pointing, in degrees.


 IMU imu = ImuSetup.get(hardwareMap, "imu",
         RevHubOrientationOnRobot.LogoFacingDirection.UP,
         RevHubOrientationOnRobot.UsbFacingDirection.FORWARD);
 double heading = ImuSetup.headingDeg(imu);   // counterclockwise is positive
 

You MUST give the directions the hub's logo and USB port face on YOUR robot. If they are wrong, the heading is wrong. See docs/modules/hardware.md for a picture. Why heading is counterclockwise-positive while turning is clockwise-positive: docs/conventions.md.

  • Method Summary

    Modifier and Type
    Method
    Description
    static com.qualcomm.robotcore.hardware.IMU
    get(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name, com.qualcomm.hardware.rev.RevHubOrientationOnRobot.LogoFacingDirection logo, com.qualcomm.hardware.rev.RevHubOrientationOnRobot.UsbFacingDirection usb)
    Gets the IMU, tells it how the hub is mounted, and sets the heading to 0.
    static double
    headingDeg(com.qualcomm.robotcore.hardware.IMU imu)
    The robot's heading in degrees, from -180 to 180.

    Methods inherited from class java.lang.Object

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

    • get

      public static com.qualcomm.robotcore.hardware.IMU get(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name, com.qualcomm.hardware.rev.RevHubOrientationOnRobot.LogoFacingDirection logo, com.qualcomm.hardware.rev.RevHubOrientationOnRobot.UsbFacingDirection usb)
      Gets the IMU, tells it how the hub is mounted, and sets the heading to 0. Call it once in INIT: starting the IMU takes a short moment.
      Parameters:
      hardwareMap - the OpMode's hardwareMap
      name - the IMU's configuration name (usually "imu")
      logo - which way the REV logo on the hub faces
      usb - which way the hub's USB port faces
      Returns:
      the IMU, ready to read
      Throws:
      IllegalStateException - if the IMU does not start
    • headingDeg

      public static double headingDeg(com.qualcomm.robotcore.hardware.IMU imu)
      The robot's heading in degrees, from -180 to 180. Turning left (counterclockwise) makes it bigger. It is 0 where the robot pointed at the last resetYaw().

      "Yaw" is the sensor word for turning flat on the floor, like a spinning top.

      Parameters:
      imu - the IMU from get(com.qualcomm.robotcore.hardware.HardwareMap, java.lang.String, com.qualcomm.hardware.rev.RevHubOrientationOnRobot.LogoFacingDirection, com.qualcomm.hardware.rev.RevHubOrientationOnRobot.UsbFacingDirection)
      Returns:
      the heading in degrees, -180 to 180, counterclockwise = positive