From bd1a5902a1a5a764e21b56ba007dfe75463f2472 Mon Sep 17 00:00:00 2001 From: Philip Salmony <34550389+pms67@users.noreply.github.com> Date: Wed, 27 May 2020 20:49:12 +0200 Subject: [PATCH] Added minus sign to derivative-on-measurement expression. Note on 'derivative-on-measurement': Since the 'error signal' effectively going into the differentiator does not depend on the setpoint: e[n] = 0 - measurement, and therefore (e[n] - e[n - 1]) = (0 - measurement) - (0 - prevMeasurement) = -Kd * (measurement - prevMeasurement). (Note the minus sign compared to derivative-on-error!) --- PID.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PID.h b/PID.h index 4ecfe64..bf6b885 100644 --- a/PID.h +++ b/PID.h @@ -6,7 +6,7 @@ typedef struct { /* Controller gains */ float Kp; float Ki; - float Kd; /* Note: since using derivative-on-measurement, Kd needs to be negative (in contrast to conventional 'derivative-on'error') */ + float Kd; /* Derivative low-pass filter time constant */ float tau;