From 9ca257d614236cdc8d3c9e71e469a1bbf01c94b7 Mon Sep 17 00:00:00 2001 From: Starlight220 <53231611+Starlight220@users.noreply.github.com> Date: Sun, 24 Dec 2023 14:18:01 +0200 Subject: [PATCH] remove use of ToPtr --- .../native/cpp/frc2/command/CommandPtr.cpp | 2 +- .../main/native/cpp/frc2/command/Commands.cpp | 32 +++++++++---------- .../include/frc2/command/CommandScheduler.h | 21 ------------ .../native/include/frc2/command/Commands.h | 2 +- .../native/include/frc2/command/Subsystem.h | 15 --------- .../include/frc2/command/WrapperCommand.h | 4 +-- .../cpp/frc2/command/DeferredCommandTest.cpp | 3 +- .../cpp/RobotContainer.cpp | 2 -- .../examples/GearsBot/cpp/RobotContainer.cpp | 17 +++++----- .../GyroDriveCommands/cpp/RobotContainer.cpp | 2 +- .../HatchbotInlined/cpp/commands/Autos.cpp | 6 ++-- .../cpp/RobotContainer.cpp | 6 ++-- .../cpp/RobotContainer.cpp | 10 ++---- .../cpp/RobotContainer.cpp | 7 ++-- .../commandbased/cpp/RobotContainer.cpp | 2 +- .../commandbased/cpp/commands/Autos.cpp | 2 +- 16 files changed, 43 insertions(+), 90 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 6fa86d30031..342a7f271d6 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -235,7 +235,7 @@ CommandPtr CommandPtr::WithName(std::string_view name) && { AssertValid(); WrapperCommand wrapper{std::move(m_ptr)}; wrapper.SetName(name); - return std::move(wrapper).ToPtr(); + return std::move(wrapper); } Command* CommandPtr::get() const& { diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp index 31a4b1fe1c3..9d460a58d06 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp @@ -23,7 +23,7 @@ using namespace frc2; // Factories CommandPtr cmd::None() { - return InstantCommand().ToPtr(); + return InstantCommand(); } CommandPtr cmd::Idle(Requirements requirements) { @@ -32,11 +32,11 @@ CommandPtr cmd::Idle(Requirements requirements) { CommandPtr cmd::RunOnce(std::function action, Requirements requirements) { - return InstantCommand(std::move(action), requirements).ToPtr(); + return InstantCommand(std::move(action), requirements); } CommandPtr cmd::Run(std::function action, Requirements requirements) { - return RunCommand(std::move(action), requirements).ToPtr(); + return RunCommand(std::move(action), requirements); } CommandPtr cmd::StartEnd(std::function start, std::function end, @@ -45,7 +45,7 @@ CommandPtr cmd::StartEnd(std::function start, std::function end, std::move(start), [] {}, [end = std::move(end)](bool interrupted) { end(); }, [] { return false; }, requirements) - .ToPtr(); + ; } CommandPtr cmd::RunEnd(std::function run, std::function end, @@ -53,44 +53,44 @@ CommandPtr cmd::RunEnd(std::function run, std::function end, return FunctionalCommand([] {}, std::move(run), [end = std::move(end)](bool interrupted) { end(); }, [] { return false; }, requirements) - .ToPtr(); + ; } CommandPtr cmd::Print(std::string_view msg) { - return PrintCommand(msg).ToPtr(); + return PrintCommand(msg); } CommandPtr cmd::DeferredProxy(wpi::unique_function supplier) { - return ProxyCommand(std::move(supplier)).ToPtr(); + return ProxyCommand(std::move(supplier)); } CommandPtr cmd::DeferredProxy(wpi::unique_function supplier) { - return ProxyCommand(std::move(supplier)).ToPtr(); + return ProxyCommand(std::move(supplier)); } CommandPtr cmd::Wait(units::second_t duration) { - return WaitCommand(duration).ToPtr(); + return WaitCommand(duration); } CommandPtr cmd::WaitUntil(std::function condition) { - return WaitUntilCommand(condition).ToPtr(); + return WaitUntilCommand(condition); } CommandPtr cmd::Either(CommandPtr&& onTrue, CommandPtr&& onFalse, std::function selector) { return ConditionalCommand(std::move(onTrue).Unwrap(), std::move(onFalse).Unwrap(), std::move(selector)) - .ToPtr(); + ; } CommandPtr cmd::Defer(wpi::unique_function supplier, Requirements requirements) { - return DeferredCommand(std::move(supplier), requirements).ToPtr(); + return DeferredCommand(std::move(supplier), requirements); } CommandPtr cmd::Sequence(std::vector&& commands) { return SequentialCommandGroup(CommandPtr::UnwrapVector(std::move(commands))) - .ToPtr(); + ; } CommandPtr cmd::RepeatingSequence(std::vector&& commands) { @@ -99,17 +99,17 @@ CommandPtr cmd::RepeatingSequence(std::vector&& commands) { CommandPtr cmd::Parallel(std::vector&& commands) { return ParallelCommandGroup(CommandPtr::UnwrapVector(std::move(commands))) - .ToPtr(); + ; } CommandPtr cmd::Race(std::vector&& commands) { return ParallelRaceGroup(CommandPtr::UnwrapVector(std::move(commands))) - .ToPtr(); + ; } CommandPtr cmd::Deadline(CommandPtr&& deadline, std::vector&& others) { return ParallelDeadlineGroup(std::move(deadline).Unwrap(), CommandPtr::UnwrapVector(std::move(others))) - .ToPtr(); + ; } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h b/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h index 1f8d74297ad..f85c71264e8 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/CommandScheduler.h @@ -169,27 +169,6 @@ class CommandScheduler final : public wpi::Sendable, */ void UnregisterAllSubsystems(); - /** - * Sets the default command for a subsystem. Registers that subsystem if it - * is not already registered. Default commands will run whenever there is no - * other command currently scheduled that requires the subsystem. Default - * commands should be written to never end (i.e. their IsFinished() method - * should return false), as they would simply be re-scheduled if they do. - * Default commands must also require their subsystem. - * - * @param subsystem the subsystem whose default command will be set - * @param defaultCommand the default command to associate with the subsystem - */ - template T> - void SetDefaultCommand(Subsystem* subsystem, T&& defaultCommand) { - if (!defaultCommand.HasRequirement(subsystem)) { - throw FRC_MakeError(frc::err::CommandIllegalUse, - "Default commands must require their subsystem!"); - } - SetDefaultCommandImpl(subsystem, std::make_unique>( - std::forward(defaultCommand))); - } - /** * Sets the default command for a subsystem. Registers that subsystem if it * is not already registered. Default commands will run whenever there is no diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h index 5c1d49a2570..4dbe285fe2a 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h @@ -139,7 +139,7 @@ CommandPtr Select(std::function selector, ((void)vec.emplace_back(commands.first, std::move(commands.second).Unwrap()), ...); - return SelectCommand(std::move(selector), std::move(vec)).ToPtr(); + return SelectCommand(std::move(selector), std::move(vec)); } /** diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h b/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h index b95b837c5f2..a78dba8dc52 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Subsystem.h @@ -67,21 +67,6 @@ class Subsystem { */ virtual std::string GetName() const; - /** - * Sets the default Command of the subsystem. The default command will be - * automatically scheduled when no other commands are scheduled that require - * the subsystem. Default commands should generally not end on their own, i.e. - * their IsFinished() method should always return false. Will automatically - * register this subsystem with the CommandScheduler. - * - * @param defaultCommand the default command to associate with this subsystem - */ - template T> - void SetDefaultCommand(T&& defaultCommand) { - CommandScheduler::GetInstance().SetDefaultCommand( - this, std::forward(defaultCommand)); - } - /** * Sets the default Command of the subsystem. The default command will be * automatically scheduled when no other commands are scheduled that require diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/WrapperCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/WrapperCommand.h index 98e8b200820..d843d9a8b5b 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/WrapperCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/WrapperCommand.h @@ -40,9 +40,7 @@ class WrapperCommand : public CommandHelper { * @param command the command being wrapped. Trying to directly schedule this * command or add it to a group will throw an exception. */ - template T> - // NOLINTNEXTLINE(bugprone-forwarding-reference-overload) - explicit WrapperCommand(T&& command) + explicit WrapperCommand(CommandPtr&& command) : WrapperCommand( std::make_unique>(std::forward(command))) {} diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/DeferredCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/DeferredCommandTest.cpp index 1af8ae4e50a..9c470227634 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/DeferredCommandTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/DeferredCommandTest.cpp @@ -29,8 +29,7 @@ TEST_P(DeferredFunctionsTest, DeferredFunctions) { [&] { isFinishedCount++; return finished; - }} - .ToPtr(); + }}; }, {}}; diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp index 37ae1aac11a..cc31eacf772 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp @@ -55,8 +55,6 @@ void RobotContainer::ConfigureButtonBindings() { [] { return frc::TrapezoidProfile::State{}; }, // Require the drive {&m_drive}) - // Convert to CommandPtr - .ToPtr() .BeforeStarting( frc2::cmd::RunOnce([this]() { m_drive.ResetEncoders(); }, {})) .WithTimeout(10_s)); diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp index c08faee741f..4b8f2c76d76 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp @@ -33,19 +33,18 @@ RobotContainer::RobotContainer() void RobotContainer::ConfigureButtonBindings() { // Configure your button bindings here frc2::JoystickButton(&m_joy, 5).OnTrue( - SetElevatorSetpoint(0.25, m_elevator).ToPtr()); - frc2::JoystickButton(&m_joy, 6).OnTrue(CloseClaw(m_claw).ToPtr()); + SetElevatorSetpoint(0.25, m_elevator)); + frc2::JoystickButton(&m_joy, 6).OnTrue(CloseClaw(m_claw)); frc2::JoystickButton(&m_joy, 7).OnTrue( - SetElevatorSetpoint(0.0, m_elevator).ToPtr()); - frc2::JoystickButton(&m_joy, 8).OnTrue(OpenClaw(m_claw).ToPtr()); + SetElevatorSetpoint(0.0, m_elevator)); + frc2::JoystickButton(&m_joy, 8).OnTrue(OpenClaw(m_claw)); frc2::JoystickButton(&m_joy, 9).OnTrue( - Autonomous(m_claw, m_wrist, m_elevator, m_drivetrain).ToPtr()); + Autonomous(m_claw, m_wrist, m_elevator, m_drivetrain)); frc2::JoystickButton(&m_joy, 10) - .OnTrue(Pickup(m_claw, m_wrist, m_elevator).ToPtr()); - frc2::JoystickButton(&m_joy, 11) - .OnTrue(Place(m_claw, m_wrist, m_elevator).ToPtr()); + .OnTrue(Pickup(m_claw, m_wrist, m_elevator)); + frc2::JoystickButton(&m_joy, 11).OnTrue(Place(m_claw, m_wrist, m_elevator)); frc2::JoystickButton(&m_joy, 12) - .OnTrue(PrepareToPickup(m_claw, m_wrist, m_elevator).ToPtr()); + .OnTrue(PrepareToPickup(m_claw, m_wrist, m_elevator)); } frc2::Command* RobotContainer::GetAutonomousCommand() { diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp index 7b076840b9b..75d37d18d4e 100644 --- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/cpp/RobotContainer.cpp @@ -47,7 +47,7 @@ void RobotContainer::ConfigureButtonBindings() { }, // Require the robot drive {&m_drive}) - .ToPtr()); + ); // Turn to 90 degrees when the 'Cross' button is pressed frc2::JoystickButton(&m_driverController, frc::PS4Controller::Button::kCross) diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/Autos.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/Autos.cpp index 73e60edb265..2fd5cfb54c9 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/Autos.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/commands/Autos.cpp @@ -27,7 +27,7 @@ frc2::CommandPtr autos::SimpleAuto(DriveSubsystem* drive) { }, // Requires the drive subsystem {drive}) - .ToPtr(); + ; } frc2::CommandPtr autos::ComplexAuto(DriveSubsystem* drive, @@ -49,7 +49,7 @@ frc2::CommandPtr autos::ComplexAuto(DriveSubsystem* drive, }, // Requires the drive subsystem {drive}) - .ToPtr(), + , // Release the hatch hatch->ReleaseHatchCommand(), // Drive backward the specified distance @@ -69,5 +69,5 @@ frc2::CommandPtr autos::ComplexAuto(DriveSubsystem* drive, }, // Requires the drive subsystem {drive}) - .ToPtr()); + ); } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp index faf9d1f02e8..2643223b311 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp @@ -68,14 +68,14 @@ void RobotContainer::ConfigureButtonBindings() { // Grab the hatch when the 'A' button is pressed. frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kA) - .OnTrue(GrabHatch(&m_hatch).ToPtr()); + .OnTrue(GrabHatch(&m_hatch)); // Release the hatch when the 'B' button is pressed. frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kB) - .OnTrue(ReleaseHatch(&m_hatch).ToPtr()); + .OnTrue(ReleaseHatch(&m_hatch)); // While holding the shoulder button, drive at half speed frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kRightBumper) - .WhileTrue(HalveDriveSpeed(&m_drive).ToPtr()); + .WhileTrue(HalveDriveSpeed(&m_drive)); } frc2::Command* RobotContainer::GetAutonomousCommand() { diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp index 856ec999119..8f547239efe 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp @@ -103,9 +103,7 @@ frc2::CommandPtr RobotContainer::GetAutonomousCommand() { m_drive.SetMotorControllersVolts(frontLeft, rearLeft, frontRight, rearRight); }, - - {&m_drive}) - .ToPtr(); + {&m_drive}); // Reset odometry to the initial pose of the trajectory, run path following // command, then stop at the end. @@ -114,9 +112,7 @@ frc2::CommandPtr RobotContainer::GetAutonomousCommand() { [this, &exampleTrajectory]() { m_drive.ResetOdometry(exampleTrajectory.InitialPose()); }, - {}) - .ToPtr(), + {}), std::move(mecanumControllerCommand), - frc2::InstantCommand([this]() { m_drive.Drive(0, 0, 0, false); }, {}) - .ToPtr()); + frc2::InstantCommand([this]() { m_drive.Drive(0, 0, 0, false); }, {})); } diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp index 2ca4b718933..fc1d6c378b2 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp @@ -87,7 +87,7 @@ frc2::CommandPtr RobotContainer::GetAutonomousCommand() { [this](auto moduleStates) { m_drive.SetModuleStates(moduleStates); }, {&m_drive}) - .ToPtr(); + ; // Reset odometry to the initial pose of the trajectory, run path following // command, then stop at the end. @@ -96,10 +96,9 @@ frc2::CommandPtr RobotContainer::GetAutonomousCommand() { [this, &exampleTrajectory]() { m_drive.ResetOdometry(exampleTrajectory.InitialPose()); }, - {}) - .ToPtr(), + {}), std::move(swerveControllerCommand), frc2::InstantCommand( [this] { m_drive.Drive(0_mps, 0_mps, 0_rad_per_s, false); }, {}) - .ToPtr()); + ); } diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp index 43005010e24..8c71c6a97cc 100644 --- a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/RobotContainer.cpp @@ -22,7 +22,7 @@ void RobotContainer::ConfigureBindings() { // Schedule `ExampleCommand` when `exampleCondition` changes to `true` frc2::Trigger([this] { return m_subsystem.ExampleCondition(); - }).OnTrue(ExampleCommand(&m_subsystem).ToPtr()); + }).OnTrue(ExampleCommand(&m_subsystem)); // Schedule `ExampleMethodCommand` when the Xbox controller's B button is // pressed, cancelling on release. diff --git a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/Autos.cpp b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/Autos.cpp index 3eb09587931..6067c7868d4 100644 --- a/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/Autos.cpp +++ b/wpilibcExamples/src/main/cpp/templates/commandbased/cpp/commands/Autos.cpp @@ -10,5 +10,5 @@ frc2::CommandPtr autos::ExampleAuto(ExampleSubsystem* subsystem) { return frc2::cmd::Sequence(subsystem->ExampleMethodCommand(), - ExampleCommand(subsystem).ToPtr()); + ExampleCommand(subsystem)); }