Class LoggedSignals
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
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe CAN bus network that a group of signals is from -
Constructor Summary
ConstructorsConstructorDescriptionLoggedSignals(com.ctre.phoenix6.BaseStatusSignal... statusSignals) Creates a newLoggedSignalsinstance with an unnamed motor and defaults to registering signals toLoggedSignals.SignalLocation.RIOLoggedSignals(String motorName, com.ctre.phoenix6.BaseStatusSignal... statusSignals) Creates a newLoggedSignalsinstance with a named motor and defaults to registering signals toLoggedSignals.SignalLocation.RIO -
Method Summary
Modifier and TypeMethodDescriptionvoidDeregisters all signals in this instance from the currentLoggedSignals.SignalLocationvoidlogAll()Publishes the current value of each signal to SmartDashboard with the specified log pathstatic voidRefreshes all registered signalsvoidregister()Registers all signals in this instance to the currentLoggedSignals.SignalLocationwithLogPath(String logPath) Sets the SmartDashboard section to log values toRegisters a named motor with its own set of signalsMoves all signals to a differentLoggedSignals.SignalLocation
-
Constructor Details
-
LoggedSignals
Creates a new
LoggedSignalsinstance with a named motor and defaults to registering signals toLoggedSignals.SignalLocation.RIOThe logging path defaults to an empty string. Use
withLogPath(String)andwithSignalLocation(SignalLocation)to change it. It also registers the signals for you, so you don't have to callregister()- Parameters:
motorName- name of the motor whose signals are being registeredstatusSignals- the signals to manage, duplicates allowed but filtered out
-
LoggedSignals
public LoggedSignals(com.ctre.phoenix6.BaseStatusSignal... statusSignals) Creates a new
LoggedSignalsinstance with an unnamed motor and defaults to registering signals toLoggedSignals.SignalLocation.RIOThe logging path defaults to an empty string. Use
withLogPath(String)andwithSignalLocation(SignalLocation)to change it. It also registers the signals for you, so you don't have to callregister()- 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
LoggedSignalsinstance it is called on, so it uses the same logging path and signal location.- Parameters:
motorName- name of the motor whose signals are being registeredstatusSignals- the signals to manage, duplicates allowed but filtered out
-
withSignalLocation
Moves all signals to a different
LoggedSignals.SignalLocation- Parameters:
location- the target signal location- Returns:
- this instance for chaining
-
withLogPath
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 forSmartDashboardsignal logging- Returns:
- this instance for chaining
-
register
public void register()Registers all signals in this instance to the current
LoggedSignals.SignalLocationSHould 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.SignalLocationShould 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().
-