![Logo](ti_logo.svg) |
AM263x Motor Control SDK
09.02.00
|
|
Go to the documentation of this file.
49 #include "../dcl_common.h"
53 #define DCL_DELTA_MIN 1.0e-04f
58 #define DCL_GAMMA_MAX 100
62 typedef struct dcl_nlpid_sps
84 #define NLPID_SPS_DEFAULTS { 1.0f, 0.0f, 0.0f, \
128 #define NLPID_DEFAULTS { 1.0f, 0.0f, 0.0f, \
134 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, \
135 &(DCL_NLPID_SPS)NLPID_SPS_DEFAULTS, &(DCL_CSS)DCL_CSS_DEFAULTS }
146 pid->d2 = pid->d3 = pid->i7 = 0.0f;
158 pid->Kp = pid->sps->Kp;
159 pid->Ki = pid->sps->Ki;
160 pid->Kd = pid->sps->Kd;
161 pid->alpha_p = pid->sps->alpha_p;
162 pid->alpha_i = pid->sps->alpha_i;
163 pid->alpha_d = pid->sps->alpha_d;
164 pid->delta_p = pid->sps->delta_p;
165 pid->delta_i = pid->sps->delta_i;
166 pid->delta_d = pid->sps->delta_d;
167 pid->gamma_p = pid->sps->gamma_p;
168 pid->gamma_i = pid->sps->gamma_i;
169 pid->gamma_d = pid->sps->gamma_d;
170 pid->c1 = pid->sps->c1;
171 pid->c2 = pid->sps->c2;
172 pid->Umax = pid->sps->Umax;
173 pid->Umin = pid->sps->Umin;
184 #ifdef DCL_ERROR_HANDLING_ENABLED
185 float32_t tau = (2.0f - pid->sps->c1 * pid->css->T) / (2.0f * pid->sps->c1);
186 float32_t ec2 = pid->sps->c1 * (pid->css->T - 2.0f * tau) / 2.0f;
205 pid->Kp = pid->sps->Kp;
206 pid->Ki = pid->sps->Ki;
207 pid->Kd = pid->sps->Kd;
208 pid->alpha_p = pid->sps->alpha_p;
209 pid->alpha_i = pid->sps->alpha_i;
210 pid->alpha_d = pid->sps->alpha_d;
211 pid->delta_p = pid->sps->delta_p;
212 pid->delta_i = pid->sps->delta_i;
213 pid->delta_d = pid->sps->delta_d;
214 pid->gamma_p = pid->sps->gamma_p;
215 pid->gamma_i = pid->sps->gamma_i;
216 pid->gamma_d = pid->sps->gamma_d;
217 pid->c1 = pid->sps->c1;
218 pid->c2 = pid->sps->c2;
219 pid->Umax = pid->sps->Umax;
220 pid->Umin = pid->sps->Umin;
255 #ifdef DCL_ERROR_HANDLING_ENABLED
266 pid->sps->c1 = 2.0f / (pid->css->T + 2.0f * tau);
267 pid->sps->c2 = (pid->css->T - 2.0f * tau) / (pid->css->T + 2.0f * tau);
283 #ifdef DCL_ERROR_HANDLING_ENABLED
294 tau = 1.0f / (2.0f *
CONST_PI * fc);
295 pid->c1 = 2.0f / (T + 2.0f * tau);
296 pid->c2 = (T - 2.0f * tau) / (T + 2.0f * tau);
307 float32_t tau = ((2.0f - pid->c1 * pid->css->T) / (2.0f * pid->c1));
308 return(1.0f / (2.0f *
CONST_PI * tau));
320 return((
float32_t) powf(delta, (alpha - 1.0f)));
332 return((
float32_t) powf(gamma, (1.0f / (alpha - 1.0f))));
348 #ifdef DCL_ERROR_HANDLING_ENABLED
350 err_code |= ((pid->sps->delta_p > 1.0f) || (pid->sps->delta_p > 1.0f) || (pid->sps->delta_p > 1.0f)) ?
dcl_param_range_err :
dcl_none;
363 pid->sps->gamma_p = xP;
364 pid->sps->gamma_i = xI;
365 pid->sps->gamma_d = xD;
380 #ifdef DCL_ERROR_HANDLING_ENABLED
411 float32_t v1, v2, v3, v4, v5, v8, v9, v10, v12, v13, v14, v15;
413 #ifdef DCL_ERROR_HANDLING_ENABLED
426 v1 = (rk - yk) * 0.5f;
427 v2 = (v1 < 0.0f) ? -1.0f : 1.0f;
430 #ifdef DCL_ERROR_HANDLING_ENABLED
444 v4 = ((v3 > pid->delta_p) ? (v2 * (
float32_t) powf(v3, pid->alpha_p)) : (v1 * pid->gamma_p));
445 v5 = ((v3 > pid->delta_i) ? (v2 * (
float32_t) powf(v3, pid->alpha_i)) : (v1 * pid->gamma_i));
446 v9 = ((v3 > pid->delta_d) ? (v2 * (
float32_t) powf(v3, pid->alpha_d)) : (v1 * pid->gamma_d));
449 v8 = (v5 * pid->Kp * pid->Ki * pid->i16) + pid->i7;
453 v10 = v9 * pid->Kd * pid->c1;
454 v12 = v10 - pid->d2 - pid->d3;
456 pid->d3 = v12 * pid->c2;
459 v13 = (pid->Kp * (v4 + v12)) + v8;
461 v15 = (v14 == v13) ? 1.0f : 0.0f;
464 #ifdef DCL_TESTPOINTS_ENABLED
468 #ifdef DCL_ERROR_HANDLING_ENABLED
486 float32_t v1, v2, vd2, v3, vd3, v4, v5, v6, v8, v9, v12, v15, v16, v17;
488 #ifdef DCL_ERROR_HANDLING_ENABLED
501 v1 = (rk - yk) * 0.5f;
502 v2 = (v1 < 0.0f) ? -1.0f : 1.0f;
505 #ifdef DCL_ERROR_HANDLING_ENABLED
518 v4 = ((v3 > pid->delta_p) ? (v2 * (
float32_t) powf(v3, pid->alpha_p)) : (v1 * pid->gamma_p));
519 v5 = ((v3 > pid->delta_i) ? (v2 * (
float32_t) powf(v3, pid->alpha_i)) : (v1 * pid->gamma_i));
522 vd2 = (yk < 0.0f) ? -1.0f : 1.0f;
525 #ifdef DCL_ERROR_HANDLING_ENABLED
536 v6 = ((vd3 > pid->delta_d) ? (vd2 * (
float32_t) powf(vd3, pid->alpha_d)) : (yk * pid->gamma_d));
539 v8 = (v5 * pid->Kp * pid->Ki * pid->i16) + pid->i7;
543 v15 = v6 * pid->Kd * pid->c1;
544 v16 = v15 - pid->d2 - pid->d3;
546 pid->d3 = v16 * pid->c2;
549 v9 = (pid->Kp * (v4 - v16)) + v8;
551 v12 = (v17 == v9) ? 1.0f : 0.0f;
554 #ifdef DCL_TESTPOINTS_ENABLED
558 #ifdef DCL_ERROR_HANDLING_ENABLED
577 float32_t v2 = (x < 0.0f) ? -1.0f : 1.0f;
580 return((v3 > delta) ? (v2 * (
float32_t) powf(v3, alpha)) : (x * powf(delta, (alpha - 1.0f))));
589 #endif // _DCL_NLPID_H_
_DCL_CRIT_ACCESS float32_t DCL_runNLF(float32_t x, float32_t alpha, float32_t delta)
Executes a basic non-linear control function.
Definition: dcl_nlpid.h:575
float32_t Umin
Lower saturation limit.
Definition: dcl_nlpid.h:79
float32_t delta_i
I path linearized range, default is 0.1.
Definition: dcl_nlpid.h:71
float32_t delta_d
D path linearized range, default is 0.1.
Definition: dcl_nlpid.h:104
float32_t alpha_i
I path non-linear exponent, default is 1.
Definition: dcl_nlpid.h:68
float32_t Ki
Linear integral gain.
Definition: dcl_nlpid.h:65
float32_t delta_p
P path linearized range, default is 0.1.
Definition: dcl_nlpid.h:102
#define CONST_PI
Local definitions of the mathematical constant pi.
Definition: dcl_macro.h:55
float32_t Kp
Linear proportional gain.
Definition: dcl_nlpid.h:64
_DCL_CODE_ACCESS bool DCL_updateNLPID(DCL_NLPID *pid)
A conditional update based on the update flag. If the update status is set, the function will update ...
Definition: dcl_nlpid.h:233
_DCL_CODE_ACCESS void DCL_resetNLPID(DCL_NLPID *pid)
Resets NLPID internal storage data with interrupt protection.
Definition: dcl_nlpid.h:142
Defines the shadow DCL_NLPID controller structure.
Definition: dcl_nlpid.h:63
_DCL_CODE_ACCESS void DCL_setActiveNLPIDgamma(DCL_NLPID *pid)
Computes the linearized gains for each path and loads the parameters in the active NLPID structure.
Definition: dcl_nlpid.h:374
_DCL_CODE_ACCESS void DCL_updateNLPIDNoCheck(DCL_NLPID *pid)
Loads PID tuning parameter from its SPS parameter with interrupt protection.
Definition: dcl_nlpid.h:181
@ dcl_none
No error.
Definition: dcl_error.h:57
float32_t delta_p
P path linearized range, default is 0.1.
Definition: dcl_nlpid.h:70
float32_t Umax
Upper saturation limit.
Definition: dcl_nlpid.h:78
_DCL_CODE_ACCESS float32_t DCL_getNLPIDfilterBW(DCL_NLPID *pid)
Returns the derivative LP filter bandwidth in Hz.
Definition: dcl_nlpid.h:305
_DCL_CODE_ACCESS void DCL_setActiveNLPIDfilterBW(DCL_NLPID *pid, float32_t fc, float32_t T)
Loads the NLPID derivative path filter active coefficients.
Definition: dcl_nlpid.h:279
#define DCL_runErrorHandler(ptr)
Prototype for basic error handler.
Definition: dcl_error.h:108
#define DCL_getUpdateStatus(p)
Determine whether a parameter update-in-progress flag is set.
Definition: dcl_css.h:122
#define DCL_GAMMA_MAX
Sets an upper bound on allowable controller gain, and therefore fixes the minimum linear region semi-...
Definition: dcl_nlpid.h:58
float32_t gamma_d
D path gain limit, default is 1.
Definition: dcl_nlpid.h:107
_DCL_CRIT_ACCESS float32_t DCL_runNLPIDParallel(DCL_NLPID *pid, float32_t rk, float32_t yk, float32_t lk)
Executes a parallel form non-linear PID controller.
Definition: dcl_nlpid.h:409
#define DCL_clearUpdateStatus(p)
Definition: dcl_css.h:116
Defines the active DCL_NLPID controller structure.
Definition: dcl_nlpid.h:94
#define _DCL_CODE_ACCESS
Defines the scope of dcl functions.
Definition: dcl_common.h:63
float32_t alpha_i
I path non-linear exponent, default is 1.
Definition: dcl_nlpid.h:100
float32_t delta_i
I path linearized range, default is 0.1.
Definition: dcl_nlpid.h:103
float32_t gamma_p
P path gain limit, default is 1.
Definition: dcl_nlpid.h:73
float32_t c2
D path low-pass filter coefficient 2, default is 0.
Definition: dcl_nlpid.h:77
@ dcl_controller_err
Controller operation not completed.
Definition: dcl_error.h:64
_DCL_CODE_ACCESS void DCL_setNLPIDfilterBW(DCL_NLPID *pid, float32_t fc)
Loads the shadow derivative LP filter coefficients.
Definition: dcl_nlpid.h:251
float32_t Kd
Linear derivative gain.
Definition: dcl_nlpid.h:98
float32_t Kp
Linear proportional gain.
Definition: dcl_nlpid.h:96
DCL_CSS * css
Pointer to controller support structure.
Definition: dcl_nlpid.h:123
float32_t gamma_i
I path gain limit, default is 1.
Definition: dcl_nlpid.h:74
float32_t Umax
Upper saturation limit.
Definition: dcl_nlpid.h:110
uint32_t dcl_interrupt_t
Definition: dcl_common.h:107
_DCL_CRIT_ACCESS float32_t DCL_runNLPIDSeries(DCL_NLPID *pid, float32_t rk, float32_t yk, float32_t lk)
Executes a series form non-linear PID controller.
Definition: dcl_nlpid.h:484
float32_t Umin
Lower saturation limit.
Definition: dcl_nlpid.h:111
float32_t alpha_d
D path non-linear exponent, default is 1.
Definition: dcl_nlpid.h:69
_DCL_CODE_ACCESS void DCL_setNLPIDgamma(DCL_NLPID *pid)
Computes the linearized gains for each path Note: active coefficients not update DCL_updateNLPID() ca...
Definition: dcl_nlpid.h:341
float32_t c1
D path low-pass filter coefficient 1, default is 1.
Definition: dcl_nlpid.h:108
#define DCL_getControllerStatus(p)
Determine whether a controller operation-in-progress flag is set.
Definition: dcl_css.h:136
float32_t Kd
Linear derivative gain.
Definition: dcl_nlpid.h:66
@ dcl_param_range_err
Parameter range exceeded.
Definition: dcl_error.h:58
float32_t alpha_d
D path non-linear exponent, default is 1.
Definition: dcl_nlpid.h:101
#define DCL_DELTA_MIN
Sets the lower bound on the linear region semi-width.
Definition: dcl_nlpid.h:53
float32_t i18
No longer needed.
Definition: dcl_nlpid.h:119
_DCL_CODE_ACCESS float32_t DCL_getNLPIDgamma(float32_t alpha, float32_t delta)
Returns the linearized region gain for specified (alpha,delta)
Definition: dcl_nlpid.h:318
float32_t Ki
Linear integral gain.
Definition: dcl_nlpid.h:97
float32_t alpha_p
P path non-linear exponent, default is 1.
Definition: dcl_nlpid.h:67
float32_t d2
D path low-pass filter storage (Kd * c1)
Definition: dcl_nlpid.h:114
#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
DCL_NLPID_SPS * sps
Pointer to shadow parameter structure.
Definition: dcl_nlpid.h:122
#define DCL_FPU32_TOL
Define the acceptable FPU numerical tolerances.
Definition: dcl_macro.h:62
float32_t c1
D path low-pass filter coefficient 1, default is 1.
Definition: dcl_nlpid.h:76
Defines the controller common support structure.
Definition: dcl_css.h:57
@ dcl_input_range_err
Input range exceeded.
Definition: dcl_error.h:61
float32_t d3
D path low-pass filter storage (c2)
Definition: dcl_nlpid.h:115
float32_t delta_d
D path linearized range, default is 0.1.
Definition: dcl_nlpid.h:72
#define DCL_restoreInts(v)
Definition: dcl_common.h:106
float32_t alpha_p
P path non-linear exponent, default is 1.
Definition: dcl_nlpid.h:99
@ dcl_param_invalid_err
Parameter not valid.
Definition: dcl_error.h:59
#define _DCL_VOLATILE
Defines volatile for DCL strctures.
Definition: dcl_common.h:79
#define DCL_setControllerStatus(p)
Macros placed at the beginning and end of the controller so that other functions know a control opera...
Definition: dcl_css.h:129
float32_t i16
Saturation multiplier, ranges between 1*lk ~ 0, where 0 means fully saturated.
Definition: dcl_nlpid.h:117
float32_t c2
D path low-pass filter coefficient 2, default is 0.
Definition: dcl_nlpid.h:109
_DCL_VOLATILE struct dcl_nlpid DCL_NLPID
#define DCL_clearControllerStatus(p)
Definition: dcl_css.h:130
float32_t gamma_i
I path gain limit, default is 1.
Definition: dcl_nlpid.h:106
float32_t gamma_p
P path gain limit, default is 1.
Definition: dcl_nlpid.h:105
#define DCL_getErrorInfo(ptr)
Macro to store error info in CSS.
Definition: dcl_error.h:98
#define DCL_setError(ptr, code)
Macro to set error code in CSS.
Definition: dcl_error.h:80
#define _DCL_CRIT_ACCESS
Defines the scope of critical dcl functions.
Definition: dcl_common.h:70
_DCL_CODE_ACCESS float32_t DCL_getNLPIDdelta(float32_t alpha, float32_t gamma)
Returns the semi-width of the linear gain region for specified (alpha,gamma)
Definition: dcl_nlpid.h:330
float float32_t
Definition: dcl_common.h:58
float32_t i7
I path feedback storage.
Definition: dcl_nlpid.h:116
float32_t gamma_d
D path gain limit, default is 1.
Definition: dcl_nlpid.h:75
_DCL_CODE_ACCESS void DCL_forceUpdateNLPID(DCL_NLPID *pid)
Loads NLPID tuning parameter from its SPS parameter without interrupt protection.
Definition: dcl_nlpid.h:156
#define DCL_disableInts()
Define enable and disable interrupt operations.
Definition: dcl_common.h:105