mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Clean up PIDCommand (#2010)
PIDCommand uses a function based (callback) model, so functions designed for use in derived classes are of limited utility.
This commit is contained in:
@@ -31,29 +31,9 @@ PIDCommand::PIDCommand(PIDController controller,
|
||||
void PIDCommand::Initialize() { m_controller.Reset(); }
|
||||
|
||||
void PIDCommand::Execute() {
|
||||
UseOutput(m_controller.Calculate(GetMeasurement(), m_setpoint()));
|
||||
m_useOutput(m_controller.Calculate(m_measurement(), m_setpoint()));
|
||||
}
|
||||
|
||||
void PIDCommand::End(bool interrupted) { UseOutput(0); }
|
||||
|
||||
void PIDCommand::SetOutput(std::function<void(double)> useOutput) {
|
||||
m_useOutput = useOutput;
|
||||
}
|
||||
|
||||
void PIDCommand::SetSetpoint(std::function<double()> setpointSource) {
|
||||
m_setpoint = setpointSource;
|
||||
}
|
||||
|
||||
void PIDCommand::SetSetpoint(double setpoint) {
|
||||
m_setpoint = [setpoint] { return setpoint; };
|
||||
}
|
||||
|
||||
void PIDCommand::SetSetpointRelative(double relativeSetpoint) {
|
||||
SetSetpoint(m_setpoint() + relativeSetpoint);
|
||||
}
|
||||
|
||||
double PIDCommand::GetMeasurement() { return m_measurement(); }
|
||||
|
||||
void PIDCommand::UseOutput(double output) { m_useOutput(output); }
|
||||
void PIDCommand::End(bool interrupted) { m_useOutput(0); }
|
||||
|
||||
PIDController& PIDCommand::getController() { return m_controller; }
|
||||
|
||||
@@ -54,18 +54,12 @@ ProfiledPIDCommand::ProfiledPIDCommand(
|
||||
void ProfiledPIDCommand::Initialize() { m_controller.Reset(); }
|
||||
|
||||
void ProfiledPIDCommand::Execute() {
|
||||
UseOutput(m_controller.Calculate(GetMeasurement(), m_goal()),
|
||||
m_controller.GetSetpoint());
|
||||
m_useOutput(m_controller.Calculate(m_measurement(), m_goal()),
|
||||
m_controller.GetSetpoint());
|
||||
}
|
||||
|
||||
void ProfiledPIDCommand::End(bool interrupted) {
|
||||
UseOutput(0, State{0_m, 0_mps});
|
||||
}
|
||||
|
||||
units::meter_t ProfiledPIDCommand::GetMeasurement() { return m_measurement(); }
|
||||
|
||||
void ProfiledPIDCommand::UseOutput(double output, State state) {
|
||||
m_useOutput(output, state);
|
||||
m_useOutput(0, State{0_m, 0_mps});
|
||||
}
|
||||
|
||||
frc::ProfiledPIDController& ProfiledPIDCommand::GetController() {
|
||||
|
||||
Reference in New Issue
Block a user