forked from M-Labs/thermostat
Integral rescaling
This commit is contained in:
parent
cc0126636c
commit
5c84b7438b
@ -333,7 +333,7 @@ fn main() -> ! {
|
||||
KP =>
|
||||
pid.parameters.kp = value as f32,
|
||||
KI =>
|
||||
pid.parameters.ki = value as f32,
|
||||
pid.update_ki(value as f32),
|
||||
KD =>
|
||||
pid.parameters.kd = value as f32,
|
||||
OutputMin =>
|
||||
|
10
src/pid.rs
10
src/pid.rs
@ -109,6 +109,16 @@ impl Controller {
|
||||
integral: self.integral,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_ki(&mut self, new_ki: f32) {
|
||||
if new_ki == 0.0 {
|
||||
self.integral = 0.0;
|
||||
} else {
|
||||
// Rescale integral with changes to kI, aka "Bumpless operation"
|
||||
self.integral = f64::from(self.parameters.ki) * self.integral / f64::from(new_ki);
|
||||
}
|
||||
self.parameters.ki = new_ki;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
|
Loading…
Reference in New Issue
Block a user