Class Navx
java.lang.Object
com.studica.frc.Navx
- All Implemented Interfaces:
AutoCloseable
Studica NavX3 IMU over CAN or USB.
Any number of Navx objects can be open, one per device. Data arrives in the background;
getters return the latest value, or Optional.empty() when that message group isn't
streaming or its data has gone stale.
If the device can't be opened, the error is reported to the Driver Station and the object
stays inert: getters return empty and commands return Status.INVALID_HANDLE.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordLinear acceleration along each axis.static final recordInternal state of the sensor-fusion filter, for diagnosing calibration.static final recordAngular velocity about each axis.static final recordMagnetic field in microtesla.static enumMessage groups the NavX3 can stream.static final recordRaw self-test codes as reported by the IMU. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()enableMessages(Navx.Message... messages) Chooses which message groups stream.static NavxfromSerialDevice(String devicePath, int updateRateHz) Opens a NavX3 on an explicit serial device.Gets the sensor-fusion filter state, for diagnosing calibration.Optional<org.wpilib.units.measure.Angle> getAngle()Gets the continuous heading, which does not wrap at +/-180 degrees.Gets the angular velocity.Asks the device for its firmware version.Gets the linear acceleration.Gets the magnetometer reading.Optional<org.wpilib.units.measure.Angle> getPitch()Gets the pitch.Optional<org.wpilib.math.geometry.Quaternion> Gets the fused gyro + accelerometer orientation.Optional<org.wpilib.math.geometry.Quaternion> Gets the fused gyro + accelerometer + magnetometer orientation.Optional<org.wpilib.units.measure.Angle> getRoll()Gets the roll.Optional<org.wpilib.math.geometry.Rotation2d> Gets the heading as a Rotation2d, fromgetYaw().Optional<org.wpilib.math.geometry.Rotation3d> Gets the orientation as a Rotation3d, from the 6-axis quaternion.Optional<int[]> Asks the device for its unique ID.Optional<org.wpilib.units.measure.Temperature> Gets the gyroscope chip temperature.Optional<org.wpilib.units.measure.Time> Gets when the newest sample was taken, on the same clock asTimer.getTimestamp(), e.g.Optional<org.wpilib.units.measure.Angle> getYaw()Gets the heading.booleanReturns whether the device is talking.booleanisOpen()Returns whether the device was opened.booleanReturns whethergetTimestamp()is the measurement time.resetYaw()Resets yaw to zero.selfTest()Runs the IMU self test.setOutputRate(int hz) Sets the output data rate.static Navxusb()Opens the NavX3 plugged into any USB port, at 100 Hz.static Navxusb(int updateRateHz) Opens the NavX3 plugged into any USB port.static NavxOpens the NavX3 in a specific SystemCore USB port, at 100 Hz.static NavxOpens the NavX3 in a specific SystemCore USB port.use9AxisYaw(boolean enable) Chooses whether the yaw estimate uses the magnetometer.
-
Constructor Details
-
Navx
public Navx(int canId) Opens a NavX3 on CAN bus S0 at 100 Hz.- Parameters:
canId- CAN device ID set on the NavX3
-
Navx
public Navx(int canId, org.wpilib.hardware.bus.CANPort bus) Opens a NavX3 on CAN at 100 Hz.- Parameters:
canId- CAN device ID set on the NavX3bus- CAN port it is wired to
-
Navx
public Navx(int canId, org.wpilib.hardware.bus.CANPort bus, int updateRateHz) Opens a NavX3 on CAN.- Parameters:
canId- CAN device ID set on the NavX3bus- CAN port it is wired toupdateRateHz- output data rate, 1-200 Hz
-
-
Method Details
-
usb
Opens the NavX3 plugged into any USB port, at 100 Hz. It may be moved between USB ports while running. With more than one NavX3 on USB, useusb(UsbPort)for each instead.- Returns:
- the Navx
-
usb
Opens the NavX3 plugged into any USB port. It may be moved between USB ports while running.- Parameters:
updateRateHz- output data rate, 1-200 Hz- Returns:
- the Navx
-
usb
-
usb
-
fromSerialDevice
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
isOpen
public boolean isOpen()Returns whether the device was opened.- Returns:
- false if the device could not be opened or has been closed
-
isConnected
public boolean isConnected()Returns whether the device is talking.- Returns:
- true if data arrived recently
-
getYaw
Gets the heading.- Returns:
- yaw, typically [-180, 180] degrees, or empty if not streaming
-
getPitch
Gets the pitch.- Returns:
- pitch, typically [-90, 90] degrees, or empty if not streaming
-
getRoll
Gets the roll.- Returns:
- roll, typically [-180, 180] degrees, or empty if not streaming
-
getAngle
Gets the continuous heading, which does not wrap at +/-180 degrees.- Returns:
- the angle, or empty if not streaming
-
getRotation2d
-
getRotation3d
Gets the orientation as a Rotation3d, from the 6-axis quaternion.- Returns:
- the orientation, or empty if not streaming
-
getQuaternion6d
Gets the fused gyro + accelerometer orientation.- Returns:
- the quaternion, or empty if not streaming
-
getQuaternion9d
Gets the fused gyro + accelerometer + magnetometer orientation.- Returns:
- the quaternion, or empty if not streaming
-
getAngularVelocity
Gets the angular velocity.- Returns:
- angular velocity about each axis, or empty if not streaming
-
getLinearAcceleration
Gets the linear acceleration.- Returns:
- acceleration along each axis, or empty if not streaming
-
getMagneticField
Gets the magnetometer reading.- Returns:
- the magnetic field, or empty if not streaming
-
getAlgorithmState
Gets the sensor-fusion filter state, for diagnosing calibration.- Returns:
- the filter state, or empty if not streaming
-
getTemperature
Gets the gyroscope chip temperature.- Returns:
- the temperature, or empty if not streaming
-
getTimestamp
Gets when the newest sample was taken, on the same clock asTimer.getTimestamp(), e.g. for a pose estimator. Over CAN FD and USB this is when the NavX3 measured it, once its clock is synced (seeisTimeSynced()); otherwise it is when the sample arrived.- Returns:
- the timestamp, or empty if not streaming
-
isTimeSynced
public boolean isTimeSynced()Returns whethergetTimestamp()is the measurement time. The NavX3's clock syncs within about a second of connecting over CAN FD or USB; classic CAN only has arrival times.- Returns:
- true if the newest sample's timestamp is when it was measured
-
resetYaw
-
setOutputRate
Sets the output data rate.- Parameters:
hz- rate, 1-200 Hz- Returns:
- the result
-
use9AxisYaw
Chooses whether the yaw estimate uses the magnetometer.- Parameters:
enable- true for 9-axis yaw (with magnetometer), false for 6-axis- Returns:
- the result
-
getFirmwareVersion
Asks the device for its firmware version. Blocks until it answers.- Returns:
- the version, or empty if the device did not answer
-
getSensorUuid
Asks the device for its unique ID. Blocks until it answers.- Returns:
- the 96-bit ID as three words, or empty if the device did not answer
-
selfTest
Runs the IMU self test. Blocks for the few seconds it takes; meanwhile the NavX3 sends no data, so the getters return empty. Keep the robot still.- Returns:
- the result codes, or empty if unsupported or the device did not answer
-