[commands] Fix PIDSubsystem setSetpoint behavior (#4759)

No longer stores a temporary setpoint in PIDSubsystem, instead
immediately sending to PIDController. This fixes an issue where the
setpoint didn't take effect until the Subsystem Periodic method ran, and
could cause commands to finish early if they were scheduled after the
subsystem periodic method ran because it used the old setpoint.
This commit is contained in:
sciencewhiz
2022-12-03 11:32:46 -08:00
committed by GitHub
parent f24ad1d715
commit 8f402645f5
3 changed files with 7 additions and 12 deletions

View File

@@ -16,16 +16,16 @@ PIDSubsystem::PIDSubsystem(PIDController controller, double initialPosition)
void PIDSubsystem::Periodic() {
if (m_enabled) {
UseOutput(m_controller.Calculate(GetMeasurement(), m_setpoint), m_setpoint);
UseOutput(m_controller.Calculate(GetMeasurement()), GetSetpoint());
}
}
void PIDSubsystem::SetSetpoint(double setpoint) {
m_setpoint = setpoint;
m_controller.SetSetpoint(setpoint);
}
double PIDSubsystem::GetSetpoint() const {
return m_setpoint;
return m_controller.GetSetpoint();
}
void PIDSubsystem::Enable() {