From e94601f54feb5c1106ebf9adf6fc8c59316a6de1 Mon Sep 17 00:00:00 2001 From: topquark12 Date: Tue, 29 Dec 2020 17:09:03 +0800 Subject: [PATCH] pid: fix derivative calculation Reviewed-on: https://git.m-labs.hk/M-Labs/thermostat/pulls/40 Co-Authored-By: topquark12 Co-Committed-By: topquark12 --- src/pid.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pid.rs b/src/pid.rs index 176283c..6001c54 100644 --- a/src/pid.rs +++ b/src/pid.rs @@ -85,7 +85,7 @@ impl Controller { None => 0.0, Some(last_input) => - f64::from(self.parameters.kd) * (input - last_input) / time_delta, + f64::from(self.parameters.kd) * (last_input - input) / time_delta, }; self.last_input = Some(input);