Skip to content

Commit 3d958e4

Browse files
committed
Resolves #66
1 parent a686ab0 commit 3d958e4

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/QuickPID.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ void QuickPID::SetMode(Control Mode) {
182182
}
183183
mode = Mode;
184184
}
185+
void QuickPID::SetMode(uint8_t Mode) {
186+
if (mode == Control::manual && Mode != 0) { // just went from manual to automatic or timer
187+
QuickPID::Initialize();
188+
}
189+
mode = (Control)Mode;
190+
}
185191

186192
/* Initialize()****************************************************************
187193
Does all the things that need to happen to ensure a bumpless transfer
@@ -200,6 +206,9 @@ void QuickPID::Initialize() {
200206
void QuickPID::SetControllerDirection(Action Action) {
201207
action = Action;
202208
}
209+
void QuickPID::SetControllerDirection(uint8_t Direction) {
210+
action = (Action)Direction;
211+
}
203212

204213
/* SetProportionalMode(.)*****************************************************
205214
Sets the computation method for the proportional term, to compute based
@@ -208,6 +217,9 @@ void QuickPID::SetControllerDirection(Action Action) {
208217
void QuickPID::SetProportionalMode(pMode pMode) {
209218
pmode = pMode;
210219
}
220+
void QuickPID::SetProportionalMode(uint8_t Pmode) {
221+
pmode = (pMode)Pmode;
222+
}
211223

212224
/* SetDerivativeMode(.)*******************************************************
213225
Sets the computation method for the derivative term, to compute based
@@ -216,6 +228,9 @@ void QuickPID::SetProportionalMode(pMode pMode) {
216228
void QuickPID::SetDerivativeMode(dMode dMode) {
217229
dmode = dMode;
218230
}
231+
void QuickPID::SetDerivativeMode(uint8_t Dmode) {
232+
dmode = (dMode)Dmode;
233+
}
219234

220235
/* SetAntiWindupMode(.)*******************************************************
221236
Sets the integral anti-windup mode to one of iAwClamp, which clamps
@@ -227,6 +242,9 @@ void QuickPID::SetDerivativeMode(dMode dMode) {
227242
void QuickPID::SetAntiWindupMode(iAwMode iAwMode) {
228243
iawmode = iAwMode;
229244
}
245+
void QuickPID::SetAntiWindupMode(uint8_t IawMode) {
246+
iawmode = (iAwMode)IawMode;
247+
}
230248

231249
/* Status Functions************************************************************
232250
These functions query the internal state of the PID.

src/QuickPID.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class QuickPID {
3030

3131
// Sets PID mode to manual (0), automatic (1) or timer (2).
3232
void SetMode(Control Mode);
33+
void SetMode(uint8_t Mode);
3334

3435
// Performs the PID calculation. It should be called every time loop() cycles ON/OFF and calculation frequency
3536
// can be set using SetMode and SetSampleTime respectively.
@@ -50,22 +51,26 @@ class QuickPID {
5051
// Sets the controller direction or action. Direct means the output will increase when the error is positive.
5152
// Reverse means the output will decrease when the error is positive.
5253
void SetControllerDirection(Action Action);
54+
void SetControllerDirection(uint8_t Direction);
5355

5456
// Sets the sample time in microseconds with which each PID calculation is performed. Default is 100000 µs.
5557
void SetSampleTimeUs(uint32_t NewSampleTimeUs);
5658

5759
// Sets the computation method for the proportional term, to compute based either on error (default),
5860
// on measurement, or the average of both.
5961
void SetProportionalMode(pMode pMode);
62+
void SetProportionalMode(uint8_t Pmode);
6063

6164
// Sets the computation method for the derivative term, to compute based either on error or measurement (default).
6265
void SetDerivativeMode(dMode dMode);
66+
void SetDerivativeMode(uint8_t Dmode);
6367

6468
// Sets the integral anti-windup mode to one of iAwClamp, which clamps the output after
6569
// adding integral and proportional (on measurement) terms, or iAwCondition (default), which
6670
// provides some integral correction, prevents deep saturation and reduces overshoot.
6771
// Option iAwOff disables anti-windup altogether.
6872
void SetAntiWindupMode(iAwMode iAwMode);
73+
void SetAntiWindupMode(uint8_t IawMode);
6974

7075
// PID Query functions ****************************************************************************************
7176
float GetKp(); // proportional gain
@@ -81,6 +86,7 @@ class QuickPID {
8186
uint8_t GetAwMode(); // iAwCondition (0, iAwClamp (1), iAwOff (2)
8287

8388
float outputSum; // Internal integral sum
89+
8490
private:
8591

8692
void Initialize();

0 commit comments

Comments
 (0)