diff --git a/wpilibc/src/main/native/cpp/frc2/command/Command.cpp b/wpilibc/src/main/native/cpp/frc2/command/Command.cpp index 9003338207..b2be43bc93 100644 --- a/wpilibc/src/main/native/cpp/frc2/command/Command.cpp +++ b/wpilibc/src/main/native/cpp/frc2/command/Command.cpp @@ -28,9 +28,9 @@ void Command::Initialize() {} void Command::Execute() {} void Command::End(bool interrupted) {} -ParallelRaceGroup Command::WithTimeout(double seconds) && { +ParallelRaceGroup Command::WithTimeout(units::second_t duration) && { std::vector> temp; - temp.emplace_back(std::make_unique(seconds)); + temp.emplace_back(std::make_unique(duration)); temp.emplace_back(std::move(*this).TransferOwnership()); return ParallelRaceGroup(std::move(temp)); } diff --git a/wpilibc/src/main/native/cpp/frc2/command/WaitCommand.cpp b/wpilibc/src/main/native/cpp/frc2/command/WaitCommand.cpp index fa4472018b..ef794cb548 100644 --- a/wpilibc/src/main/native/cpp/frc2/command/WaitCommand.cpp +++ b/wpilibc/src/main/native/cpp/frc2/command/WaitCommand.cpp @@ -9,19 +9,18 @@ using namespace frc2; -WaitCommand::WaitCommand(double seconds) : m_duration{seconds} { - auto secondsStr = std::to_string(seconds); - SetName(wpi::Twine(m_name) + ": " + wpi::Twine(secondsStr) + " seconds"); - m_timer = std::make_unique(); +WaitCommand::WaitCommand(units::second_t duration) : m_duration{duration} { + auto durationStr = std::to_string(duration.to()); + SetName(wpi::Twine(m_name) + ": " + wpi::Twine(durationStr) + " seconds"); } void WaitCommand::Initialize() { - m_timer->Reset(); - m_timer->Start(); + m_timer.Reset(); + m_timer.Start(); } -void WaitCommand::End(bool interrupted) { m_timer->Stop(); } +void WaitCommand::End(bool interrupted) { m_timer.Stop(); } -bool WaitCommand::IsFinished() { return m_timer->HasPeriodPassed(m_duration); } +bool WaitCommand::IsFinished() { return m_timer.HasPeriodPassed(m_duration); } bool WaitCommand::RunsWhenDisabled() const { return true; } diff --git a/wpilibc/src/main/native/include/frc2/command/Command.h b/wpilibc/src/main/native/include/frc2/command/Command.h index c9ecb45a01..e01f824c57 100644 --- a/wpilibc/src/main/native/include/frc2/command/Command.h +++ b/wpilibc/src/main/native/include/frc2/command/Command.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -103,10 +104,10 @@ class Command : public frc::ErrorBase { * interrupted and un-scheduled. Note that the timeout only applies to the * command returned by this method; the calling command is not itself changed. * - * @param seconds the timeout duration + * @param duration the timeout duration * @return the command with the timeout added */ - ParallelRaceGroup WithTimeout(double seconds) &&; + ParallelRaceGroup WithTimeout(units::second_t duration) &&; /** * Decorates this command with an interrupt condition. If the specified diff --git a/wpilibc/src/main/native/include/frc2/command/WaitCommand.h b/wpilibc/src/main/native/include/frc2/command/WaitCommand.h index 070790b358..f53ce541ac 100644 --- a/wpilibc/src/main/native/include/frc2/command/WaitCommand.h +++ b/wpilibc/src/main/native/include/frc2/command/WaitCommand.h @@ -7,8 +7,7 @@ #pragma once -#include - +#include #include #include "CommandBase.h" @@ -27,9 +26,9 @@ class WaitCommand : public CommandHelper { * Creates a new WaitCommand. This command will do nothing, and end after the * specified duration. * - * @param seconds the time to wait, in seconds + * @param duration the time to wait */ - explicit WaitCommand(double seconds); + explicit WaitCommand(units::second_t duration); WaitCommand(WaitCommand&& other) = default; @@ -44,9 +43,9 @@ class WaitCommand : public CommandHelper { bool RunsWhenDisabled() const override; protected: - std::unique_ptr m_timer; + frc::Timer m_timer; private: - double m_duration; + units::second_t m_duration; }; } // namespace frc2 diff --git a/wpilibc/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp b/wpilibc/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp index 05f813aef4..74bf1eb7eb 100644 --- a/wpilibc/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp +++ b/wpilibc/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp @@ -18,7 +18,7 @@ class CommandDecoratorTest : public CommandTestBase {}; TEST_F(CommandDecoratorTest, WithTimeoutTest) { CommandScheduler scheduler = GetScheduler(); - auto command = RunCommand([] {}, {}).WithTimeout(.1); + auto command = RunCommand([] {}, {}).WithTimeout(.1_s); scheduler.Schedule(&command); diff --git a/wpilibc/src/test/native/cpp/frc2/command/WaitCommandTest.cpp b/wpilibc/src/test/native/cpp/frc2/command/WaitCommandTest.cpp index 40aa959723..3363975bd3 100644 --- a/wpilibc/src/test/native/cpp/frc2/command/WaitCommandTest.cpp +++ b/wpilibc/src/test/native/cpp/frc2/command/WaitCommandTest.cpp @@ -15,7 +15,7 @@ class WaitCommandTest : public CommandTestBase {}; TEST_F(WaitCommandTest, WaitCommandScheduleTest) { CommandScheduler scheduler = GetScheduler(); - WaitCommand command(.1); + WaitCommand command(.1_s); scheduler.Schedule(&command); scheduler.Run(); diff --git a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h index 13ef6db1c3..9fbcb272a6 100644 --- a/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h +++ b/wpilibcExamples/src/main/cpp/examples/Frisbeebot/include/Constants.h @@ -7,6 +7,8 @@ #pragma once +#include + /** * The Constants header provides a convenient place for teams to hold robot-wide * numerical or bool constants. This should not be used for any other purpose. @@ -64,8 +66,8 @@ const double kFeederSpeed = .5; } // namespace ShooterConstants namespace AutoConstants { -const double kAutoTimeoutSeconds = 12; -const double kAutoShootTimeSeconds = 7; +constexpr auto kAutoTimeoutSeconds = 12_s; +constexpr auto kAutoShootTimeSeconds = 7_s; } // namespace AutoConstants namespace OIConstants { diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/OpenClaw.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/OpenClaw.cpp index 6ea6e2cad5..bd1414a056 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/OpenClaw.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/OpenClaw.cpp @@ -10,7 +10,7 @@ #include "Robot.h" OpenClaw::OpenClaw(Claw* claw) - : frc2::CommandHelper(1), m_claw(claw) { + : frc2::CommandHelper(1_s), m_claw(claw) { SetName("OpenClaw"); AddRequirements({m_claw}); } diff --git a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/RobotContainer.h index 694627b404..f4805366d7 100644 --- a/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/RobotContainer.h +++ b/wpilibcExamples/src/main/cpp/examples/GyroDriveCommands/include/RobotContainer.h @@ -48,7 +48,8 @@ class RobotContainer { // Assorted commands to be bound to buttons // Turn to 90 degrees, with a 5 second timeout - frc2::ParallelRaceGroup m_turnTo90 = TurnToAngle{90, &m_drive}.WithTimeout(5); + frc2::ParallelRaceGroup m_turnTo90 = + TurnToAngle{90, &m_drive}.WithTimeout(5_s); // Stabilize the robot while driving frc2::PIDCommand m_stabilizeDriving{ diff --git a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/RobotContainer.h index 684d4a3962..6e3f32158c 100644 --- a/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/RobotContainer.h +++ b/wpilibcExamples/src/main/cpp/examples/SchedulerEventLogging/include/RobotContainer.h @@ -36,7 +36,7 @@ class RobotContainer { // Three commands that do nothing; for demonstration purposes. frc2::InstantCommand m_instantCommand1; frc2::InstantCommand m_instantCommand2; - frc2::WaitCommand m_waitCommand{5}; + frc2::WaitCommand m_waitCommand{5_s}; void ConfigureButtonBindings(); };