DCL Direct Form 2 2nd Order Functions
Module: Digital Control Library (DCL)
Structures
Name |
|
|---|---|
struct |
DCL_DF22_SPS |
Types
Name |
|
|---|---|
typedef _DCL_VOLATILE struct |
DCL_DF22 |
Functions
Name |
|
|---|---|
_DCL_CODE_ACCESS void |
DCL_resetDF22(DCL_DF22 * df) |
_DCL_CODE_ACCESS void |
DCL_forceUpdateDF22(DCL_DF22 * df) |
_DCL_CODE_ACCESS void |
DCL_updateDF22NoCheck(DCL_DF22 * df) |
_DCL_CODE_ACCESS bool |
DCL_updateDF22(DCL_DF22 * df) |
_DCL_CODE_ACCESS bool |
DCL_isStableDF22(DCL_DF22 * df) |
_DCL_CODE_ACCESS void |
DCL_loadDF22asZPK(DCL_DF22 * df, DCL_ZPK3 * zpk) |
_DCL_CODE_ACCESS void |
DCL_loadDF22asZwn(DCL_DF22 * df, float32_t z, float32_t wn) |
_DCL_CODE_ACCESS void |
DCL_loadDF22asSeriesPID(DCL_DF22 * df, float32_t Kp, float32_t Ki, float32_t Kd, float32_t fc) |
_DCL_CODE_ACCESS void |
DCL_loadDF22asParallelPID(DCL_DF22 * df, float32_t Kp, float32_t Ki, float32_t Kd, float32_t fc) |
DCL_runDF22(DCL_DF22 * df, float32_t ek) |
|
DCL_runDF22PartialCompute(DCL_DF22 * df, float32_t ek) |
|
_DCL_CRIT_ACCESS void |
DCL_runDF22PartialUpdate(DCL_DF22 * df, float32_t ek, float32_t uk) |
DCL_runDF22Clamp(DCL_DF22 * df, float32_t ek, float32_t Umax, float32_t Umin) |
Defines
Name |
|
|---|---|
DF22_SPS_DEFAULTS |
|
DF22_DEFAULTS |
|
DF22_INT_DEFAULTS |
|
DCL_initDF22() |
|
DCL_initDF22asParam(_b0, _b1, _b2, _a1, _a2) |
|
DCL_initDF22asSPS(df_ptr, sps_ptr) |
Detailed Description
Contains direct form 2 2nd order DF22 compensator with its related structures and functions
Types Documentation
typedef DCL_DF22
typedef _DCL_VOLATILE struct DCL_DF22;
DCL_DF22 object for storing df22 specific parameters.
Functions Documentation
function DCL_resetDF22
_DCL_CODE_ACCESS void DCL_resetDF22(
DCL_DF22 * df
)
Resets DF22 internal storage data with interrupt protection.
Parameters:
df Pointer to the DCL_DF22 controller structure
function DCL_forceUpdateDF22
_DCL_CODE_ACCESS void DCL_forceUpdateDF22(
DCL_DF22 * df
)
Loads DF22 tuning parameter from its SPS parameter without interrupt protection.
Parameters:
df Pointer to the active DCL_DF22 controller structure
function DCL_updateDF22NoCheck
_DCL_CODE_ACCESS void DCL_updateDF22NoCheck(
DCL_DF22 * df
)
Loads DF22 tuning parameter from its SPS parameter with interrupt protection.
Parameters:
df Pointer to the DCL_DF22 controller structure
function DCL_updateDF22
_DCL_CODE_ACCESS bool DCL_updateDF22(
DCL_DF22 * df
)
A conditional update based on the update flag. If the update status is set, the function will update DF22 parameter from its SPS parameter and clear the status flag on completion.
Parameters:
df Pointer to the DCL_DF22 controller structure
Return: ‘true’ if an update is applied, otherwise ‘false’
Note: Note: Use DCL_setUpdateStatus(df) to set the update status.
function DCL_isStableDF22
_DCL_CODE_ACCESS bool DCL_isStableDF22(
DCL_DF22 * df
)
Determines stability of the shadow compensator.
Parameters:
df Pointer to the DCL_DF22 controller structure
Return: ‘true’ if both poles have magnitude less than 1, ‘false’ otherwise
function DCL_loadDF22asZPK
_DCL_CODE_ACCESS void DCL_loadDF22asZPK(
DCL_DF22 * df,
DCL_ZPK3 * zpk
)
Loads the DF22 shadow coefficients from a ZPK3 description.
Parameters:
Note: Note: Sampling period df->css->T are used in the calculation. New settings take effect after DCL_updateDF22(). Only z1, z2, p1 & p2 are considered, z3 & p3 are ignored.
function DCL_loadDF22asZwn
_DCL_CODE_ACCESS void DCL_loadDF22asZwn(
DCL_DF22 * df,
float32_t z,
float32_t wn
)
Loads the DF22 shadow coefficients from damping ratio and un-damped natural frequency using sample rate in CSS.
Parameters:
df Pointer to the DCL_DF22 controller structure
z The damping ratio
wn The un-damped natural frequency in rad/s
Note: Note: Sampling period df->css->T are used in the calculation. New settings take effect after DCL_updateDF22().
function DCL_loadDF22asSeriesPID
_DCL_CODE_ACCESS void DCL_loadDF22asSeriesPID(
DCL_DF22 * df,
float32_t Kp,
float32_t Ki,
float32_t Kd,
float32_t fc
)
Loads the shadow DF22 compensator coefficients to emulate a series form PID.
Parameters:
df Pointer to the DCL_DF22 controller structure
Kp Proportional gain
Ki Integral gain
Kd Derivative gain
fc Derivative path filter bandwidth in Hz
Note: Note: Sampling period df->css->T are used in the calculation. New settings take effect after DCL_updateDF22().
function DCL_loadDF22asParallelPID
_DCL_CODE_ACCESS void DCL_loadDF22asParallelPID(
DCL_DF22 * df,
float32_t Kp,
float32_t Ki,
float32_t Kd,
float32_t fc
)
Loads the shadow DF22 compensator coefficients to emulate a parallel form PID.
Parameters:
df Pointer to the DCL_DF22 controller structure
Kp Proportional gain
Ki Integral gain
Kd Derivative gain
fc Derivative path filter bandwidth in Hz
Note: Note: Sampling period df->css->T are used in the calculation. New settings take effect after DCL_updateDF22().
function DCL_runDF22
_DCL_CRIT_ACCESSfloat32_t DCL_runDF22(
DCL_DF22 * df,
float32_t ek
)
Executes a 2nd order Direct Form 2 controller.
Parameters:
df Pointer to the DCL_DF22 controller structure
ek The servo error
Return: The control effort
function DCL_runDF22PartialCompute
_DCL_CRIT_ACCESSfloat32_t DCL_runDF22PartialCompute(
DCL_DF22 * df,
float32_t ek
)
Immediate computation to obtain DF22 servo error without updating the controller.
Parameters:
df Pointer to the DCL_DF22 controller structure
ek The servo error
Return: The control effort
function DCL_runDF22PartialUpdate
_DCL_CRIT_ACCESS void DCL_runDF22PartialUpdate(
DCL_DF22 * df,
float32_t ek,
float32_t uk
)
Update DF22 controller based on pre-computed control effort.
Parameters:
df Pointer to the DCL_DF22 controller structure
ek The servo error
uk The controller output in the previous sample interval
function DCL_runDF22Clamp
_DCL_CRIT_ACCESSfloat32_t DCL_runDF22Clamp(
DCL_DF22 * df,
float32_t ek,
float32_t Umax,
float32_t Umin
)
Executes a 2nd order Direct Form 2 controller with clamp.
Parameters:
df Pointer to the DCL_DF22 controller structure
ek The servo error
Umax Upper saturation limit
Umin Lower saturation limit
Return: The control effort
Macros Documentation
define DF22_SPS_DEFAULTS
#define DF22_SPS_DEFAULTS {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}
Defaults for DCL_DF22_SPS.
define DF22_DEFAULTS
#define DF22_DEFAULTS {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, &(DCL_DF22_SPS)DF22_SPS_DEFAULTS, &(DCL_CSS)DCL_CSS_DEFAULTS}
Defines default values to initialize DCL_DF22.
define DF22_INT_DEFAULTS
#define DF22_INT_DEFAULTS .x1 = 0.0f, .x2 = 0.0f, .sps = &(DCL_DF22_SPS)DF22_SPS_DEFAULTS, .css = &(DCL_CSS)DCL_CSS_DEFAULTS
Macro for internal default values to initialize DCL_DF22 Example: DCL_DF22 df22_ctrl = { .b0 = 1.00f, .b1 = 0.0f, … .a2 = 0.0f, DF22_INT_DEFAULTS };.
define DCL_initDF22
#define DCL_initDF22(
)
&(DCL_DF22)DF22_DEFAULTS
Initialize DCL_DF22 struct with default parameters Example: DCL_DF22* df22_ctrl = DCL_initDF22();.
Return: A DCL_DF22* pointer
define DCL_initDF22asParam
#define DCL_initDF22asParam(
_b0,
_b1,
_b2,
_a1,
_a2
)
&(DCL_DF22) \
{ \
.b0 = _b0, .b1 = _b1, .b2 = _b2, .a1 = _a1, .a2 = _a2, .a3 = _a3, DF22_INT_DEFAULTS \
}
Initialize DCL_DF22 struct with input compensator parameters Example: DCL_DF22 DF22_ctrl = DCL_initD22asParam(1.0f,0.0f,0.0f,0.0f,0.0f);.
Return: A DCL_DF22* pointer
Note: Note: input parameter needs to be in the same order as listed in DF22_SPS struct.
define DCL_initDF22asSPS
#define DCL_initDF22asSPS(
df_ptr,
sps_ptr
)
({ \
DCL_DF22 *new_df = (df_ptr) ? df_ptr : DCL_initDF22(); \
DCL_DF22_SPS *new_sps = (sps_ptr) ? sps_ptr : &(DCL_DF22_SPS)DF22_SPS_DEFAULTS; \
if (sps_ptr) \
{ \
*new_df = (DCL_DF22){(new_sps)->b0, (new_sps)->b1, (new_sps)->b2, \
(new_sps)->a1, (new_sps)->a2, 0.0f, \
0.0f, (DCL_DF22_SPS *)new_sps, &(DCL_CSS)DCL_CSS_DEFAULTS}; \
} \
new_df; \
})
Initialize DCL_DF22 struct using sps parameters Example: DCL_DF22_SPS df_sps = { .b0 = , .b1 = , …}; //initial parameter DCL_DF22 df_ctrl; DCL_initDF22asSPS(&df_ctrl,&df_sps);.
Parameters:
df_ptr DCL_DF22* pointer that needs to be initialized
sps_ptr DCL_DF22_SPS* pointer with assigned parameters
Return: Returns DCL_DF22* with set sps parameters, default parameter will be used if sps_ptr is not specified