11 #include <initializer_list>
13 #include <frc/trajectory/TrapezoidProfile.h>
14 #include <wpi/ArrayRef.h>
16 #include "frc2/Timer.h"
17 #include "frc2/command/CommandBase.h"
18 #include "frc2/command/CommandHelper.h"
27 template <
class Distance>
29 :
public CommandHelper<CommandBase, TrapezoidProfileCommand<Distance>> {
30 using Distance_t = units::unit_t<Distance>;
32 units::compound_unit<Distance, units::inverse<units::seconds>>;
33 using Velocity_t = units::unit_t<Velocity>;
45 std::function<
void(State)> output,
46 std::initializer_list<Subsystem*> requirements)
47 : m_profile(profile), m_output(output) {
59 std::function<
void(State)> output,
61 : m_profile(profile), m_output(output) {
70 void Execute()
override { m_output(m_profile.Calculate(m_timer.
Get())); }
72 void End(
bool interrupted)
override { m_timer.
Stop(); }
75 return m_timer.
HasElapsed(m_profile.TotalTime());
80 std::function<void(State)> m_output;
units::second_t Get() const
Get the current time from the timer.
void Start()
Start the timer running.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
void Execute() override
The main body of a command.
Definition: TrapezoidProfileCommand.h:70
A trapezoid-shaped velocity profile.
Definition: TrapezoidProfile.h:45
void Stop()
Stop the timer.
A wrapper for the frc::Timer class that returns unit-typed values.
Definition: Timer.h:40
void Initialize() override
The initial subroutine of a command.
Definition: TrapezoidProfileCommand.h:65
TrapezoidProfileCommand(frc::TrapezoidProfile< Distance > profile, std::function< void(State)> output, wpi::ArrayRef< Subsystem * > requirements={})
Creates a new TrapezoidProfileCommand that will execute the given TrapezoidalProfile.
Definition: TrapezoidProfileCommand.h:58
void Reset()
Reset the timer by setting the time to 0.
void End(bool interrupted) override
The action to take when the command ends.
Definition: TrapezoidProfileCommand.h:72
A command that runs a TrapezoidProfile.
Definition: TrapezoidProfileCommand.h:28
void AddRequirements(std::initializer_list< Subsystem * > requirements)
Adds the specified requirements to the command.
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:26
bool IsFinished() override
Whether the command has finished.
Definition: TrapezoidProfileCommand.h:74
Definition: TrapezoidProfile.h:68
TrapezoidProfileCommand(frc::TrapezoidProfile< Distance > profile, std::function< void(State)> output, std::initializer_list< Subsystem * > requirements)
Creates a new TrapezoidProfileCommand that will execute the given TrapezoidalProfile.
Definition: TrapezoidProfileCommand.h:44
bool HasElapsed(units::second_t period)
Check if the period specified has passed.