Class LoggedSignals

java.lang.Object
com.stuypulse.robot.util.LoggedSignals

public class LoggedSignals extends Object

A container and handler for Phoenix's StatusSignals

Allows for compartmentalization of signals, which can be done by subsystem and by motor, and easy handling and logging.

Usage example:


 // ... imports
 public class SubsystemImpl extends SubsystemBase {
     private final TalonFX motor1;
     private final TalonFX motor2;
     private final LoggedSignals signals;
 
     public SubsystemImpl() {
         motor1 = new TalonFX(6);
         motor2 = new TalonFX(7);
         signals = new LoggedSignals(
             "Motor Number 1", 
             motor1.getVelocity(),
             motor1.getStatorCurrent(),
             motor1.getSupplyCurrent()
         ).addMotor(
             "Motor Number 2", 
             motor2.getVelocity(),
             motor2.getStatorCurrent(),
             motor2.getSupplyCurrent()
         );
     }
 
     @Override
     public void periodic() {
         // ... other logic
         signals.logAll(); // call after the motor control logic is applied
     }
 }
 
  • Constructor Details

    • LoggedSignals

      public LoggedSignals(String motorName, com.ctre.phoenix6.BaseStatusSignal... statusSignals)

      Creates a new LoggedSignals instance with a named motor and defaults to registering signals to LoggedSignals.SignalLocation.RIO

      The logging path defaults to an empty string. Use withLogPath(String) and withSignalLocation(SignalLocation) to change it. It also registers the signals for you, so you don't have to call register()

      Parameters:
      motorName - name of the motor whose signals are being registered
      statusSignals - the signals to manage, duplicates allowed but filtered out
    • LoggedSignals

      public LoggedSignals(com.ctre.phoenix6.BaseStatusSignal... statusSignals)

      Creates a new LoggedSignals instance with an unnamed motor and defaults to registering signals to LoggedSignals.SignalLocation.RIO

      The logging path defaults to an empty string. Use withLogPath(String) and withSignalLocation(SignalLocation) to change it. It also registers the signals for you, so you don't have to call register()

      Parameters:
      statusSignals - the signals to manage, duplicates allowed but filtered out
  • Method Details

    • withMotor

      public LoggedSignals withMotor(String motorName, com.ctre.phoenix6.BaseStatusSignal... statusSignals)

      Registers a named motor with its own set of signals

      Adds to the internal set of the LoggedSignals instance it is called on, so it uses the same logging path and signal location.

      Parameters:
      motorName - name of the motor whose signals are being registered
      statusSignals - the signals to manage, duplicates allowed but filtered out
    • withSignalLocation

      public LoggedSignals withSignalLocation(LoggedSignals.SignalLocation location)

      Moves all signals to a different LoggedSignals.SignalLocation

      Parameters:
      location - the target signal location
      Returns:
      this instance for chaining
    • withLogPath

      public LoggedSignals withLogPath(String logPath)

      Sets the SmartDashboard section to log values to

      For example, the path "Shooter/" will log values like "Shooter/PositionRotations" if no motor name was specified.

      Parameters:
      logPath - the prefix string for SmartDashboard signal logging
      Returns:
      this instance for chaining
    • register

      public void register()

      Registers all signals in this instance to the current LoggedSignals.SignalLocation

      SHould be called whenever the internal signal set is added to. Signal locations use a set internally, so no need to worry about duplicates

    • deregister

      public void deregister()

      Deregisters all signals in this instance from the current LoggedSignals.SignalLocation

      Should be called whenever stuff is removed from the internal signal set. Signal locations use a set internally, so no need to worry about duplicates

    • logAll

      public void logAll()

      Publishes the current value of each signal to SmartDashboard with the specified log path

      Should be called after refreshAll(). Iterates over the motors and logs the signal values to SmartDashboard

    • refreshAll

      public static void refreshAll()

      Refreshes all registered signals

      Should be called once per robot periodic loop before reading any signal values or calling logAll().