AM243x Motor Control SDK  09.02.00
pi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * 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
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef PI_H
34 #define PI_H
35 
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40 
41 #include "dcl.h"
42 #include <stdlib.h>
43 
59 //*****************************************************************************
60 //
62 //
63 //*****************************************************************************
64 typedef struct _PI_Obj_
65 {
70 } PI_Obj;
71 
72 //*****************************************************************************
73 //
75 //
76 //*****************************************************************************
77 typedef struct _PI_Obj_ *PI_Handle;
78 
79 //*****************************************************************************
80 //
86 //
87 //*****************************************************************************
88 static inline float32_t
90 {
91  return(handle->fbackValue);
92 } // end of PI_getFbackValue() function
93 
94 //*****************************************************************************
95 //
101 //
102 //*****************************************************************************
103 static inline float32_t
105 {
106  return(handle->ffwdValue);
107 } // end of PI_getFfwdValue() function
108 
109 //*****************************************************************************
110 //
118 //
119 //*****************************************************************************
120 static inline void
122 {
123  *pKp = handle->cntlr.Kp;
124  *pKi = handle->cntlr.Ki;
125 } // end of PI_getGains() function
126 
127 //*****************************************************************************
128 //
134 //
135 //*****************************************************************************
136 static inline float32_t
138 {
139  return(handle->cntlr.Ki);
140 } // end of PI_getKi() function
141 
142 //*****************************************************************************
143 //
149 //
150 //*****************************************************************************
151 static inline float32_t
153 {
154  return(handle->cntlr.Kp);
155 } // end of PI_getKp() function
156 
157 //*****************************************************************************
158 //
167 //
168 //*****************************************************************************
169 static inline void
170 PI_getMinMax(PI_Handle handle, float32_t *pOutMin, float32_t *pOutMax)
171 {
172  *pOutMin = handle->cntlr.Umin;
173  *pOutMax = handle->cntlr.Umax;
174 } // end of PI_getMinMax() function
175 
176 //*****************************************************************************
177 //
183 //
184 //*****************************************************************************
185 static inline float32_t
187 {
188  return(handle->cntlr.Umax);
189 } // end of PI_getOutMax() function
190 
191 //*****************************************************************************
192 //
198 //
199 //*****************************************************************************
200 static inline float32_t
202 {
203  return(handle->cntlr.Umin);
204 } // end of PI_getOutMin() function
205 
206 //*****************************************************************************
207 //
213 //
214 //*****************************************************************************
215 static inline float32_t
217 {
218  return(handle->refValue);
219 } // end of PI_getRefValue() function
220 
221 //*****************************************************************************
222 //
228 //
229 //*****************************************************************************
230 static inline float32_t
232 {
233  return(handle->cntlr.i10);
234 } // end of PI_getUi() function
235 
236 //*****************************************************************************
237 //
246 //
247 //*****************************************************************************
248 extern PI_Obj*
249 PI_init(void *pMemory, const size_t numBytes);
250 
251 //*****************************************************************************
252 //
258 //
259 //*****************************************************************************
260 static inline void
261 PI_setFbackValue(PI_Handle handle, const float32_t fbackValue)
262 {
263  handle->fbackValue = fbackValue;
264 
265  return;
266 } // end of PI_setFbackValue() function
267 
268 //*****************************************************************************
269 //
275 //
276 //*****************************************************************************
277 static inline void
278 PI_setFfwdValue(PI_Handle handle, const float32_t ffwdValue)
279 {
280  handle->ffwdValue = ffwdValue;
281 
282  return;
283 } // end of PI_setFfwdValue() function
284 
285 //*****************************************************************************
286 //
294 //
295 //*****************************************************************************
296 static inline void
297 PI_setGains(PI_Handle handle, const float32_t Kp, const float32_t Ki)
298 {
299  handle->cntlr.Kp = Kp;
300  handle->cntlr.Ki = Ki;
301 } // end of PI_setGains() function
302 
303 //*****************************************************************************
304 //
310 //
311 //*****************************************************************************
312 static inline void
313 PI_setKi(PI_Handle handle, const float32_t Ki)
314 {
315  handle->cntlr.Ki = Ki;
316 } // end of PI_setKi() function
317 
318 //*****************************************************************************
319 //
325 //
326 //*****************************************************************************
327 static inline void
328 PI_setKp(PI_Handle handle, const float32_t Kp)
329 {
330  handle->cntlr.Kp = Kp;
331 } // end of PI_setKp() function
332 
333 //*****************************************************************************
334 //
343 //
344 //*****************************************************************************
345 static inline void
346 PI_setMinMax(PI_Handle handle, const float32_t outMin, const float32_t outMax)
347 {
348  handle->cntlr.Umin = outMin;
349  handle->cntlr.Umax = outMax;
350 } // end of PI_setMinMax() function
351 
352 //*****************************************************************************
353 //
359 //
360 //*****************************************************************************
361 static inline void
362 PI_setOutMax(PI_Handle handle, const float32_t outMax)
363 {
364  handle->cntlr.Umax = outMax;
365 } // end of PI_setOutMax() function
366 
367 //*****************************************************************************
368 //
374 //
375 //*****************************************************************************
376 static inline void
377 PI_setOutMin(PI_Handle handle, const float32_t outMin)
378 {
379  handle->cntlr.Umin = outMin;
380 } // end of PI_setOutMin() function
381 
382 //*****************************************************************************
383 //
389 //
390 //*****************************************************************************
391 static inline void
392 PI_setRefValue(PI_Handle handle, const float32_t refValue)
393 {
394  handle->refValue = refValue;
395 
396  return;
397 } // end of PI_setRefValue() function
398 
399 //*****************************************************************************
400 //
406 //
407 //*****************************************************************************
408 static inline void
409 PI_setUi(PI_Handle handle, const float32_t Ui)
410 {
411  handle->cntlr.i10 = Ui;
412 } // end of PI_setUi() function
413 
414 //*****************************************************************************
415 //
427 //
428 //*****************************************************************************
429 static inline void
430 PI_run_parallel(PI_Handle handle, const float32_t refValue,
431  const float32_t fbackValue, const float32_t ffwdValue,
432  float32_t *pOutValue)
433 {
434  handle->cntlr.i10 += ffwdValue;
435  *pOutValue = DCL_runPIParallel(&handle->cntlr, refValue, fbackValue);
436 
437  PI_setRefValue(handle,refValue);
438  PI_setFbackValue(handle,fbackValue);
439  PI_setFfwdValue(handle,ffwdValue);
440 } // end of PI_run_parallel() function
441 
442 //*****************************************************************************
443 //
455 //
456 //*****************************************************************************
457 static inline void
458 PI_run_series(PI_Handle handle, const float32_t refValue,
459  const float32_t fbackValue, const float32_t ffwdValue,
460  float32_t *pOutValue)
461 {
462  handle->cntlr.i10 += ffwdValue;
463  *pOutValue = DCL_runPISeries(&handle->cntlr, refValue, fbackValue);
464 
465  PI_setRefValue(handle,refValue);
466  PI_setFbackValue(handle,fbackValue);
467  PI_setFfwdValue(handle,ffwdValue);
468 } // end of PI_run_series() function
469 
470 
471 //*****************************************************************************
472 //
482 //
483 //*****************************************************************************
484 static inline void
485 PI_run(PI_Handle handle, const float32_t refValue,
486  const float32_t fbackValue, float32_t *pOutValue)
487 {
488  *pOutValue = DCL_runPISeries(&handle->cntlr, refValue, fbackValue);
489 } // end of PI_run_series() function
490 
493 #ifdef __cplusplus
494 }
495 #endif
496 
497 #endif // end of PI_H defines
PI_Obj::refValue
float32_t refValue
the reference input value
Definition: pi.h:67
PI_getKi
static float32_t PI_getKi(PI_Handle handle)
Gets the integral gain in the PI controller.
Definition: pi.h:137
PI_setFfwdValue
static void PI_setFfwdValue(PI_Handle handle, const float32_t ffwdValue)
Sets the feedforward value in the PI controller.
Definition: pi.h:278
PI_setRefValue
static void PI_setRefValue(PI_Handle handle, const float32_t refValue)
Sets the reference value in the PI controller.
Definition: pi.h:392
PI_getRefValue
static float32_t PI_getRefValue(PI_Handle handle)
Gets the reference value in the PI controller.
Definition: pi.h:216
PI_Handle
struct _PI_Obj_ * PI_Handle
Defines the PI handle.
Definition: pi.h:77
PI_setMinMax
static void PI_setMinMax(PI_Handle handle, const float32_t outMin, const float32_t outMax)
Sets the minimum and maximum output value allowed in the PI controller.
Definition: pi.h:346
PI_Obj::fbackValue
float32_t fbackValue
the feedback input value
Definition: pi.h:68
PI_setOutMax
static void PI_setOutMax(PI_Handle handle, const float32_t outMax)
Sets the maximum output value allowed in the PI controller.
Definition: pi.h:362
PI_getOutMin
static float32_t PI_getOutMin(PI_Handle handle)
Gets the minimum output value allowed in the PI controller.
Definition: pi.h:201
PI_getGains
static void PI_getGains(PI_Handle handle, float32_t *pKp, float32_t *pKi)
Gets the gains in the PI controller.
Definition: pi.h:121
PI_setOutMin
static void PI_setOutMin(PI_Handle handle, const float32_t outMin)
Sets the minimum output value allowed in the PI controller.
Definition: pi.h:377
PI_getUi
static float32_t PI_getUi(PI_Handle handle)
Gets the integrator start value in the PI controller.
Definition: pi.h:231
PI_run_series
static void PI_run_series(PI_Handle handle, const float32_t refValue, const float32_t fbackValue, const float32_t ffwdValue, float32_t *pOutValue)
Runs the series form of the PI controller.
Definition: pi.h:458
PI_run_parallel
static void PI_run_parallel(PI_Handle handle, const float32_t refValue, const float32_t fbackValue, const float32_t ffwdValue, float32_t *pOutValue)
Runs the parallel form of the PI controller.
Definition: pi.h:430
DCL_runPIParallel
_DCL_CRIT_ACCESS float32_t DCL_runPIParallel(DCL_PI *pi, float32_t rk, float32_t yk)
Executes a parallel form PI controller Implemented as inline C function.
Definition: dcl_pi.h:340
PI_setGains
static void PI_setGains(PI_Handle handle, const float32_t Kp, const float32_t Ki)
Sets the gains in the PI controller.
Definition: pi.h:297
PI_setFbackValue
static void PI_setFbackValue(PI_Handle handle, const float32_t fbackValue)
Sets the feedback value in the PI controller.
Definition: pi.h:261
PI_getKp
static float32_t PI_getKp(PI_Handle handle)
Gets the proportional gain in the PI controller.
Definition: pi.h:152
PI_Obj::ffwdValue
float32_t ffwdValue
the feedforward input value
Definition: pi.h:69
dcl.h
Top level header that contains all collections of Digital Controller Library functions.
PI_Obj::cntlr
DCL_PI cntlr
The PI controller object.
Definition: pi.h:66
PI_getMinMax
static void PI_getMinMax(PI_Handle handle, float32_t *pOutMin, float32_t *pOutMax)
Gets the minimum and maximum output value allowed in the PI controller.
Definition: pi.h:170
PI_init
PI_Obj * PI_init(void *pMemory, const size_t numBytes)
Initializes the PI controller.
PI_getFfwdValue
static float32_t PI_getFfwdValue(PI_Handle handle)
Gets the feedforward value in the PI controller.
Definition: pi.h:104
DCL_runPISeries
_DCL_CRIT_ACCESS float32_t DCL_runPISeries(DCL_PI *pi, float32_t rk, float32_t yk)
Executes an inline series form PI controller.
Definition: dcl_pi.h:313
PI_Obj
Defines the PI controller object.
Definition: pi.h:65
PI_run
static void PI_run(PI_Handle handle, const float32_t refValue, const float32_t fbackValue, float32_t *pOutValue)
Runs the series form of the PI controller without updating the data strcture.
Definition: pi.h:485
DCL_PI
_DCL_VOLATILE struct dcl_pi DCL_PI
PI_getFbackValue
static float32_t PI_getFbackValue(PI_Handle handle)
Gets the feedback value in the PI controller.
Definition: pi.h:89
PI_setUi
static void PI_setUi(PI_Handle handle, const float32_t Ui)
Sets the integrator start value in the PI controller.
Definition: pi.h:409
PI_setKp
static void PI_setKp(PI_Handle handle, const float32_t Kp)
Sets the proportional gain in the PI controller.
Definition: pi.h:328
PI_getOutMax
static float32_t PI_getOutMax(PI_Handle handle)
Gets the maximum output value allowed in the PI controller.
Definition: pi.h:186
float32_t
float float32_t
Definition: dcl_common.h:58
PI_setKi
static void PI_setKi(PI_Handle handle, const float32_t Ki)
Sets the integral gain in the PI controller.
Definition: pi.h:313