From 83a266852a9ea037275bf5011972e04256c1cc3b Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 11 Oct 2020 01:56:22 +0200 Subject: [PATCH] pid: move ki coefficient inside integration --- src/pid.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pid.rs b/src/pid.rs index 543e6e7..f25acb9 100644 --- a/src/pid.rs +++ b/src/pid.rs @@ -52,20 +52,20 @@ impl Controller { // partial let p = f64::from(self.parameters.kp) * error; - //integral - self.integral += error; + // integral + self.integral += f64::from(self.parameters.ki) * error; if self.integral < self.parameters.integral_min.into() { self.integral = self.parameters.integral_min.into(); } if self.integral > self.parameters.integral_max.into() { self.integral = self.parameters.integral_max.into(); } - let i = f64::from(self.parameters.ki) * f64::from(self.integral); + let i = self.integral; // derivative let d = match self.last_input { None => 0.0, - Some(last_input) => f64::from(self.parameters.kd) * (last_input - input) + Some(last_input) => f64::from(self.parameters.kd) * (last_input - input), }; self.last_input = Some(input);