Class SmartMotorControllerCommandRegistry
java.lang.Object
yams.commands3.telemetry.SmartMotorControllerCommandRegistry
Registry for
Command instances associated with a
SmartMotorController. Mechanisms register setpoint commands
here so the scheduler can manage them.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddCommand(String cmdName, org.wpilib.command3.Mechanism mechanism, Runnable callback) Add a command to the registry.static voidaddCommand(String cmdName, org.wpilib.command3.Mechanism mechanism, Runnable callback, Runnable onEnd) Add a command to the registry, with aRunnablerun when the shared command ends.static booleancommandExists(String cmdName, org.wpilib.command3.Mechanism mechanism) Check if a command exists.static Optional<org.wpilib.command3.Command> getCommand(String cmdName, org.wpilib.command3.Mechanism mechanism) Get a registered command, such as the "Live Tuning" command, to schedule it from code.static voidremoveCommands(org.wpilib.command3.Mechanism mechanism) Remove all commands registered for the given mechanism instance.
-
Method Details
-
addCommand
public static void addCommand(String cmdName, org.wpilib.command3.Mechanism mechanism, Runnable callback) Add a command to the registry.- Parameters:
cmdName- Command name to publish to NetworkTables.mechanism- Mechanism to create the command for.callback- Runnable to be added to the shared command.- Throws:
IllegalStateException- if a differentMechanisminstance with the same name has already registered a command undercmdName.
-
addCommand
public static void addCommand(String cmdName, org.wpilib.command3.Mechanism mechanism, Runnable callback, Runnable onEnd) Add a command to the registry, with aRunnablerun when the shared command ends.- Parameters:
cmdName- Command name to publish to NetworkTables.mechanism- Mechanism to create the command for.callback- Runnable to be added to the shared command.onEnd- Runnable run when the shared command ends.- Throws:
IllegalStateException- if a differentMechanisminstance with the same name has already registered a command undercmdName.
-
getCommand
public static Optional<org.wpilib.command3.Command> getCommand(String cmdName, org.wpilib.command3.Mechanism mechanism) Get a registered command, such as the "Live Tuning" command, to schedule it from code.- Parameters:
cmdName- Command name.mechanism- Mechanism the command was registered for.- Returns:
- The command, or empty if none is registered under
cmdName.
-
commandExists
Check if a command exists.- Parameters:
cmdName- Command name.mechanism- Mechanism.- Returns:
- True if command exists.
-
removeCommands
public static void removeCommands(org.wpilib.command3.Mechanism mechanism) Remove all commands registered for the given mechanism instance.Call this when a mechanism is being torn down (e.g. between tests) so that a new instance with the same name can register without triggering the conflict check.
- Parameters:
mechanism- Mechanism whose commands should be removed.
-