Class PhoenixOdometryThread

java.lang.Object
java.lang.Thread
com.marswars.swerve_lib.PhoenixOdometryThread
All Implemented Interfaces:
Runnable

public class PhoenixOdometryThread extends Thread
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.

  • Method Details

    • configure

      public static void configure(String bus_name, double wheel_radius_m)
      Configures the PhoenixOdometryThread singleton.
      Parameters:
      bus_name - The CAN bus name the Phoenix devices are on
      wheel_radius_m - The wheel radius in meters
    • getInstance

      public static PhoenixOdometryThread getInstance()
      Gets the configured PhoenixOdometryThread singleton.
      Returns:
      the configured PhoenixOdometryThread
    • start

      public void start()
      Overrides:
      start in class Thread
    • registerGyro

      public void registerGyro(StatusSignal<Angle> yaw_signal)
      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 signal
      drive_signal - Drive position signal
    • registerSignal

      protected void registerSignal(BaseStatusSignal signal)
      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 seconds
      steer_positions - Steer positions in radians
      drive_positions - Drive positions in radians
    • enqueueGyroSamples

      public void enqueueGyroSamples(double[] timestamps, Rotation2d[] samples)
      Enqueues simulated gyro measurements (simulation only).
      Parameters:
      timestamps - Timestamps in seconds
      samples - Gyro yaw samples
    • getSwerveSamples

      public List<SwerveMeasurements.SwerveMeasurement> getSwerveSamples()
      Drains the measurement queues and returns synchronized swerve samples.
      Returns:
      list of combined swerve measurements
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread