YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
yams::motorcontrollers::SmartMotorControllerCommandRegistry Class Reference

#include <SmartMotorControllerCommandRegistry.hpp>

Static Public Member Functions

static void AddCommand (const std::string &cmdName, wpi::cmd::SubsystemBase *subsystem, std::function< void()> callback)
 
static void AddCommand (const std::string &cmdName, wpi::cmd::SubsystemBase *subsystem, std::function< void()> callback, std::function< void()> onEnd)
 
static wpi::cmd::Command * GetCommand (const std::string &cmdName, wpi::cmd::SubsystemBase *subsystem)
 
static bool CommandExists (const std::string &cmdName, wpi::cmd::SubsystemBase *subsystem)
 
static void RemoveCommands (wpi::cmd::SubsystemBase *subsystem)
 
static void Clear ()
 

Detailed Description

Registry that aggregates per-subsystem commands from multiple SmartMotorControllers.

When multiple SmartMotorControllers belong to the same subsystem (e.g. a dual-motor arm), each one registers its live-tuning callback here. The registry creates a single combined command per subsystem that runs all registered callbacks on every periodic loop.

The published SmartDashboard path is: Mechanisms/Commands/SubsystemName%/CommandName%

Member Function Documentation

◆ AddCommand() [1/2]

static void yams::motorcontrollers::SmartMotorControllerCommandRegistry::AddCommand ( const std::string &  cmdName,
wpi::cmd::SubsystemBase *  subsystem,
std::function< void()>  callback 
)
static

Register a callback for a command on a subsystem.

If no command with this name exists for the subsystem yet, a new one is created and published to SmartDashboard. If one already exists, the callback is appended to it.

Parameters
cmdNameDisplay name for the command (e.g. "Live Tuning").
subsystemSubsystem that owns the command (used for requirement and naming).
callbackRunnable invoked each loop while the command is running.

◆ AddCommand() [2/2]

static void yams::motorcontrollers::SmartMotorControllerCommandRegistry::AddCommand ( const std::string &  cmdName,
wpi::cmd::SubsystemBase *  subsystem,
std::function< void()>  callback,
std::function< void()>  onEnd 
)
static

Register a callback for a command on a subsystem, with a callback run when the command ends.

Parameters
cmdNameDisplay name for the command (e.g. "Live Tuning").
subsystemSubsystem that owns the command (used for requirement and naming).
callbackRunnable invoked each loop while the command is running.
onEndRunnable invoked when the command ends.

◆ Clear()

static void yams::motorcontrollers::SmartMotorControllerCommandRegistry::Clear ( )
static

Destroy all registered commands and callbacks, and unpublish them from the Tuning tunables.

Must be called before program exit while WPILib's SendableRegistry is still alive, otherwise the CommandPtr destructors will attempt to lock an already-destroyed mutex and crash (SIGSEGV/exit 139).

◆ CommandExists()

static bool yams::motorcontrollers::SmartMotorControllerCommandRegistry::CommandExists ( const std::string &  cmdName,
wpi::cmd::SubsystemBase *  subsystem 
)
static

Check whether a command with the given name already exists for a subsystem.

Parameters
cmdNameCommand name.
subsystemSubsystem.
Returns
true if the command is already registered.

◆ GetCommand()

static wpi::cmd::Command * yams::motorcontrollers::SmartMotorControllerCommandRegistry::GetCommand ( const std::string &  cmdName,
wpi::cmd::SubsystemBase *  subsystem 
)
static

Get a registered command, such as the "Live Tuning" command, to schedule it from code.

Parameters
cmdNameCommand name.
subsystemSubsystem the command was registered for.
Returns
The command, or nullptr if none is registered under cmdName.

◆ RemoveCommands()

static void yams::motorcontrollers::SmartMotorControllerCommandRegistry::RemoveCommands ( wpi::cmd::SubsystemBase *  subsystem)
static

Remove all commands registered for a specific subsystem instance, and unpublish them from the Tuning tunables.

Call this when a subsystem 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
subsystemSubsystem whose commands should be removed.

The documentation for this class was generated from the following file: