From 6cda038e59ad402451875c3c9cdef27dcd491514 Mon Sep 17 00:00:00 2001 From: LaurentDelaon <35500047+LaurentDelaon@users.noreply.github.com> Date: Wed, 31 Jul 2019 10:28:41 +0200 Subject: [PATCH] Update PID_v1.cpp I put the start sample time at is beginning not after the calculus. Taking account the calcul past time and other... --- PID_v1.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PID_v1.cpp b/PID_v1.cpp index cb6637c..4752939 100644 --- a/PID_v1.cpp +++ b/PID_v1.cpp @@ -62,6 +62,8 @@ bool PID::Compute() unsigned long timeChange = (now - lastTime); if(timeChange>=SampleTime) { + // take the start sample time + lastTime = now; /*Compute all the working error variables*/ double input = *myInput; double error = *mySetpoint - input; @@ -88,7 +90,7 @@ bool PID::Compute() /*Remember some variables for next time*/ lastInput = input; - lastTime = now; + return true; } else return false;