MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

float/pi.h
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2 * Copyright (c) 2014, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * --/COPYRIGHT--*/
32 #ifndef _PI_H_
33 #define _PI_H_
34
40
41
42 // **************************************************************************
43 // the includes
44
45 // modules
46 #include "sw/modules/types/src/types.h"
47 #include "sw/modules/math/src/float/math.h"
48
49
54
55
56 // Include the algorithm overview defined in modules/<module>/docs/doxygen/doxygen.h
58
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62
63
64 // **************************************************************************
65 // the defines
66
67
68
69 // **************************************************************************
70 // the typedefs
71
74 typedef struct _PI_Obj_
75 {
76 float_t Kp;
77 float_t Ki;
78
79 float_t Ui;
80
81 float_t refValue;
82 float_t fbackValue;
83 float_t ffwdValue;
84
85 float_t outMin;
86 float_t outMax;
87
88 } PI_Obj;
89
90
93 typedef struct _PI_Obj_ *PI_Handle;
94
95
96 // **************************************************************************
97 // the function prototypes
98
102 static inline float_t PI_getFbackValue(PI_Handle handle)
103 {
104 PI_Obj *obj = (PI_Obj *)handle;
105
106 return(obj->fbackValue);
107 } // end of PI_getFbackValue() function
108
109
113 static inline float_t PI_getFfwdValue(PI_Handle handle)
114 {
115 PI_Obj *obj = (PI_Obj *)handle;
116
117 return(obj->ffwdValue);
118 } // end of PI_getFfwdValue() function
119
120
125 static inline void PI_getGains(PI_Handle handle,float_t *pKp,float_t *pKi)
126 {
127 PI_Obj *obj = (PI_Obj *)handle;
128
129 *pKp = obj->Kp;
130 *pKi = obj->Ki;
131
132 return;
133 } // end of PI_getGains() function
134
135
139 static inline float_t PI_getKi(PI_Handle handle)
140 {
141 PI_Obj *obj = (PI_Obj *)handle;
142
143 return(obj->Ki);
144 } // end of PI_getKi() function
145
146
150 static inline float_t PI_getKp(PI_Handle handle)
151 {
152 PI_Obj *obj = (PI_Obj *)handle;
153
154 return(obj->Kp);
155 } // end of PI_getKp() function
156
157
162 static inline void PI_getMinMax(PI_Handle handle,float_t *pOutMin,float_t *pOutMax)
163 {
164 PI_Obj *obj = (PI_Obj *)handle;
165
166 *pOutMin = obj->outMin;
167 *pOutMax = obj->outMax;
168
169 return;
170 } // end of PI_getMinMax() function
171
172
176 static inline float_t PI_getOutMax(PI_Handle handle)
177 {
178 PI_Obj *obj = (PI_Obj *)handle;
179
180 return(obj->outMax);
181 } // end of PI_getOutMax() function
182
183
187 static inline float_t PI_getOutMin(PI_Handle handle)
188 {
189 PI_Obj *obj = (PI_Obj *)handle;
190
191 return(obj->outMin);
192 } // end of PI_getOutMin() function
193
194
198 static inline float_t PI_getRefValue(PI_Handle handle)
199 {
200 PI_Obj *obj = (PI_Obj *)handle;
201
202 return(obj->refValue);
203 } // end of PI_getRefValue() function
204
205
209 static inline float_t PI_getUi(PI_Handle handle)
210 {
211 PI_Obj *obj = (PI_Obj *)handle;
212
213 return(obj->Ui);
214 } // end of PI_getUi() function
215
216
221 extern PI_Handle PI_init(void *pMemory,const size_t numBytes);
222
223
227 static inline void PI_setFbackValue(PI_Handle handle,const float_t fbackValue)
228 {
229 PI_Obj *obj = (PI_Obj *)handle;
230
231 obj->fbackValue = fbackValue;
232
233 return;
234 } // end of PI_setFbackValue() function
235
236
240 static inline void PI_setFfwdValue(PI_Handle handle,const float_t ffwdValue)
241 {
242 PI_Obj *obj = (PI_Obj *)handle;
243
244 obj->ffwdValue = ffwdValue;
245
246 return;
247 } // end of PI_setFfwdValue() function
248
249
254 static inline void PI_setGains(PI_Handle handle,const float_t Kp,const float_t Ki)
255 {
256 PI_Obj *obj = (PI_Obj *)handle;
257
258 obj->Kp = Kp;
259 obj->Ki = Ki;
260
261 return;
262 } // end of PI_setGains() function
263
264
268 static inline void PI_setKi(PI_Handle handle,const float_t Ki)
269 {
270 PI_Obj *obj = (PI_Obj *)handle;
271
272 obj->Ki = Ki;
273
274 return;
275 } // end of PI_setKi() function
276
277
281 static inline void PI_setKp(PI_Handle handle,const float_t Kp)
282 {
283 PI_Obj *obj = (PI_Obj *)handle;
284
285 obj->Kp = Kp;
286
287 return;
288 } // end of PI_setKp() function
289
290
295 static inline void PI_setMinMax(PI_Handle handle,const float_t outMin,const float_t outMax)
296 {
297 PI_Obj *obj = (PI_Obj *)handle;
298
299 obj->outMin = outMin;
300 obj->outMax = outMax;
301
302 return;
303 } // end of PI_setMinMax() function
304
305
309 static inline void PI_setOutMax(PI_Handle handle,const float_t outMax)
310 {
311 PI_Obj *obj = (PI_Obj *)handle;
312
313 obj->outMax = outMax;
314
315 return;
316 } // end of PI_setOutMax() function
317
318
322 static inline void PI_setOutMin(PI_Handle handle,const float_t outMin)
323 {
324 PI_Obj *obj = (PI_Obj *)handle;
325
326 obj->outMin = outMin;
327
328 return;
329 } // end of PI_setOutMin() function
330
331
335 static inline void PI_setRefValue(PI_Handle handle,const float_t refValue)
336 {
337 PI_Obj *obj = (PI_Obj *)handle;
338
339 obj->refValue = refValue;
340
341 return;
342 } // end of PI_setRefValue() function
343
344
348 static inline void PI_setUi(PI_Handle handle,const float_t Ui)
349 {
350 PI_Obj *obj = (PI_Obj *)handle;
351
352 obj->Ui = Ui;
353
354 return;
355 } // end of PI_setUi() function
356
357
364 static inline void PI_run_parallel(PI_Handle handle,const float_t refValue,const float_t fbackValue,
365 const float_t ffwdValue,float_t *pOutValue)
366 {
367 float_t Error;
368 float_t Kp = PI_getKp(handle);
369 float_t Ki = PI_getKi(handle);
370 float_t Up;
371 float_t Ui = PI_getUi(handle);
372 float_t outMax = PI_getOutMax(handle);
373 float_t outMin = PI_getOutMin(handle);
374
375 Error = refValue - fbackValue;
376
377 Up = Kp * Error; // Compute the proportional output
378 Ui = MATH_sat(Ui + (Ki * Error),outMax,outMin); // Compute the integral output
379
380 PI_setUi(handle,Ui);
381 PI_setRefValue(handle,refValue);
382 PI_setFbackValue(handle,fbackValue);
383 PI_setFfwdValue(handle,ffwdValue);
384
385 *pOutValue = MATH_sat(Up + Ui + ffwdValue,outMax,outMin); // Saturate the output
386
387 return;
388 } // end of PI_run_parallel() function
389
390
397 static inline void PI_run_series(PI_Handle handle,const float_t refValue,const float_t fbackValue,
398 const float_t ffwdValue,float_t *pOutValue)
399 {
400 float_t Error;
401 float_t Kp = PI_getKp(handle);
402 float_t Ki = PI_getKi(handle);
403 float_t Up;
404 float_t Ui = PI_getUi(handle);
405 float_t outMax = PI_getOutMax(handle);
406 float_t outMin = PI_getOutMin(handle);
407
408
409 Error = refValue - fbackValue;
410
411 Up = Kp * Error; // Compute the proportional output
412
413 Ui = MATH_sat(Ui + (Ki * Up),outMax,outMin); // Compute the integral output with saturation
414
415 PI_setUi(handle,Ui);
416 PI_setRefValue(handle,refValue);
417 PI_setFbackValue(handle,fbackValue);
418 PI_setFfwdValue(handle,ffwdValue);
419
420 *pOutValue = MATH_sat(Up + Ui + ffwdValue,outMax,outMin); // Saturate the output
421
422 return;
423 } // end of PI_run_series() function
424
425
426 #ifdef __cplusplus
427 }
428 #endif // extern "C"
429
431 #endif //end of _PI_H_ definition
432
_PI_Obj_::ffwdValue
_iq ffwdValue
the feedforward input value
Definition: 32b/pi.h:83
PI_getKi
static float_t PI_getKi(PI_Handle handle)
Gets the integral gain in the PI controller.
Definition: float/pi.h:139
types.h
Contains the public interface to the types definitions.
PI_getOutMax
static float_t PI_getOutMax(PI_Handle handle)
Gets the maximum output value allowed in the PI controller.
Definition: float/pi.h:176
_PI_Obj_
Defines the PI controller object.
Definition: 32b/pi.h:74
PI_run_parallel
static void PI_run_parallel(PI_Handle handle, const float_t refValue, const float_t fbackValue, const float_t ffwdValue, float_t *pOutValue)
Runs the parallel form of the PI controller.
Definition: float/pi.h:364
_PI_Obj_::refValue
float_t refValue
the reference input value
Definition: float/pi.h:81
math.h
Contains the public interface to the math (MATH) module routines.
PI_setOutMin
static void PI_setOutMin(PI_Handle handle, const float_t outMin)
Sets the minimum output value allowed in the PI controller.
Definition: float/pi.h:322
_PI_Obj_::outMax
float_t outMax
the maximum output value allowed for the PI controller
Definition: float/pi.h:86
PI_getMinMax
static void PI_getMinMax(PI_Handle handle, float_t *pOutMin, float_t *pOutMax)
Gets the minimum and maximum output value allowed in the PI controller.
Definition: float/pi.h:162
_PI_Obj_::Ui
_iq Ui
the integrator start value for the PI controller
Definition: 32b/pi.h:79
_PI_Obj_::Ki
_iq Ki
the integral gain for the PI controller
Definition: 32b/pi.h:77
PI_getRefValue
static float_t PI_getRefValue(PI_Handle handle)
Gets the reference value in the PI controller.
Definition: float/pi.h:198
PI_run_series
static void PI_run_series(PI_Handle handle, const float_t refValue, const float_t fbackValue, const float_t ffwdValue, float_t *pOutValue)
Runs the series form of the PI controller.
Definition: float/pi.h:397
_PI_Obj_::ffwdValue
float_t ffwdValue
the feedforward input value
Definition: float/pi.h:83
PI_setKp
static void PI_setKp(PI_Handle handle, const float_t Kp)
Sets the proportional gain in the PI controller.
Definition: float/pi.h:281
MATH_sat
static float_t MATH_sat(const float_t in, const float_t max, const float_t min)
Saturates the input value between the minimum and maximum values.
Definition: float/math.h:218
PI_setKi
static void PI_setKi(PI_Handle handle, const float_t Ki)
Sets the integral gain in the PI controller.
Definition: float/pi.h:268
PI_getKp
static float_t PI_getKp(PI_Handle handle)
Gets the proportional gain in the PI controller.
Definition: float/pi.h:150
PI_init
PI_Handle PI_init(void *pMemory, const size_t numBytes)
Initializes the PI controller.
Definition: 32b/pi.c:56
PI_setMinMax
static void PI_setMinMax(PI_Handle handle, const float_t outMin, const float_t outMax)
Sets the minimum and maximum output value allowed in the PI controller.
Definition: float/pi.h:295
_PI_Obj_::Kp
float_t Kp
the proportional gain for the PI controller
Definition: float/pi.h:76
_PI_Obj_::Kp
_iq Kp
the proportional gain for the PI controller
Definition: 32b/pi.h:76
PI_getFfwdValue
static float_t PI_getFfwdValue(PI_Handle handle)
Gets the feedforward value in the PI controller.
Definition: float/pi.h:113
PI_Obj
struct _PI_Obj_ PI_Obj
Defines the PI controller object.
PI_setRefValue
static void PI_setRefValue(PI_Handle handle, const float_t refValue)
Sets the reference value in the PI controller.
Definition: float/pi.h:335
_PI_Obj_::fbackValue
_iq fbackValue
the feedback input value
Definition: 32b/pi.h:82
PI_setFbackValue
static void PI_setFbackValue(PI_Handle handle, const float_t fbackValue)
Sets the feedback value in the PI controller.
Definition: float/pi.h:227
PI_setGains
static void PI_setGains(PI_Handle handle, const float_t Kp, const float_t Ki)
Sets the gains in the PI controller.
Definition: float/pi.h:254
PI_setFfwdValue
static void PI_setFfwdValue(PI_Handle handle, const float_t ffwdValue)
Sets the feedforward value in the PI controller.
Definition: float/pi.h:240
_PI_Obj_::outMax
_iq outMax
the maximum output value allowed for the PI controller
Definition: 32b/pi.h:86
_PI_Obj_::Ui
float_t Ui
the integrator start value for the PI controller
Definition: float/pi.h:79
_PI_Obj_::refValue
_iq refValue
the reference input value
Definition: 32b/pi.h:81
_PI_Obj_::fbackValue
float_t fbackValue
the feedback input value
Definition: float/pi.h:82
PI_getFbackValue
static float_t PI_getFbackValue(PI_Handle handle)
Gets the feedback value in the PI controller.
Definition: float/pi.h:102
PI_Handle
struct _PI_Obj_ * PI_Handle
Defines the PI handle.
Definition: float/pi.h:93
PI_setOutMax
static void PI_setOutMax(PI_Handle handle, const float_t outMax)
Sets the maximum output value allowed in the PI controller.
Definition: float/pi.h:309
_PI_Obj_::outMin
float_t outMin
the minimum output value allowed for the PI controller
Definition: float/pi.h:85
PI_setUi
static void PI_setUi(PI_Handle handle, const float_t Ui)
Sets the integrator start value in the PI controller.
Definition: float/pi.h:348
PI_getOutMin
static float_t PI_getOutMin(PI_Handle handle)
Gets the minimum output value allowed in the PI controller.
Definition: float/pi.h:187
_PI_Obj_::Ki
float_t Ki
the integral gain for the PI controller
Definition: float/pi.h:77
PI_getGains
static void PI_getGains(PI_Handle handle, float_t *pKp, float_t *pKi)
Gets the gains in the PI controller.
Definition: float/pi.h:125
PI_getUi
static float_t PI_getUi(PI_Handle handle)
Gets the integrator start value in the PI controller.
Definition: float/pi.h:209
_PI_Obj_::outMin
_iq outMin
the minimum output value allowed for the PI controller
Definition: 32b/pi.h:85
float_t
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121