Package swervelib.imu

Class NavXSwerve

java.lang.Object
swervelib.imu.SwerveIMU
swervelib.imu.NavXSwerve

public class NavXSwerve extends SwerveIMU
Communicates with the NavX(AHRS) as the IMU.
  • Constructor Details

    • NavXSwerve

      public NavXSwerve(SerialPort.Port port)
      Constructor for the NavX(AHRS) swerve.
      Parameters:
      port - Serial Port to connect to.
    • NavXSwerve

      public NavXSwerve(SPI.Port port)
      Constructor for the NavX(AHRS) swerve.
      Parameters:
      port - SPI Port to connect to.
    • NavXSwerve

      public NavXSwerve(I2C.Port port)
      Constructor for the NavX(AHRS) swerve.
      Parameters:
      port - I2C Port to connect to.
  • Method Details

    • factoryDefault

      public void factoryDefault()
      Reset offset to current gyro reading. Does not call NavX(AHRS.reset()) because it has been reported to be too slow.
      Specified by:
      factoryDefault in class SwerveIMU
    • clearStickyFaults

      public void clearStickyFaults()
      Clear sticky faults on IMU.
      Specified by:
      clearStickyFaults in class SwerveIMU
    • setOffset

      public void setOffset(Rotation3d offset)
      Set the gyro offset.
      Specified by:
      setOffset in class SwerveIMU
      Parameters:
      offset - gyro offset as a Rotation3d.
    • setInverted

      public void setInverted(boolean invertIMU)
      Set the gyro to invert its default direction
      Specified by:
      setInverted in class SwerveIMU
      Parameters:
      invertIMU - invert gyro direction
    • getRawRotation3d

      public Rotation3d getRawRotation3d()
      Fetch the Rotation3d from the IMU without any zeroing. Robot relative.
      Specified by:
      getRawRotation3d in class SwerveIMU
      Returns:
      Rotation3d from the IMU.
    • getRotation3d

      public Rotation3d getRotation3d()
      Fetch the Rotation3d from the IMU. Robot relative.
      Specified by:
      getRotation3d in class SwerveIMU
      Returns:
      Rotation3d from the IMU.
    • getAccel

      public Optional<Translation3d> getAccel()
      Fetch the acceleration [x, y, z] from the IMU in meters per second squared. If acceleration isn't supported returns empty.
      Specified by:
      getAccel in class SwerveIMU
      Returns:
      Translation3d of the acceleration as an Optional.
    • getRate

      public double getRate()
      Fetch the rotation rate from the IMU in degrees per second. If rotation rate isn't supported returns empty.
      Specified by:
      getRate in class SwerveIMU
      Returns:
      Double of the rotation rate as an Optional.
    • getIMU

      public Object getIMU()
      Get the instantiated NavX(AHRS) IMU object.
      Specified by:
      getIMU in class SwerveIMU
      Returns:
      IMU object.