Package com.marswars.swerve_lib
Class PhoenixOdometryThread
java.lang.Object
java.lang.Thread
com.marswars.swerve_lib.PhoenixOdometryThread
- All Implemented Interfaces:
Runnable
Provides an interface for asynchronously reading high-frequency measurements to a set of queues.
This version is intended for Phoenix 6 devices on both the RIO and CANivore buses. When using a CANivore, the thread uses the "waitForAll" blocking method to enable more consistent sampling. This also allows Phoenix Pro users to benefit from lower latency between devices using CANivore time synchronization.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Method Summary
Modifier and TypeMethodDescriptionstatic voidConfigures the PhoenixOdometryThread singleton.voidenqueueGyroSamples(double[] timestamps, Rotation2d[] samples) Enqueues simulated gyro measurements (simulation only).voidenqueueModuleSamples(int index, double[] stamps, Rotation2d[] steer_positions, double[] drive_positions) Enqueues simulated module measurements (simulation only).static PhoenixOdometryThreadGets the configured PhoenixOdometryThread singleton.Drains the measurement queues and returns synchronized swerve samples.voidregisterGyro(StatusSignal<Angle> yaw_signal) Registers a gyro yaw signal for odometry sampling.voidregisterModule(int module_index, StatusSignal<Angle> steer_signal, StatusSignal<Angle> drive_signal) Registers a swerve module's steer and drive position signals for sampling.protected voidregisterSignal(BaseStatusSignal signal) Adds a signal to the internal list for synchronized sampling.voidrun()voidstart()Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, suspend, toString, yield
-
Method Details
-
configure
Configures the PhoenixOdometryThread singleton.- Parameters:
bus_name- The CAN bus name the Phoenix devices are onwheel_radius_m- The wheel radius in meters
-
getInstance
Gets the configured PhoenixOdometryThread singleton.- Returns:
- the configured PhoenixOdometryThread
-
start
public void start() -
registerGyro
Registers a gyro yaw signal for odometry sampling.- Parameters:
yaw_signal- The yaw status signal to sample
-
registerModule
public void registerModule(int module_index, StatusSignal<Angle> steer_signal, StatusSignal<Angle> drive_signal) Registers a swerve module's steer and drive position signals for sampling.- Parameters:
module_index- Index of the module (0-3)steer_signal- Steer position signaldrive_signal- Drive position signal
-
registerSignal
Adds a signal to the internal list for synchronized sampling.- Parameters:
signal- The status signal to add
-
enqueueModuleSamples
public void enqueueModuleSamples(int index, double[] stamps, Rotation2d[] steer_positions, double[] drive_positions) Enqueues simulated module measurements (simulation only).- Parameters:
index- Module index (0-3)stamps- Timestamps in secondssteer_positions- Steer positions in radiansdrive_positions- Drive positions in radians
-
enqueueGyroSamples
Enqueues simulated gyro measurements (simulation only).- Parameters:
timestamps- Timestamps in secondssamples- Gyro yaw samples
-
getSwerveSamples
Drains the measurement queues and returns synchronized swerve samples.- Returns:
- list of combined swerve measurements
-
run
public void run()
-