DCL PID Controller Functions
Module: Digital Control Library (DCL)
Structures
Name |
|
|---|---|
struct |
DCL_PID_SPS |
Types
Name |
|
|---|---|
typedef _DCL_VOLATILE struct |
Functions
Name |
|
|---|---|
_DCL_CODE_ACCESS void |
DCL_resetPID(DCL_PID * pid) |
_DCL_CODE_ACCESS void |
DCL_forceUpdatePID(DCL_PID * pid) |
_DCL_CODE_ACCESS void |
DCL_updatePIDNoCheck(DCL_PID * pid) |
_DCL_CODE_ACCESS bool |
DCL_updatePID(DCL_PID * pid) |
_DCL_CODE_ACCESS void |
DCL_setPIDfilterBW(DCL_PID * pid, float32_t fc) |
_DCL_CODE_ACCESS void |
DCL_setActivePIDfilterBW(DCL_PID * pid, float32_t fc, float32_t T) |
DCL_getPIDfilterBW(DCL_PID * pid) |
|
_DCL_CODE_ACCESS void |
DCL_loadSeriesPIDasZPK(DCL_PID * pid, DCL_ZPK3 * zpk) |
_DCL_CODE_ACCESS void |
DCL_loadParallelPIDasZPK(DCL_PID * pid, DCL_ZPK3 * zpk) |
DCL_runPIDSeries(DCL_PID * pid, float32_t rk, float32_t yk, float32_t lk) |
|
DCL_runPIDParallel(DCL_PID * pid, float32_t rk, float32_t yk, float32_t lk) |
Defines
Name |
|
|---|---|
PID_SPS_DEFAULTS |
|
PID_DEFAULTS |
|
PID_INT_DEFAULTS |
|
DCL_initPID() |
|
DCL_initPIDasParam(kp, ki, kd, kr, _c1, _c2, umax, umin) |
|
DCL_initPIDasSPS(pid_ptr, sps_ptr) |
Detailed Description
Contains 32-bit PID controller with its related structures and functions
Types Documentation
typedef DCL_PID
typedef _DCL_VOLATILE struct DCL_PID;
DCL_PID object for storing PID specific parameters.
Functions Documentation
function DCL_resetPID
_DCL_CODE_ACCESS void DCL_resetPID(
DCL_PID * pid
)
Resets PID internal storage data with interrupt protection.
Parameters:
pid Pointer to the DCL_PID structure
function DCL_forceUpdatePID
_DCL_CODE_ACCESS void DCL_forceUpdatePID(
DCL_PID * pid
)
Loads PID tuning parameter from its SPS parameter without interrupt protection.
Parameters:
pid Pointer to the active DCL_PID controller structure
function DCL_updatePIDNoCheck
_DCL_CODE_ACCESS void DCL_updatePIDNoCheck(
DCL_PID * pid
)
Loads PID tuning parameter from its SPS parameter with interrupt protection.
Parameters:
pid Pointer to the active DCL_PID controller structure
function DCL_updatePID
_DCL_CODE_ACCESS bool DCL_updatePID(
DCL_PID * pid
)
A conditional update based on the update flag. If the update status is set, the function will update PID parameter from its SPS parameter and clear the status flag on completion.
Parameters:
pid Pointer to the DCL_PID controller structure
Return: ‘true’ if an update is applied, otherwise ‘false’
Note: Note: Use DCL_setUpdateStatus(pid) to set the update status.
function DCL_setPIDfilterBW
_DCL_CODE_ACCESS void DCL_setPIDfilterBW(
DCL_PID * pid,
float32_t fc
)
Loads the derivative path filter shadow coefficients.
Parameters:
pid Pointer to the DCL_PID structure
fc The desired filter bandwidth in Hz
Note: Note: Sampling period pid->css->T are used in the calculation. New coefficients take effect when DCL_updatePID() is called.
function DCL_setActivePIDfilterBW
_DCL_CODE_ACCESS void DCL_setActivePIDfilterBW(
DCL_PID * pid,
float32_t fc,
float32_t T
)
Loads the PID derivative path filter active coefficients.
Parameters:
pid Pointer to the DCL_PID structure
fc The desired filter bandwidth in Hz
T The controller update rate in seconds
Note: Note: Sampling period pid->css->T are used in the calculation. New coefficients take effect immediately. SPS & CSS contents are unaffected.
function DCL_getPIDfilterBW
_DCL_CODE_ACCESSfloat32_t DCL_getPIDfilterBW(
DCL_PID * pid
)
Calculates the active derivative path filter bandwidth in Hz.
Parameters:
pid Pointer to the DCL_PID structure
Return: The filter bandwidth in Hz
Note: Note: Sampling period pid->css->T are used in the calculation.
function DCL_loadSeriesPIDasZPK
_DCL_CODE_ACCESS void DCL_loadSeriesPIDasZPK(
DCL_PID * pid,
DCL_ZPK3 * zpk
)
Configures a series PID controller parameter in ZPK form.
Parameters:
Note: Note: Sampling period pid->css->T are used in the calculation. Parameters take effect after call to DCL_updatePID(). Only z1, z2 & p2 considered, p1 = 0 assumed.
function DCL_loadParallelPIDasZPK
_DCL_CODE_ACCESS void DCL_loadParallelPIDasZPK(
DCL_PID * pid,
DCL_ZPK3 * zpk
)
Configures a parallel PID controller in ZPK form.
Parameters:
Note: Note: Sampling period pid->css->T are used in the calculation. Parameters take effect after call to DCL_updatePID(). Only z1, z2 & p2 considered, p1 = 0 assumed.
function DCL_runPIDSeries
_DCL_CRIT_ACCESSfloat32_t DCL_runPIDSeries(
DCL_PID * pid,
float32_t rk,
float32_t yk,
float32_t lk
)
Executes an ideal form PID controller.
Parameters:
pid Pointer to the DCL_PID structure
rk The controller set-point reference
yk The measured feedback value
lk External output clamp flag
Return: The control effort
function DCL_runPIDParallel
_DCL_CRIT_ACCESSfloat32_t DCL_runPIDParallel(
DCL_PID * pid,
float32_t rk,
float32_t yk,
float32_t lk
)
Executes a parallel form PID controller.
Parameters:
pid Pointer to the DCL_PID structure
rk The controller set-point reference
yk The measured feedback value
lk External output clamp flag
Return: The control effort
Macros Documentation
define PID_SPS_DEFAULTS
#define PID_SPS_DEFAULTS {1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f}
Defines default values to initialize DCL_PID_SPS.
define PID_DEFAULTS
#define PID_DEFAULTS {1.0f, \
0.0f, \
0.0f, \
1.0f, \
1.0f, \
0.0f, \
1.0f, \
-1.0f, \
0.0f, \
0.0f, \
0.0f, \
1.0f, \
&(DCL_PID_SPS)PID_SPS_DEFAULTS, \
&(DCL_CSS)DCL_CSS_DEFAULTS}
Defines default values to initialize the DCL_PID structure.
define PID_INT_DEFAULTS
#define PID_INT_DEFAULTS .d2 = 0.0f, .d3 = 0.0f, .i10 = 0.0f, .i14 = 1.0f, .sps = &(DCL_PID_SPS)PID_SPS_DEFAULTS, \
.css = &(DCL_CSS)DCL_CSS_DEFAULTS
Macro for internal default values to initialize DCL_PID Example: DCL_PID pid_ctrl = { .Kp = 1.0f, .Ki = 0.0f, … .Umin = -1.0f, PID_INT_DEFAULTS };.
define DCL_initPID
#define DCL_initPID(
)
&(DCL_PID)PID_DEFAULTS
Initialize DCL_PID struct with default parameters Example: DCL_PID* pid_ctrl = DCL_initPID();.
Return: A DCL_PID* pointer
define DCL_initPIDasParam
#define DCL_initPIDasParam(
kp,
ki,
kd,
kr,
_c1,
_c2,
umax,
umin
)
&(DCL_PID) \
{ \
.Kp = kp, .Ki = ki, .Kd = kd, .Kr = kr, .c1 = _c1, .c2 = _c2, .Umax = umax, .Umin = umin, PID_INT_DEFAULTS \
}
Initialize DCL_PID struct with input controller parameters Example: DCL_PID* pid_ctrl = DCL_initPIDasParam(1.0f,0.0f,0.0f,1.0f,1.0f,0.0f,1.0f,-1.0f);.
Return: A DCL_PID* pointer
Note: Note: input parameter needs to be in the same order as listed in PID_SPS struct
define DCL_initPIDasSPS
#define DCL_initPIDasSPS(
pid_ptr,
sps_ptr
)
({ \
DCL_PID *new_pid = (pid_ptr) ? pid_ptr : DCL_initPID(); \
DCL_PID_SPS *new_sps = (sps_ptr) ? sps_ptr : &(DCL_PID_SPS)PID_SPS_DEFAULTS; \
if (sps_ptr) \
{ \
*new_pid = (DCL_PID){(new_sps)->Kp, \
(new_sps)->Ki, \
(new_sps)->Kd, \
(new_sps)->Kr, \
(new_sps)->c1, \
(new_sps)->c2, \
(new_sps)->Umax, \
(new_sps)->Umin, \
0.0f, \
0.0f, \
0.0f, \
1.0f, \
(DCL_PID_SPS *)new_sps, \
&(DCL_CSS)DCL_CSS_DEFAULTS}; \
} \
new_pid; \
})
Initialize DCL_PID struct with SPS parameters Example: DCL_PID_SPS pid_sps = { .Kp = , .Ki = , …}; //initial parameter DCL_PID pid_ctrl; DCL_initPIasSPS(&pid_ctrl,&pid_sps);.
Parameters:
pid_ptr DCL_PID* pointer that needs to be initialized
sps_ptr DCL_PID_SPS* pointer with assigned parameters
Return: Returns DCL_PID* with set sps parameters, default parameter will be used if sps_ptr is not specified
Note: Note: The newly declared DCL_PID structure will use the SPS input parameter as its attribute for sps.