Fri, 30 Jul 2021 20:35:04 +0200
Updated the README
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 Setup the PID controller and initialize. | |
31 | * @param[in] Input The measured value. | |
32 | * @param[in,out] Output The computed result. | |
33 | * @param[in] Setpoint The setpoint to regulate to. | |
34 | * @param[in] Kp The Proportional value. | |
35 | * @param[in] Ki The Intergral value. | |
36 | * @param[in] Kd The Derivate value. | |
29 | 37 | * @param[in] Direction Direct or Reverse action. |
0 | 38 | */ |
82 | 39 | void PID(double* Input, double* Output, double* Setpoint, double Kp, double Ki, double Kd, PID_DIRECTION Direction); |
0 | 40 | |
41 | /** | |
42 | * @brief sets PID to either Manual or Automatic. | |
43 | * @param Mode Manual (0) or Automatic (1). | |
44 | */ | |
45 | void PID_SetMode(PID_MODE Mode); | |
46 | ||
47 | /** | |
48 | * @brief This, as they say, is where the magic happens. this function should be called | |
49 | * every time "void loop()" executes. the function will decide for itself whether a new | |
50 | * pid Output needs to be computed. | |
51 | * @return Returns true when the output is computed, false when nothing has been done. | |
52 | */ | |
53 | bool PID_Compute(void); | |
54 | ||
55 | /** | |
56 | * @brief Clamps the output to a specific range. 0-255 by default, but it's likely the user | |
57 | * will want to change this depending on the application. | |
58 | * @param[in] Min The minimal value that Output can be. | |
59 | * @param[in] Max The maximum value that Output can be. | |
60 | */ | |
61 | void PID_SetOutputLimits(double Min, double Max); | |
62 | ||
63 | /** | |
64 | * @brief While most users will set the tunings once in the constructor, this function gives | |
65 | * the user the option of changing tunings during runtime for Adaptive control. | |
66 | * @param[in] Kp The Proportional value. | |
67 | * @param[in] Ki The Intergral value. | |
68 | * @param[in] Kd The Derivate value. | |
69 | */ | |
82 | 70 | void PID_SetTunings(double Kp, double Ki, double Kd); |
0 | 71 | |
72 | /** | |
73 | * @brief The PID will either be connected to a DIRECT acting process (+Output leads | |
74 | * to +Input) or a REVERSE acting process(+Output leads to -Input.) we need to | |
75 | * know which one, because otherwise we may increase the output when we should | |
76 | * be decreasing. | |
77 | * @param[in] Direction Direct or Reverse action. | |
78 | */ | |
79 | void PID_SetControllerDirection(PID_DIRECTION Direction); | |
80 | ||
81 | /** | |
82 | * @brief Sets the frequency, in Milliseconds, with which the PID calculation is performed. | |
83 | * default is 100 | |
84 | * @param[in] NewSampleTime The new time in Milliseconds. | |
85 | */ | |
86 | void PID_SetSampleTime(int NewSampleTime); | |
87 | ||
88 | /** | |
89 | * @brief This function queries the internal state of the PID. It's here for display | |
90 | * purposes. this are the functions the PID Front-end uses for example. | |
91 | * @return The Kp setting. | |
92 | */ | |
93 | double PID_GetKp(); | |
94 | ||
95 | /** | |
96 | * @brief This function queries the internal state of the PID. It's here for display | |
97 | * purposes. this are the functions the PID Front-end uses for example. | |
98 | * @return The Ki setting. | |
99 | */ | |
100 | double PID_GetKi(); | |
101 | ||
102 | /** | |
103 | * @brief This function queries the internal state of the PID. It's here for display | |
104 | * purposes. this are the functions the PID Front-end uses for example. | |
105 | * @return The Kp setting. | |
106 | */ | |
107 | double PID_GetKd(); | |
108 | ||
109 | /** | |
110 | * @brief This function queries the internal state of the PID. It's here for display | |
111 | * purposes. this are the functions the PID Front-end uses for example. | |
112 | * @return Returns PID_AUTOMATIC or PID_MANUAL. | |
113 | */ | |
114 | PID_MODE PID_GetMode(); | |
115 | ||
116 | /** | |
117 | * @brief This function queries the internal state of the PID. It's here for display | |
118 | * purposes. this are the functions the PID Front-end uses for example. | |
119 | * @return Returns PID_DIRECT or PID_REVERSE. | |
120 | */ | |
121 | PID_DIRECTION PID_GetDirection(); | |
122 | ||
123 | ||
124 | #endif |