10 #include <frc/trajectory/TrapezoidProfile.h>
11 #include <units/units.h>
13 #include "frc2/command/SubsystemBase.h"
21 template <
class Distance>
23 using Distance_t = units::unit_t<Distance>;
25 units::compound_unit<Distance, units::inverse<units::seconds>>;
26 using Velocity_t = units::unit_t<Velocity>;
41 Distance_t initialPosition = Distance_t{0},
42 units::second_t period = 20_ms)
43 : m_constraints(constraints),
44 m_state{initialPosition, Velocity_t(0)},
45 m_goal{initialPosition, Velocity_t{0}},
51 m_state = profile.Calculate(m_period);
62 void SetGoal(State goal) { m_goal = goal; }
69 void SetGoal(Distance_t goal) { m_goal = State{goal, Velocity_t(0)}; }
78 virtual void UseState(State state) = 0;
91 Constraints m_constraints;
94 units::second_t m_period;
95 bool m_enabled{
false};
A subsystem that generates and runs trapezoidal motion profiles automatically.
Definition: TrapezoidProfileSubsystem.h:22
virtual void UseState(State state)=0
Users should override this to consume the current state of the motion profile.
void SetGoal(State goal)
Sets the goal state for the subsystem.
Definition: TrapezoidProfileSubsystem.h:62
A trapezoid-shaped velocity profile.
Definition: TrapezoidProfile.h:45
void SetGoal(Distance_t goal)
Sets the goal state for the subsystem.
Definition: TrapezoidProfileSubsystem.h:69
void Disable()
Disable the TrapezoidProfileSubsystem's output.
Definition: TrapezoidProfileSubsystem.h:88
void Enable()
Enable the TrapezoidProfileSubsystem's output.
Definition: TrapezoidProfileSubsystem.h:83
Definition: TrapezoidProfile.h:55
Definition: TrapezoidProfile.h:68
A base for subsystems that handles registration in the constructor, and provides a more intuitive met...
Definition: SubsystemBase.h:22
TrapezoidProfileSubsystem(Constraints constraints, Distance_t initialPosition=Distance_t{0}, units::second_t period=20_ms)
Creates a new TrapezoidProfileSubsystem.
Definition: TrapezoidProfileSubsystem.h:40
void Periodic() override
This method is called periodically by the CommandScheduler.
Definition: TrapezoidProfileSubsystem.h:48