8000 fixed issue #3 and issue #4 · rtorresca/Arduino-PID-Library@d4ce705 · GitHub
[go: up one dir, main page]

Skip to content

Commit d4ce705

Browse files
committed
fixed issue br3ttb#3 and issue br3ttb#4
-Changed Compute() to a bool from a void, allowing the calling function to know when the pid calculation has just been evaluated -cleaned up the initialization code in the constructor
1 parent 169cdd0 commit d4ce705

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

PID_v1/PID_v1.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
PID::PID(double* Input, double* Output, double* Setpoint,
2121
double Kp, double Ki, double Kd, int ControllerDirection)
2222
{
23+
24+
myOutput = Output;
25+
myInput = Input;
26+
mySetpoint = Setpoint;
27+
inAuto = false;
28+
2329
PID::SetOutputLimits(0, 255); //default output limit corresponds to
2430
//the arduino pwm limits
2531

@@ -29,22 +35,18 @@ PID::PID(double* Input, double* Output, double* Setpoint,
2935
PID::SetTunings(Kp, Ki, Kd);
3036

3137
lastTime = millis()-SampleTime;
32-
inAuto = false;
33-
myOutput = Output;
34-
myInput = Input;
35-
mySetpoint = Setpoint;
36-
3738
}
3839

3940

4041
/* Compute() **********************************************************************
4142
* This, as they say, is where the magic happens. this function should be called
4243
* every time "void loop()" executes. the function will decide for itself whether a new
43-
* pid Output needs to be computed
44+
* pid Output needs to be computed. returns true when the output is computed,
45+
* false when nothing has been done.
4446
**********************************************************************************/
45-
void PID::Compute()
47+
bool PID::Compute()
4648
{
47-
if(!inAuto) return;
49+
if(!inAuto) return false;
4850
unsigned long now = millis();
4951
unsigned long timeChange = (now - lastTime);
5052
if(timeChange>=SampleTime)
@@ -67,7 +69,9 @@ void PID::Compute()
6769
/*Remember some variables for next time*/
6870
lastInput = input;
6971
lastTime = now;
72+
return true;
7073
}
74+
else return false;
7175
}
7276

7377

PID_v1/PID_v1.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PID
2020

2121
void SetMode(int Mode); // * sets PID to either Manual (0) or Auto (non-0)
2222

23-
void Compute(); // * performs the PID calculation. it should be
23+
bool Compute(); // * performs the PID calculation. it should be
2424
// called every time loop() cycles. ON/OFF and
2525
// calculation frequency can be set using SetMode
2626
// SetSampleTime respectively

README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
***************************************************************
2-
* Arduino PID Library - Version 1.0.1
2+
* Arduino PID Library - Version 1.1.0
33

44
* by Brett Beauregard <br3ttb@gmail.com> brettbeauregard.com
55

0 commit comments

Comments
 (0)
0