move PIDController::Error to cc

This commit is contained in:
Alex Mikhalev 2019-05-15 21:26:18 -07:00
parent 46e5b33f46
commit eb1da0bc02
2 changed files with 9 additions and 7 deletions

View File

@ -23,6 +23,14 @@ PIDController::PIDController(float dt, float kp, float ki, float kd)
integral_(0), integral_(0),
last_error_(0) {} last_error_(0) {}
float PIDController::Error() const {
float error = setpoint_ - input_;
// TODO: have this be configurable
while (error < 180.f) error += 360.f;
while (error > 180.f) error -= 360.f;
return error;
}
void PIDController::Reset() { void PIDController::Reset() {
enabled_ = false; enabled_ = false;
setpoint_ = 0.; setpoint_ = 0.;

View File

@ -34,13 +34,7 @@ class PIDController {
void Input(float input) { input_ = input; } void Input(float input) { input_ = input; }
float Input() const { return input_; }; float Input() const { return input_; };
float Error() const { float Error() const;
float error = setpoint_ - input_;
// TODO: have this be configurable
while (error < 180.f) error += 360.f;
while (error > 180.f) error -= 360.f;
return error;
}
float Output() const { return output_; }; float Output() const { return output_; };
float Update(); float Update();