10 #include <frc/controller/ProfiledPIDController.h>
11 #include <units/units.h>
13 #include "frc2/command/SubsystemBase.h"
22 template <
class Distance>
24 using Distance_t = units::unit_t<Distance>;
26 units::compound_unit<Distance, units::inverse<units::seconds>>;
27 using Velocity_t = units::unit_t<Velocity>;
38 Distance_t initialPosition = Distance_t{0})
39 : m_controller{controller} {
46 m_controller.GetSetpoint());
55 void SetGoal(State goal) { m_goal = goal; }
62 void SetGoal(Distance_t goal) { m_goal = State{goal, Velocity_t(0)}; }
76 UseOutput(0, State{Distance_t(0), Velocity_t(0)});
96 bool m_enabled{
false};
113 virtual void UseOutput(
double output, State setpoint) = 0;
virtual void Disable()
Disables the PID control.
Definition: ProfiledPIDSubsystem.h:75
A subsystem that uses a ProfiledPIDController to control an output.
Definition: ProfiledPIDSubsystem.h:23
void Periodic() override
This method is called periodically by the CommandScheduler.
Definition: ProfiledPIDSubsystem.h:43
virtual Distance_t GetMeasurement()=0
Returns the measurement of the process variable used by the ProfiledPIDController.
ProfiledPIDSubsystem(frc::ProfiledPIDController< Distance > controller, Distance_t initialPosition=Distance_t{0})
Creates a new ProfiledPIDSubsystem.
Definition: ProfiledPIDSubsystem.h:37
virtual void Enable()
Enables the PID control.
Definition: ProfiledPIDSubsystem.h:67
virtual void UseOutput(double output, State setpoint)=0
Uses the output from the ProfiledPIDController.
Implements a PID control loop whose setpoint is constrained by a trapezoid profile.
Definition: ProfiledPIDController.h:33
bool IsEnabled()
Returns whether the controller is enabled.
Definition: ProfiledPIDSubsystem.h:85
void SetGoal(Distance_t goal)
Sets the goal state for the subsystem.
Definition: ProfiledPIDSubsystem.h:62
Definition: TrapezoidProfile.h:68
frc::ProfiledPIDController< Distance > & GetController()
Returns the ProfiledPIDController.
Definition: ProfiledPIDSubsystem.h:92
A base for subsystems that handles registration in the constructor, and provides a more intuitive met...
Definition: SubsystemBase.h:22
void SetGoal(State goal)
Sets the goal state for the subsystem.
Definition: ProfiledPIDSubsystem.h:55