@@ -5,7 +5,8 @@ PID Controller library for ARM Cortex M (STM32)
5
5
6
6
> #### Download Arduino Library : [ Arduino-PID-Library] ( https://github.com/br3ttb/Arduino-PID-Library )
7
7
8
- ### Version : 1.0.0
8
+ ## Release
9
+ - #### Version : 1.0.0
9
10
10
11
- #### Type : Embedded Software.
11
12
@@ -21,13 +22,14 @@ PID Controller library for ARM Cortex M (STM32)
21
22
- #### Required Library/Driver :
22
23
23
24
25
+ ## Overview
24
26
### Initialization and de-initialization functions:
25
27
``` c++
26
28
void PID (PID_TypeDef * uPID, double * Input, double * Output, double * Setpoint, double Kp, double Ki, double Kd, PIDPON_TypeDef POn, PIDCD_TypeDef ControllerDirection);
27
29
void PID2(PID_TypeDef * uPID, double * Input, double * Output, double * Setpoint, double Kp, double Ki, double Kd, PIDCD_TypeDef ControllerDirection);
28
30
```
29
31
30
- ### PID operation functions:
32
+ ### Operation functions:
31
33
```c++
32
34
/* ::::::::::: Computing ::::::::::: */
33
35
uint8_t PID_Compute(PID_TypeDef *uPID);
@@ -57,33 +59,67 @@ double PID_GetKd(PID_TypeDef *uPID);
57
59
```
58
60
59
61
### Macros:
62
+ ``` diff
63
+ non
64
+ ```
65
+
66
+ ## Guide
67
+
68
+ #### This library can be used as follows:
69
+ #### 1. Add pid.h header
70
+ #### 2. Create PID struct and initialize it, for example:
71
+ * Initializer:
72
+ ``` c++
73
+ PID (PID_TypeDef * uPID, double * Input, double * Output, double * Setpoint, double Kp, double Ki, double Kd, PIDPON_TypeDef POn, PIDCD_TypeDef ControllerDirection);
74
+ ```
75
+ * Parameters:
76
+ * uPID : Pointer to pid struct
77
+ * Input : The variable we're trying to control (double)
78
+ * Output : The variable that will be adjusted by the pid (double)
79
+ * Setpoint : The value we want to Input to maintain (double)
80
+ * Kp,Ki,Kd : Tuning Parameters. these affect how the pid will change the output (double>=0)
81
+ * POn : Either P_ON_E (Default) or P_ON_M. Allows Proportional on Measurement to be specified.
82
+ * ControllerDirection : Either DIRECT or REVERSE. determines which direction the output will move when faced with a given error. DIRECT is most common
83
+
84
+
85
+ * Example:
86
+ ```c++
87
+ PID_TypeDef TPID;
88
+
89
+ double Temp, PIDOut, TempSetpoint;
60
90
61
- ## How to use this library
62
-
63
- ### The PID library can be used as follows:
64
- 1.1 Add pid.h header
65
-
66
- 2.1 Initialize:
67
-
68
- ``` c++
69
- PID_TypeDef TPID;
70
-
71
- double Temp, PIDOut, TempSetpoint;
72
-
73
- PID (&TPID, &Temp, &PIDOut, &TempSetpoint, 2, 5, 1, _ PID_P_ON_E, _ PID_CD_DIRECT);
74
-
75
- PID_SetMode(&TPID, _ PID_MODE_AUTOMATIC);
76
- PID_SetSampleTime(&TPID, 500);
77
- PID_SetOutputLimits(&TPID, 1, 100);
78
- ```
79
-
80
- 3.1 Using Compute function, for example:
91
+ PID(&TPID, &Temp, &PIDOut, &TempSetpoint, 2, 5, 1, _PID_P_ON_E, _PID_CD_DIRECT);
92
+ ```
93
+ #### 3. Set 'mode', 'sample time' and 'output limit', for example:
94
+ * Functions:
95
+ ``` c++
96
+ void PID_SetMode (PID_TypeDef * uPID, PIDMode_TypeDef Mode);
97
+ void PID_SetOutputLimits(PID_TypeDef * uPID, double Min, double Max);
98
+ void PID_SetSampleTime(PID_TypeDef * uPID, int32_t NewSampleTime);
99
+ ```
100
+ * Parameters:
101
+ * uPID : Pointer to pid struct
102
+ * Mode : _PID_MODE_AUTOMATIC or _PID_MODE_MANUAL
103
+ * Min : Low end of the range. must be < max (double)
104
+ * Max : High end of the range. must be > min (double)
105
+ * NewSampleTime : How often, in milliseconds, the PID will be evaluated. (int>0)
106
+
107
+ * Example:
108
+ ```c++
109
+ PID_SetMode(&TPID, _PID_MODE_AUTOMATIC);
110
+ PID_SetSampleTime(&TPID, 500);
111
+ PID_SetOutputLimits(&TPID, 1, 100);
112
+ ```
113
+
114
+ #### 4. Using Compute function, for example:
81
115
82
116
``` c++
83
117
PID_Compute (&TPID);
84
118
```
85
119
86
- ##### Example 1:
120
+ ## Examples
121
+
122
+ #### Example 1: PID Compute for temperature
87
123
```c++
88
124
#include "main.h"
89
125
#include "pid.h"
@@ -121,8 +157,8 @@ int main(void)
121
157
```
122
158
123
159
## Tests performed:
124
- - [ ] Run on AVR
125
160
- [x] Run on STM32 Fx cores
126
161
127
- #### Developer: Majid Derhambakhsh
162
+ ## Developers:
163
+ - ### Majid Derhambakhsh
128
164
0 commit comments