[cmd2] Flatten wpi::cmd::cmd to wpi::cmd (#8764)

Fixes #8763
This commit is contained in:
sciencewhiz
2026-04-13 21:48:13 -07:00
committed by GitHub
parent f89cf297e4
commit 613c86d1d7
36 changed files with 185 additions and 204 deletions

View File

@@ -13,7 +13,7 @@ RobotContainer::RobotContainer() {
ConfigureButtonBindings();
// Set up default drive command
m_drive.SetDefaultCommand(wpi::cmd::cmd::Run(
m_drive.SetDefaultCommand(wpi::cmd::Run(
[this] {
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
-m_driverController.GetRightX());
@@ -42,5 +42,5 @@ void RobotContainer::ConfigureButtonBindings() {
wpi::cmd::CommandPtr RobotContainer::GetAutonomousCommand() {
// Runs the chosen command in autonomous
return wpi::cmd::cmd::None();
return wpi::cmd::None();
}

View File

@@ -36,9 +36,9 @@ class RobotContainer {
// RobotContainer-owned commands
wpi::cmd::CommandPtr m_driveHalfVelocity =
wpi::cmd::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {});
wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {});
wpi::cmd::CommandPtr m_driveFullVelocity =
wpi::cmd::cmd::RunOnce([this] { m_drive.SetMaxOutput(1); }, {});
wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(1); }, {});
void ConfigureButtonBindings();
};

View File

@@ -24,7 +24,7 @@ RobotContainer::RobotContainer() {
ConfigureButtonBindings();
// Set up default drive command
m_drive.SetDefaultCommand(wpi::cmd::cmd::Run(
m_drive.SetDefaultCommand(wpi::cmd::Run(
[this] {
m_drive.ArcadeDrive(-m_driverController.GetLeftY(),
-m_driverController.GetRightX());
@@ -41,9 +41,8 @@ void RobotContainer::ConfigureButtonBindings() {
m_driverController.WestFace().OnTrue(m_hatch.ReleaseHatchCommand());
// While holding Right Bumper, drive at half velocity
m_driverController.RightBumper()
.OnTrue(wpi::cmd::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {}))
.OnFalse(
wpi::cmd::cmd::RunOnce([this] { m_drive.SetMaxOutput(1.0); }, {}));
.OnTrue(wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {}))
.OnFalse(wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(1.0); }, {}));
}
wpi::cmd::Command* RobotContainer::GetAutonomousCommand() {

View File

@@ -33,7 +33,7 @@ wpi::cmd::CommandPtr autos::SimpleAuto(DriveSubsystem* drive) {
wpi::cmd::CommandPtr autos::ComplexAuto(DriveSubsystem* drive,
HatchSubsystem* hatch) {
return wpi::cmd::cmd::Sequence(
return wpi::cmd::Sequence(
// Drive forward the specified distance
wpi::cmd::FunctionalCommand(
// Reset encoders on command start

View File

@@ -31,7 +31,7 @@ void RapidReactCommandBot::ConfigureBindings() {
// Fire the shooter with the South Face button
m_driverController.SouthFace().OnTrue(
wpi::cmd::cmd::Parallel(
wpi::cmd::Parallel(
m_shooter.ShootCommand(ShooterConstants::kShooterTarget),
m_storage.RunCommand())
// Since we composed this inline we should give it a name

View File

@@ -21,7 +21,7 @@ Shooter::Shooter() {
wpi::cmd::CommandPtr Shooter::ShootCommand(
wpi::units::turns_per_second_t setpoint) {
return wpi::cmd::cmd::Parallel(
return wpi::cmd::Parallel(
// Run the shooter flywheel at the desired setpoint using
// feedforward and feedback
Run([this, setpoint] {
@@ -32,7 +32,7 @@ wpi::cmd::CommandPtr Shooter::ShootCommand(
}),
// Wait until the shooter has reached the setpoint, and then
// run the feeder
wpi::cmd::cmd::WaitUntil([this] {
wpi::cmd::WaitUntil([this] {
return m_shooterFeedback.AtSetpoint();
}).AndThen([this] { m_feederMotor.SetThrottle(1.0); }))
.WithName("Shoot");

View File

@@ -20,8 +20,8 @@ void RobotContainer::ConfigureButtonBindings() {
[this] { return -m_controller.GetRawAxis(2); }));
// Example of how to use the onboard IO
m_onboardButtonA.OnTrue(wpi::cmd::cmd::Print("Button A Pressed"))
.OnFalse(wpi::cmd::cmd::Print("Button A Released"));
m_onboardButtonA.OnTrue(wpi::cmd::Print("Button A Pressed"))
.OnFalse(wpi::cmd::Print("Button A Released"));
// Setup SmartDashboard options.
m_chooser.SetDefaultOption("Auto Routine Distance", &m_autoDistance);

View File

@@ -23,8 +23,8 @@ Drive::Drive() {
wpi::cmd::CommandPtr Drive::ArcadeDriveCommand(std::function<double()> fwd,
std::function<double()> rot) {
return wpi::cmd::cmd::Run(
[this, fwd, rot] { m_drive.ArcadeDrive(fwd(), rot()); }, {this})
return wpi::cmd::Run([this, fwd, rot] { m_drive.ArcadeDrive(fwd(), rot()); },
{this})
.WithName("Arcade Drive");
}

View File

@@ -15,7 +15,7 @@ Shooter::Shooter() {
wpi::cmd::CommandPtr Shooter::RunShooterCommand(
std::function<double()> shooterVelocity) {
return wpi::cmd::cmd::Run(
return wpi::cmd::Run(
[this, shooterVelocity] {
m_shooterMotor.SetVoltage(
wpi::units::volt_t{m_shooterFeedback.Calculate(

View File

@@ -21,16 +21,16 @@ void RobotContainer::ConfigureButtonBindings() {
[this] { return -m_controller.GetRawAxis(2); }));
// Example of how to use the onboard IO
m_userButton.OnTrue(wpi::cmd::cmd::Print("USER Button Pressed"))
.OnFalse(wpi::cmd::cmd::Print("USER Button Released"));
m_userButton.OnTrue(wpi::cmd::Print("USER Button Pressed"))
.OnFalse(wpi::cmd::Print("USER Button Released"));
wpi::cmd::JoystickButton(&m_controller, 1)
.OnTrue(wpi::cmd::cmd::RunOnce([this] { m_arm.SetAngle(45_deg); }, {}))
.OnFalse(wpi::cmd::cmd::RunOnce([this] { m_arm.SetAngle(0_deg); }, {}));
.OnTrue(wpi::cmd::RunOnce([this] { m_arm.SetAngle(45_deg); }, {}))
.OnFalse(wpi::cmd::RunOnce([this] { m_arm.SetAngle(0_deg); }, {}));
wpi::cmd::JoystickButton(&m_controller, 2)
.OnTrue(wpi::cmd::cmd::RunOnce([this] { m_arm.SetAngle(90_deg); }, {}))
.OnFalse(wpi::cmd::cmd::RunOnce([this] { m_arm.SetAngle(0_deg); }, {}));
.OnTrue(wpi::cmd::RunOnce([this] { m_arm.SetAngle(90_deg); }, {}))
.OnFalse(wpi::cmd::RunOnce([this] { m_arm.SetAngle(0_deg); }, {}));
// Setup SmartDashboard options.
m_chooser.SetDefaultOption("Auto Routine Distance", &m_autoDistance);

View File

@@ -36,13 +36,12 @@ class RobotContainer {
// takes a generic type, so the selector does not have to be an enum; it could
// be any desired type (string, integer, boolean, double...)
wpi::cmd::CommandPtr m_exampleSelectCommand =
wpi::cmd::cmd::Select<CommandSelector>(
wpi::cmd::Select<CommandSelector>(
[this] { return m_chooser.GetSelected(); },
// Maps selector values to commands
std::pair{ONE, wpi::cmd::cmd::Print("Command one was selected!")},
std::pair{TWO, wpi::cmd::cmd::Print("Command two was selected!")},
std::pair{THREE,
wpi::cmd::cmd::Print("Command three was selected!")});
std::pair{ONE, wpi::cmd::Print("Command one was selected!")},
std::pair{TWO, wpi::cmd::Print("Command two was selected!")},
std::pair{THREE, wpi::cmd::Print("Command three was selected!")});
void ConfigureButtonBindings();
};

View File

@@ -8,6 +8,6 @@
#include "wpi/commands2/Commands.hpp"
wpi::cmd::CommandPtr autos::ExampleAuto(ExampleSubsystem* subsystem) {
return wpi::cmd::cmd::Sequence(subsystem->ExampleMethodCommand(),
ExampleCommand(subsystem).ToPtr());
return wpi::cmd::Sequence(subsystem->ExampleMethodCommand(),
ExampleCommand(subsystem).ToPtr());
}

View File

@@ -13,5 +13,5 @@ RobotContainer::RobotContainer() {
void RobotContainer::ConfigureBindings() {}
wpi::cmd::CommandPtr RobotContainer::GetAutonomousCommand() {
return wpi::cmd::cmd::Print("No autonomous command configured");
return wpi::cmd::Print("No autonomous command configured");
}