![Logo](ti_logo.svg) |
AM263x Motor Control SDK
09.00.00
|
|
Go to the documentation of this file.
48 #include "../dcl_common.h"
55 typedef struct dcl_pid_sps
69 #define PID_SPS_DEFAULTS { 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f }
98 #define PID_DEFAULTS { 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, \
99 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, \
100 &(DCL_PID_SPS)PID_SPS_DEFAULTS, &(DCL_CSS)DCL_CSS_DEFAULTS }
110 #define PID_INT_DEFAULTS .d2=0.0f, .d3=0.0f, .i10=0.0f, .i14=1.0f, \
111 .sps=&(DCL_PID_SPS)PID_SPS_DEFAULTS, .css=&(DCL_CSS)DCL_CSS_DEFAULTS
118 #define DCL_initPID() &(DCL_PID)PID_DEFAULTS
126 #define DCL_initPIDasParam(kp,ki,kd,kr,_c1,_c2,umax,umin) &(DCL_PID){ .Kp=kp, .Ki=ki, .Kd=kd, .Kr=kr, \
127 .c1=_c1, .c2=_c2, .Umax=umax, .Umin=umin, PID_INT_DEFAULTS }
140 #define DCL_initPIDasSPS(pid_ptr,sps_ptr) \
142 DCL_PID* new_pid = (pid_ptr) ? pid_ptr : DCL_initPID(); \
143 DCL_PID_SPS* new_sps = (sps_ptr) ? sps_ptr : &(DCL_PID_SPS)PID_SPS_DEFAULTS; \
146 *new_pid = (DCL_PID){ (new_sps)->Kp, (new_sps)->Ki, (new_sps)->Kd,(new_sps)->Kr,\
147 (new_sps)->c1, (new_sps)->c2, (new_sps)->Umax, (new_sps)->Umin, 0.0f, 0.0f, \
148 0.0f, 1.0f, (DCL_PID_SPS*)new_sps, &(DCL_CSS)DCL_CSS_DEFAULTS }; \
161 pid->d2 = pid->d3 = pid->i10 = 0.0f;
174 #ifdef DCL_ERROR_HANDLING_ENABLED
175 float32_t tau = (2.0f - pid->sps->c1 * pid->css->t_sec) / (2.0f * pid->sps->c1);
176 float32_t ec2 = pid->sps->c1 * (pid->css->t_sec - 2.0f * tau) / 2.0f;
181 err_code |= ((pid->sps->Kp > 0.0f) && (pid->sps->Ki > 0.0f) && (pid->sps->Kd > 0.0f) && (pid->sps->Kr > 0.0f)) ?
dcl_none :
dcl_param_range_err ;
190 pid->Kp = pid->sps->Kp;
191 pid->Ki = pid->sps->Ki;
192 pid->Kd = pid->sps->Kd;
193 pid->Kr = pid->sps->Kr;
194 pid->c1 = pid->sps->c1;
195 pid->c2 = pid->sps->c2;
196 pid->Umax = pid->sps->Umax;
197 pid->Umin = pid->sps->Umin;
209 #ifdef DCL_ERROR_HANDLING_ENABLED
210 float32_t tau = (2.0f - pid->sps->c1 * pid->css->t_sec) / (2.0f * pid->sps->c1);
211 float32_t ec2 = pid->sps->c1 * (pid->css->t_sec - 2.0f * tau) / 2.0f;
216 err_code |= ((pid->sps->Kp > 0.0f) && (pid->sps->Ki > 0.0f) && (pid->sps->Kd > 0.0f) && (pid->sps->Kr > 0.0f)) ?
dcl_none :
dcl_param_range_err ;
229 pid->Kp = pid->sps->Kp;
230 pid->Ki = pid->sps->Ki;
231 pid->Kd = pid->sps->Kd;
232 pid->Kr = pid->sps->Kr;
233 pid->c1 = pid->sps->c1;
234 pid->c2 = pid->sps->c2;
235 pid->Umax = pid->sps->Umax;
236 pid->Umin = pid->sps->Umin;
271 pid->sps->Kp = pid->Kp;
272 pid->sps->Ki = pid->Ki;
273 pid->sps->Kd = pid->Kd;
274 pid->sps->Kr = pid->Kr;
275 pid->sps->c1 = pid->c1;
276 pid->sps->c2 = pid->c2;
277 pid->sps->Umax = pid->Umax;
278 pid->sps->Umin = pid->Umin;
292 #ifdef DCL_ERROR_HANDLING_ENABLED
305 pid->sps->c1 = 2.0f / (t_sec + (2.0f * tau));
306 pid->sps->c2 = (t_sec - (2.0f * tau)) / (t_sec + (2.0f * tau));
321 #ifdef DCL_ERROR_HANDLING_ENABLED
333 pid->c1 = 2.0f / (t_sec + (2.0f * tau));
334 pid->c2 = (t_sec - (2.0f * tau)) / (t_sec + (2.0f * tau));
345 float32_t tau = ((2.0f - pid->c1 * pid->css->t_sec) / (2.0f * pid->c1));
346 return(1.0f / (2.0f *
CONST_PI * tau));
361 #ifdef DCL_ERROR_HANDLING_ENABLED
380 float32_t a0p = 4.0f + (alpha1 * 2.0f * t_sec) + (alpha0 * t_sec * t_sec);
381 float32_t b0 = zpk->
K * (4.0f + (beta1 * 2.0f * t_sec) + (beta0 * t_sec *t_sec)) / a0p;
382 float32_t b1 = zpk->
K * (-8.0f + (2.0f * beta0 * t_sec * t_sec)) / a0p;
383 float32_t b2 = zpk->
K * (4.0f - (beta1 * 2.0f * t_sec) + (beta0 * t_sec * t_sec)) / a0p;
384 float32_t a2 = (4.0f - (alpha1 * 2.0f * t_sec) + (alpha0 * t_sec * t_sec)) / a0p;
386 float32_t tau = (t_sec / 2.0f) * (1.0f - c2) / (1.0f + c2);
387 pid->sps->c1 = 2.0f / (t_sec + 2.0f * tau);
392 #ifdef DCL_ERROR_HANDLING_ENABLED
403 float32_t k1 = ((c2 * b0) - b1 - ((2.0f + c2) * b2)) / det;
404 float32_t k2 = (c2 + 1.0f) * (b0 + b1 + b2) / det;
405 float32_t k3 = ((c2 * c2 * b0) - (c2 * b1) + b2) / det;
407 pid->sps->Ki = k2 / k1;
408 pid->sps->Kd = k3 / (k1 * pid->sps->c1);
410 #ifdef DCL_TESTPOINTS_ENABLED
427 #ifdef DCL_ERROR_HANDLING_ENABLED
446 float32_t a0p = 4.0f + (alpha1 * 2.0f * t_sec) + (alpha0 * t_sec * t_sec);
447 float32_t b0 = zpk->
K * (4.0f + (beta1 * 2.0f * t_sec) + (beta0 * t_sec * t_sec)) / a0p;
448 float32_t b1 = zpk->
K * (-8.0f + (2.0f * beta0 * t_sec * t_sec)) / a0p;
449 float32_t b2 = zpk->
K * (4.0f - (beta1 * 2.0f * t_sec) + (beta0 * t_sec * t_sec)) / a0p;
450 float32_t a2 = (4.0f - (alpha1 * 2.0f * t_sec) + (alpha0 * t_sec * t_sec)) / a0p;
452 float32_t tau = (t_sec / 2.0f) * (1.0f - c2) / (1.0f + c2);
453 pid->sps->c1 = 2.0f / (t_sec + 2.0f * tau);
458 #ifdef DCL_ERROR_HANDLING_ENABLED
468 pid->sps->Kp = ((c2 * b0) - b1 - ((2.0f + c2) * b2)) / det;
469 pid->sps->Ki = (c2 + 1.0f) * (b0 + b1 + b2) / det;
470 pid->sps->Kd = ((c2 * c2 * b0) - (c2 * b1) + b2) / (det * pid->sps->c1);
472 #ifdef DCL_TESTPOINTS_ENABLED
491 v5 = (pid->Kr * rk) - yk;
492 v8 = ((rk - yk) * pid->Ki * pid->Kp * pid->i14) + pid->i10;
494 v1 = yk * pid->Kd * pid->c1;
495 v4 = v1 - pid->d2 - pid->d3;
497 pid->d3 = v4 * pid->c2;
498 v9 = ((v5 - v4) * pid->Kp) + v8;
500 v12 = (v10 == v9) ? 1.0f : 0.0f;
503 #ifdef DCL_TESTPOINTS_ENABLED
521 float32_t v1, v4, v5, v6, v8, v9, v10, v12;
525 v8 = v5 * pid->Ki * pid->i14 + pid->i10;
527 v1 = v5 * pid->Kd * pid->c1;
528 v4 = v1 - pid->d2 - pid->d3;
530 pid->d3 = v4 * pid->c2;
533 v12 = (v10 == v9) ? 1.0f : 0.0f;
536 #ifdef DCL_TESTPOINTS_ENABLED
549 #endif // _DCL_PID_H_
DCL_PID_SPS * sps
updates controller parameter
Definition: dcl_pid.h:92
_DCL_CODE_ACCESS void DCL_fupdatePID(DCL_PID *pid)
Loads PID tuning parameter from its SPS parameter.
Definition: dcl_pid.h:171
_DCL_CODE_ACCESS _DCL_CODE_SECTION bool DCL_updatePID(DCL_PID *pid)
Updates PID parameter from its SPS parameter with interrupt protection.
Definition: dcl_pid.h:206
_DCL_VOLATILE struct dcl_pid DCL_PID
float32_t c1
D path filter coefficient 1, default is 1.
Definition: dcl_pid.h:80
#define DCL_isValue(x, y)
Determines numerical proximity to specified value.
Definition: dcl_aux.h:72
_DCL_CODE_ACCESS void DCL_setActivePIDfilterBW(DCL_PID *pid, float32_t fc, float32_t t_sec)
Loads the PID derivative path filter active coefficients Note: Sampling period pid->css->t_sec are us...
Definition: dcl_pid.h:318
#define CONST_PI
Local definitions of the mathematical constant pi.
Definition: dcl_aux.h:55
float32_t Umin
Lower saturation limit
Definition: dcl_pid.h:83
float32_t K
Real gain.
Definition: dcl_zpk3.h:69
_DCL_CODE_ACCESS void DCL_setPIDfilterBW(DCL_PID *pid, float32_t fc)
Loads the derivative path filter shadow coefficients. Note: Sampling period pid->css->t_sec are used ...
Definition: dcl_pid.h:289
_DCL_CODE_ACCESS void DCL_updatePIDSPS(DCL_PID *pid)
Update SPS parameter with active param, userful when needing to update only few active param from SPS...
Definition: dcl_pid.h:269
float32_t Kp
Proportional gain.
Definition: dcl_pid.h:57
float complex z2
Complex zeros 2.
Definition: dcl_zpk3.h:64
float32_t Umax
Upper saturation limit.
Definition: dcl_pid.h:63
#define _DCL_CODE_SECTION
Defines dcl function section that users can specify in the linker file(.cmd) and to accelerate perfor...
Definition: dcl_common.h:60
#define DCL_clearPendingStatus(p)
Definition: dcl_css.h:129
float complex p2
Complex poles 2.
Definition: dcl_zpk3.h:67
Defines DCL_PID shadow parameter set used for updating controller parameter.
Definition: dcl_pid.h:56
#define DCL_setUpdateStatus(p)
Macros to set and clear the update-in-progress flag.
Definition: dcl_css.h:116
float32_t Umax
Upper saturation limit.
Definition: dcl_pid.h:82
DCL_PID object for storing PID specific parameters.
Definition: dcl_pid.h:74
#define DCL_runErrorHandler(ptr)
Prototype for basic error handler.
Definition: dcl_error.h:107
_DCL_CODE_ACCESS _DCL_CODE_SECTION bool DCL_pendingUpdatePID(DCL_PID *pid)
A conditional update based on the pending-for-update flag. If the pending status is set,...
Definition: dcl_pid.h:253
@ dcl_param_range_err
Parameter range exceeded.
Definition: dcl_error.h:58
float32_t Kd
Derivative gain.
Definition: dcl_pid.h:59
_DCL_CODE_ACCESS _DCL_CODE_SECTION float32_t DCL_runPIDParallel(DCL_PID *pid, float32_t rk, float32_t yk, float32_t lk)
Executes a parallel form PID controller.
Definition: dcl_pid.h:519
#define DCL_getUpdateStatus(p)
Determine whether a parameter update-in-progress flag is set.
Definition: dcl_css.h:123
float32_t d3
D path feedback value (c2)
Definition: dcl_pid.h:87
#define DCL_clearUpdateStatus(p)
Definition: dcl_css.h:117
float32_t c2
D path filter coefficient 2, default is 0.
Definition: dcl_pid.h:62
#define _DCL_CODE_ACCESS
Defines the scope of dcl functions (static inline/extern inline/none)
Definition: dcl_common.h:55
float complex p1
Complex poles 1.
Definition: dcl_zpk3.h:66
_DCL_CODE_ACCESS void DCL_resetPID(DCL_PID *pid)
Resets PID internal storage data with interrupt protection.
Definition: dcl_pid.h:158
float32_t Kp
Proportional gain.
Definition: dcl_pid.h:76
@ dcl_none
No error.
Definition: dcl_error.h:57
float32_t i14
I path saturation storage.
Definition: dcl_pid.h:89
uint32_t dcl_interrupt_t
Definition: dcl_common.h:96
_DCL_CODE_ACCESS float32_t DCL_getPIDfilterBW(DCL_PID *pid)
Calculates the active derivative path filter bandwidth in Hz. Note: Sampling period pid->css->t_sec a...
Definition: dcl_pid.h:343
float32_t Ki
Integral gain.
Definition: dcl_pid.h:77
_DCL_VOLATILE struct dcl_pid * PID_Handle
#define DCL_isZero(x)
Determines floating point numerical proximity to zero.
Definition: dcl_aux.h:77
float32_t Umin
Lower saturation limit.
Definition: dcl_pid.h:64
float32_t c2
D path filter coefficient 2, default is 0.
Definition: dcl_pid.h:81
float32_t Kr
Set point weight, default is 1.
Definition: dcl_pid.h:79
#define DCL_c2Limit
Defines the lower limit on derivative filter coefficient c2 in order for fc to lie below the Nyquist ...
Definition: dcl_aux.h:93
@ dcl_param_invalid_err
Parameter not valid.
Definition: dcl_error.h:59
_DCL_CODE_ACCESS void DCL_loadParallelPIDasZPK(DCL_PID *pid, DCL_ZPK3 *zpk)
Configures a parallel PID controller in ZPK form. Note: Sampling period pid->css->t_sec are used in t...
Definition: dcl_pid.h:425
#define DCL_runSat(data, Umax, Umin)
Macro to saturate a control variable but does not change the data itself unlike runClamp()
Definition: dcl_clamp.h:89
Defines the controller common support structure.
Definition: dcl_css.h:57
#define DCL_getPendingStatus(p)
Determine whether a parameter pending-for-update flag is set.
Definition: dcl_css.h:135
#define DCL_restoreInts(v)
Definition: dcl_common.h:95
float32_t i10
I path feedback value.
Definition: dcl_pid.h:88
Defines the DCL_ZPK3 controller structure.
Definition: dcl_zpk3.h:62
#define _DCL_VOLATILE
Defines volatile for DCL strctures Flags can be defined in dcl.h or user files before including DCL l...
Definition: dcl_common.h:68
DCL_CSS * css
configuration & debugging
Definition: dcl_pid.h:93
#define DCL_getErrorInfo(ptr)
Macro to store error info in CSS.
Definition: dcl_error.h:97
float32_t c1
D path filter coefficient 1, default is 1.
Definition: dcl_pid.h:61
float32_t Ki
Integral gain.
Definition: dcl_pid.h:58
#define DCL_setError(ptr, code)
Macro to set error code in CSS.
Definition: dcl_error.h:79
_DCL_CODE_ACCESS _DCL_CODE_SECTION float32_t DCL_runPIDSeries(DCL_PID *pid, float32_t rk, float32_t yk, float32_t lk)
Executes an ideal form PID controller.
Definition: dcl_pid.h:487
_DCL_CODE_ACCESS void DCL_loadSeriesPIDasZPK(DCL_PID *pid, DCL_ZPK3 *zpk)
Configures a series PID controller parameter in ZPK form. Note: Sampling period pid->css->t_sec are u...
Definition: dcl_pid.h:358
float float32_t
Defines single,double precision data type. Note: Assumes ABI to be TI_EABI, does not support legacy T...
Definition: dcl_common.h:51
float32_t d2
D path feedback value (Kd * c1)
Definition: dcl_pid.h:86
float32_t Kd
Derivative gain.
Definition: dcl_pid.h:78
float complex z1
Complex zeros 1.
Definition: dcl_zpk3.h:63
#define DCL_disableInts()
Define enable and disable interrupt operations.
Definition: dcl_common.h:94
float32_t Kr
Set point weight, default is 1.
Definition: dcl_pid.h:60