-
Notifications
You must be signed in to change notification settings - Fork 118
Cpp Example: Register Named Commands
Michael Jansen edited this page Oct 9, 2023
·
4 revisions
You must register your named commands so that they can be used in the creation of Event Markers and Autos. All of your named commands need to be registered before you create a PathPlanner path or auto in your code. Failure to do so would mean that any named command registered after path/auto creation will not be used in those paths and autos. A recommended place to do this would be in RobotContainer, after the initialization of your subsystems and before the initialization of any commands that use PathPlanner.
All named commands are registered via static methods in the NamedCommands
class. The string used when registering a command should be identical to the one used in the PathPlanner GUI.
#include <pathplanner/lib/auto/NamedCommands.h>
#include <memory>
using namespace pathplanner;
RobotContainer::RobotContainer() : m_swerve(), m_exampleSubsystem() {
// Register Named Commands. You must pass either a CommandPtr rvalue or a shared_ptr to the command, not the command directly.
NamedCommands::registerCommand("autoBalance", std::move(m_swerve.autoBalanceCommand())); // <- This example method returns CommandPtr
NamedCommands::registerCommand("exampleCommand", std::move(m_exampleSubsystem.exampleCommand())); // <- This example method returns CommandPtr
NamedCommands::registerCommand("someOtherCommand", std::move(SomeOtherCommand().ToPtr()));
NamedCommands::registerCommand("someOtherCommandShared", std::make_shared<frc2::SomeOtherCommand>());
// Do all other initialization
configureButtonBindings();
// ...
}
- Controls & Shortcuts
- Editing Paths & Autos
- Navigation Menu
- Settings
- Project Browser
- Telemetry Page
- Navigation Grid Editor
- Register Named Commands
- Build an Auto
- Follow a Single Path
- Create a Path On-the-fly
- Path Groups
- Automatic Pathfinding
Advanced Usage
- Register Named Commands
- Build an Auto
- Follow a Single Path
- Create a Path On-the-fly
- Path Groups
- Automatic Pathfinding
Advanced Usage
- Register Named Commands
- Build an Auto
- Follow a Single Path
- Create a Path On-the-fly
- Path Groups
- Automatic Pathfinding