rims-arduino-library
v3.1.1
Recirculation infusion mash system library for Arduino
utility
PID_v1mod.h
Go to the documentation of this file.
1
18
#ifndef PID_v1mod_h
19
#define PID_v1mod_h
20
#define LIBRARY_VERSION 1.0.0
21
22
#define SIGN(x) ((x>0)-(x<0))
23
24
25
class
PIDmod
26
{
27
28
29
public
:
30
31
//Constants used in some of the functions below
32
#define AUTOMATIC 1
33
#define MANUAL 0
34
#define DIRECT 0
35
#define REVERSE 1
36
37
//commonly used functions **************************************************************************
38
PIDmod(
double
*,
double
*,
double
*,
// * constructor. links the PID to the Input, Output, and
39
double
,
double
,
double
,
int
);
// Setpoint. Initial tuning parameters are also set here
40
41
void
SetMode(
int
Mode);
// * sets PID to either Manual (0) or Auto (non-0)
42
43
bool
Compute();
// * performs the PID calculation. it should be
44
// called every time loop() cycles. ON/OFF and
45
// calculation frequency can be set using SetMode
46
// SetSampleTime respectively
47
48
void
SetOutputLimits(
double
,
double
);
//clamps the output to a specific range. 0-255 by default, but
49
//it's likely the user will want to change this depending on
50
//the application
51
52
53
//available but not commonly used functions ********************************************************
54
void
SetTunings(
double
,
double
,
// * While most users will set the tunings once in the
55
double
);
// constructor, this function gives the user the option
56
// of changing tunings during runtime for Adaptive control
57
void
SetDerivativeFilter(
double
);
// * Added by Francis Gagnon. Add a first-order
58
// lowpass filter to derivative part of given time constant [sec].
59
void
SetControllerDirection(
int
);
// * Sets the Direction, or "Action" of the controller. DIRECT
60
// means the output will increase when error is positive. REVERSE
61
// means the opposite. it's very unlikely that this will be needed
62
// once it is set in the constructor.
63
void
SetSampleTime(
int
);
// * sets the frequency, in Milliseconds, with which
64
// the PID calculation is performed. default is 100
65
66
67
68
//Display functions ****************************************************************
69
double
GetKp();
// These functions query the pid for interal values.
70
double
GetKi();
// they were created mainly for the pid front-end,
71
double
GetKd();
// where it's important to know what is actually
72
int
GetMode();
// inside the PID.
73
int
GetDirection();
//
74
75
private
:
76
void
Initialize();
77
78
double
dispKp;
// * we'll hold on to the tuning parameters in user-entered
79
double
dispKi;
// format for display purposes
80
double
dispKd;
//
81
82
double
kp;
// * (P)roportional Tuning Parameter
83
double
ki;
// * (I)ntegral Tuning Parameter
84
double
kd;
// * (D)erivative Tuning Parameter
85
double
filterCst;
// * (1/N) Derivative filter constant (Francis Gagnon)
86
87
int
controllerDirection;
88
89
double
*myInput;
// * Pointers to the Input, Output, and Setpoint variables
90
double
*myOutput;
// This creates a hard link between the variables and the
91
double
*mySetpoint;
// PID, freeing the user from having to constantly tell us
92
// what these values are. with pointers we'll just know.
93
94
boolean
clamp;
// Francis Gagnon
95
96
double
ITerm, lastInput;
97
double
lastFilterOutput;
// Francis Gagnon
98
99
unsigned
long
SampleTime;
100
double
outMin, outMax;
101
bool
inAuto;
102
};
103
#endif
104
Generated on Tue Feb 19 2019 14:39:11 for rims-arduino-library by
1.8.13