From cccbc9af304a2718ab1a322e28d1372861bb14d7 Mon Sep 17 00:00:00 2001 From: tlatorre Date: Mon, 18 Jan 2021 12:27:22 -0600 Subject: [PATCH] update Compute() so it computes on the first call --- PID_v1.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/PID_v1.cpp b/PID_v1.cpp index cb6637c..3c76372 100644 --- a/PID_v1.cpp +++ b/PID_v1.cpp @@ -57,10 +57,12 @@ PID::PID(double* Input, double* Output, double* Setpoint, **********************************************************************************/ bool PID::Compute() { + static bool first = true; + if(!inAuto) return false; unsigned long now = millis(); unsigned long timeChange = (now - lastTime); - if(timeChange>=SampleTime) + if(first || (timeChange>=SampleTime)) { /*Compute all the working error variables*/ double input = *myInput; @@ -89,6 +91,7 @@ bool PID::Compute() /*Remember some variables for next time*/ lastInput = input; lastTime = now; + first = false; return true; } else return false;