Sat, 27 Oct 2018 18:53:53 +0200
Annotatie einde infusie
0 | 1 | /** |
2 | * @file | |
3 | * @brief Interface definitions for the PID controller. | |
4 | * | |
5 | * Loger description | |
6 | */ | |
7 | ||
8 | #ifndef _PID_V1_H | |
9 | #define _PID_V1_H | |
10 | ||
11 | /** | |
12 | * @brief PID mode codes. | |
13 | */ | |
14 | typedef enum | |
15 | { | |
16 | PID_MANUAL = 0, ///< PID mode manual. | |
17 | PID_AUTOMATIC = 1, ///< PID mode is automatic. | |
18 | } PID_MODE; | |
19 | ||
20 | /** | |
21 | * @brief PID direction codes. | |
22 | */ | |
23 | typedef enum | |
24 | { | |
25 | PID_DIRECT = 0, ///< PID direction normal. | |
26 | PID_REVERSE = 1, ///< PID direction reverse. | |
27 | } PID_DIRECTION; | |
28 | ||
29 | /** | |
30 | * @brief PID calculation mode. | |
31 | */ | |
32 | typedef enum | |
33 | { | |
34 | PID_P_ON_M = 0, ///< PID on Measurement. | |
35 | PID_P_ON_E = 1, ///< PID on Errors. | |
36 | } PID_PON; | |
37 | ||
38 | ||
39 | ||
40 | /** | |
41 | * @brief Setup the PID controller and initialize. | |
42 | * @param[in] Input The measured value. | |
43 | * @param[in,out] Output The computed result. | |
44 | * @param[in] Setpoint The setpoint to regulate to. | |
45 | * @param[in] Kp The Proportional value. | |
46 | * @param[in] Ki The Intergral value. | |
47 | * @param[in] Kd The Derivate value. | |
48 | * @param[in] POn 0 - PID on Measurement, 1 - PID on Error. | |
49 | * @param[in] ControllerDirection Direct or Reverse action. | |
50 | */ | |
51 | void PID(double* Input, double* Output, double* Setpoint, double Kp, double Ki, double Kd, PID_PON POn, PID_DIRECTION Direction); | |
52 | ||
53 | /** | |
54 | * @brief sets PID to either Manual or Automatic. | |
55 | * @param Mode Manual (0) or Automatic (1). | |
56 | */ | |
57 | void PID_SetMode(PID_MODE Mode); | |
58 | ||
59 | /** | |
60 | * @brief This, as they say, is where the magic happens. this function should be called | |
61 | * every time "void loop()" executes. the function will decide for itself whether a new | |
62 | * pid Output needs to be computed. | |
63 | * @return Returns true when the output is computed, false when nothing has been done. | |
64 | */ | |
65 | bool PID_Compute(void); | |
66 | ||
67 | /** | |
68 | * @brief Clamps the output to a specific range. 0-255 by default, but it's likely the user | |
69 | * will want to change this depending on the application. | |
70 | * @param[in] Min The minimal value that Output can be. | |
71 | * @param[in] Max The maximum value that Output can be. | |
72 | */ | |
73 | void PID_SetOutputLimits(double Min, double Max); | |
74 | ||
75 | /** | |
76 | * @brief While most users will set the tunings once in the constructor, this function gives | |
77 | * the user the option of changing tunings during runtime for Adaptive control. | |
78 | * @param[in] Kp The Proportional value. | |
79 | * @param[in] Ki The Intergral value. | |
80 | * @param[in] Kd The Derivate value. | |
81 | * @param[in] POn 0 - PID on Measurement, 1 - PID on Error. | |
82 | */ | |
83 | void PID_SetTunings(double Kp, double Ki, double Kd, PID_PON POn); | |
84 | ||
85 | /** | |
86 | * @brief The PID will either be connected to a DIRECT acting process (+Output leads | |
87 | * to +Input) or a REVERSE acting process(+Output leads to -Input.) we need to | |
88 | * know which one, because otherwise we may increase the output when we should | |
89 | * be decreasing. | |
90 | * @param[in] Direction Direct or Reverse action. | |
91 | */ | |
92 | void PID_SetControllerDirection(PID_DIRECTION Direction); | |
93 | ||
94 | /** | |
95 | * @brief Sets the frequency, in Milliseconds, with which the PID calculation is performed. | |
96 | * default is 100 | |
97 | * @param[in] NewSampleTime The new time in Milliseconds. | |
98 | */ | |
99 | void PID_SetSampleTime(int NewSampleTime); | |
100 | ||
101 | /** | |
102 | * @brief This function queries the internal state of the PID. It's here for display | |
103 | * purposes. this are the functions the PID Front-end uses for example. | |
104 | * @return The Kp setting. | |
105 | */ | |
106 | double PID_GetKp(); | |
107 | ||
108 | /** | |
109 | * @brief This function queries the internal state of the PID. It's here for display | |
110 | * purposes. this are the functions the PID Front-end uses for example. | |
111 | * @return The Ki setting. | |
112 | */ | |
113 | double PID_GetKi(); | |
114 | ||
115 | /** | |
116 | * @brief This function queries the internal state of the PID. It's here for display | |
117 | * purposes. this are the functions the PID Front-end uses for example. | |
118 | * @return The Kp setting. | |
119 | */ | |
120 | double PID_GetKd(); | |
121 | ||
122 | /** | |
123 | * @brief This function queries the internal state of the PID. It's here for display | |
124 | * purposes. this are the functions the PID Front-end uses for example. | |
125 | * @return Returns PID_AUTOMATIC or PID_MANUAL. | |
126 | */ | |
127 | PID_MODE PID_GetMode(); | |
128 | ||
129 | /** | |
130 | * @brief This function queries the internal state of the PID. It's here for display | |
131 | * purposes. this are the functions the PID Front-end uses for example. | |
132 | * @return Returns PID_DIRECT or PID_REVERSE. | |
133 | */ | |
134 | PID_DIRECTION PID_GetDirection(); | |
135 | ||
136 | ||
137 | #endif |