Improve various subsystem APIs (#2130)

Improves the APIs for various prebuilt subsystems (PIDSubsystem, TrapezoidProfileSubsystem, ProfiledPIDSubsystem). Addresses #2128, and also changes the rather cumbersome getSetpoint API to a more intuitive setSetpoint one. Updates examples to match.
This commit is contained in:
Oblarg
2019-11-26 00:46:47 -05:00
committed by Peter Johnson
parent ce3973435e
commit 6dcd2b0e2c
19 changed files with 184 additions and 204 deletions

View File

@@ -30,25 +30,11 @@ class PIDSubsystem : public SubsystemBase {
void Periodic() override;
/**
* Uses the output from the PIDController.
* Sets the setpoint for the subsystem.
*
* @param output the output of the PIDController
* @param setpoint the setpoint for the subsystem
*/
virtual void UseOutput(double output) = 0;
/**
* Returns the reference (setpoint) used by the PIDController.
*
* @return the reference (setpoint) to be used by the controller
*/
virtual double GetSetpoint() = 0;
/**
* Returns the measurement of the process variable used by the PIDController.
*
* @return the measurement of the process variable
*/
virtual double GetMeasurement() = 0;
void SetSetpoint(double setpoint);
/**
* Enables the PID control. Resets the controller.
@@ -60,6 +46,13 @@ class PIDSubsystem : public SubsystemBase {
*/
virtual void Disable();
/**
* Returns whether the controller is enabled.
*
* @return Whether the controller is enabled.
*/
bool IsEnabled();
/**
* Returns the PIDController.
*
@@ -70,5 +63,23 @@ class PIDSubsystem : public SubsystemBase {
protected:
PIDController m_controller;
bool m_enabled;
/**
* Returns the measurement of the process variable used by the PIDController.
*
* @return the measurement of the process variable
*/
virtual double GetMeasurement() = 0;
/**
* Uses the output from the PIDController.
*
* @param output the output of the PIDController
* @param setpoint the setpoint of the PIDController (for feedforward)
*/
virtual void UseOutput(double output, double setpoint) = 0;
private:
double m_setpoint{0};
};
} // namespace frc2