mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
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:
@@ -14,18 +14,22 @@ PIDSubsystem::PIDSubsystem(PIDController controller)
|
||||
|
||||
void PIDSubsystem::Periodic() {
|
||||
if (m_enabled) {
|
||||
UseOutput(m_controller.Calculate(GetMeasurement(), GetSetpoint()));
|
||||
UseOutput(m_controller.Calculate(GetMeasurement(), m_setpoint), m_setpoint);
|
||||
}
|
||||
}
|
||||
|
||||
void PIDSubsystem::SetSetpoint(double setpoint) { m_setpoint = setpoint; }
|
||||
|
||||
void PIDSubsystem::Enable() {
|
||||
m_controller.Reset();
|
||||
m_enabled = true;
|
||||
}
|
||||
|
||||
void PIDSubsystem::Disable() {
|
||||
UseOutput(0);
|
||||
UseOutput(0, 0);
|
||||
m_enabled = false;
|
||||
}
|
||||
|
||||
bool PIDSubsystem::IsEnabled() { return m_enabled; }
|
||||
|
||||
PIDController& PIDSubsystem::GetController() { return m_controller; }
|
||||
|
||||
Reference in New Issue
Block a user