From 8afd1dd14a451a99f6fdf683c88956fca43b5397 Mon Sep 17 00:00:00 2001 From: nkaminski Date: Fri, 24 Feb 2017 17:32:42 -0600 Subject: [PATCH 1/2] add NeedsCompute() function --- PID_v1.cpp => PID_v2.cpp | 9 +++++++++ PID_v1.h => PID_v2.h | 2 ++ library.json | 4 ++-- library.properties | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) rename PID_v1.cpp => PID_v2.cpp (97%) rename PID_v1.h => PID_v2.h (95%) diff --git a/PID_v1.cpp b/PID_v2.cpp similarity index 97% rename from PID_v1.cpp rename to PID_v2.cpp index 86222c7..2cd30c0 100644 --- a/PID_v1.cpp +++ b/PID_v2.cpp @@ -44,6 +44,15 @@ PID::PID(double* Input, double* Output, double* Setpoint, * pid Output needs to be computed. returns true when the output is computed, * false when nothing has been done. **********************************************************************************/ +bool PID::NeedsCompute() +{ + if(!inAuto) return false; + unsigned long now = millis(); + unsigned long timeChange = (now - lastTime); + if(timeChange>=SampleTime) + return true; + return false; +} bool PID::Compute() { if(!inAuto) return false; diff --git a/PID_v1.h b/PID_v2.h similarity index 95% rename from PID_v1.h rename to PID_v2.h index 77b3e4b..b67cc10 100644 --- a/PID_v1.h +++ b/PID_v2.h @@ -20,6 +20,8 @@ class PID void SetMode(int Mode); // * sets PID to either Manual (0) or Auto (non-0) + bool NeedsCompute(); // * Returns true if calling Compute() will actually + // perform a PID computation. bool Compute(); // * performs the PID calculation. it should be // called every time loop() cycles. ON/OFF and // calculation frequency can be set using SetMode diff --git a/library.json b/library.json index cf2510c..c580cc3 100644 --- a/library.json +++ b/library.json @@ -1,9 +1,9 @@ { - "name": "PID", + "name": "PIDV2", "keywords": "PID, controller, signal", "description": "A PID controller seeks to keep some input variable close to a desired setpoint by adjusting an output. The way in which it does this can be 'tuned' by adjusting three parameters (P,I,D).", "url": "http://playground.arduino.cc/Code/PIDLibrary", - "include": "PID_v1", + "include": "PID_v2", "authors": [ { diff --git a/library.properties b/library.properties index 9a316b0..89a4daa 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PID -version=1.1.1 +version=2.0.0 author=Brett Beauregard maintainer=Brett Beauregard sentence=PID controller From c6d1b7382764f638528c857a32cfaeacc8044096 Mon Sep 17 00:00:00 2001 From: nkaminski Date: Fri, 24 Feb 2017 17:37:06 -0600 Subject: [PATCH 2/2] fix headers --- PID_v2.cpp | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PID_v2.cpp b/PID_v2.cpp index 2cd30c0..eb27551 100644 --- a/PID_v2.cpp +++ b/PID_v2.cpp @@ -11,7 +11,7 @@ #include "WProgram.h" #endif -#include +#include /*Constructor (...)********************************************************* * The parameters specified here are those for for which we can't set up diff --git a/library.properties b/library.properties index 89a4daa..5d7bc1f 100644 --- a/library.properties +++ b/library.properties @@ -1,4 +1,4 @@ -name=PID +name=PIDV2 version=2.0.0 author=Brett Beauregard maintainer=Brett Beauregard