/* ==================================================================================
File name: PID_REG3.H (IQ version)
=====================================================================================*/
#ifndef __PIDREG3_H__
#define __PIDREG3_H__
typedef struct { _iq Ref; // Input: Reference input
_iq Fdb; // Input: Feedback input
_iq Err; // Variable: Error
_iq Kp; // Parameter: Proportional gain
_iq Up; // Variable: Proportional output
_iq Ui; // Variable: Integral output
_iq Ud; // Variable: Derivative output
_iq OutPreSat; // Variable: Pre-saturated output
_iq OutMax; // Parameter: Maximum output
_iq OutMin; // Parameter: Minimum output
_iq Out; // Output: PID output
_iq SatErr; // Variable: Saturated difference
_iq Ki; // Parameter: Integral gain
_iq Kc; // Parameter: Integral correction gain
_iq Kd; // Parameter: Derivative gain
_iq Up1; // History: Previous proportional output
} PIDREG3;
typedef PIDREG3 *PIDREG3_handle;
/*-----------------------------------------------------------------------------
Default initalizer for the PIDREG3 object.
-----------------------------------------------------------------------------*/
#define PIDREG3_DEFAULTS { 0, \
0, \
0, \
_IQ(1.3), \
0, \
0, \
0, \
0, \
_IQ(1), \
_IQ(-1), \
0, \
0, \
_IQ(0.02), \
_IQ(0.5), \
_IQ(1.05), \
0, \
}
/*------------------------------------------------------------------------------
PID Macro Definition
------------------------------------------------------------------------------*/
#define PID_REG3_MACRO(v) \
v.Err = v.Ref - v.Fdb; /* Compute the error */ \
v.Up= _IQmpy(v.Kp,v.Err); /* Compute the proportional output */ \
v.Ui= v.Ui + _IQmpy(v.Ki,v.Up) + _IQmpy(v.Kc,v.SatErr); /* Compute the integral output */ \
v.OutPreSat= v.Up + v.Ui; /* Compute the pre-saturated output */ \
v.Out = _IQsat(v.OutPreSat, v.OutMax, v.OutMin); /* Saturate the output */ \
v.SatErr = v.Out - v.OutPreSat; /* Compute the saturate difference */ \
v.Up1 = v.Up; /* Update the previous proportional output */
#define PID_REG3_POS_MACRO(v) \
v.Err = v.Ref - v.Fdb; /* Compute the error */ \
if (v.Err >= _IQ(0.5)) \
v.Err -= _IQ(1.0); /* roll in the error */ \
else if (v.Err <= _IQ(-0.5)) \
v.Err += _IQ(1.0); /* roll in the error */ \
v.Up= _IQmpy(v.Kp,v.Err); /* Compute the proportional output */ \
v.Ui= v.Ui + _IQmpy(v.Ki,v.Up) + _IQmpy(v.Kc,v.SatErr); /* Compute the integral output */ \
v.Ud = _IQmpy(v.Kd,(v.Up - v.Up1)); \
v.OutPreSat= v.Up + v.Ui + v.Ud; /* Compute the pre-saturated output */ \
v.Out = _IQsat(v.OutPreSat, v.OutMax, v.OutMin); /* Saturate the output */ \
v.SatErr = v.Out - v.OutPreSat; /* Compute the saturate difference */ \
v.Up1 = v.Up;
#endif // __PIDREG3_H__
// Add the lines below if derivative output is needed following the integral update
位置在ti\controlSUITE\libs\app_libs\motor_control\math_blocks\v4.3/
在给出的文档中似乎没有对这个的说明(看大家用的这个,也打算用这个。把Kd设为0就是PI了吧)
1、Kc,积分校正增益,没明白是什么作用
2、这个是增量式PID吗?
3、SatErr,饱和差,好像是v->SatErr = v->Out - v->OutPreSat;,但不知道什么用
4、v.Ui= v.Ui + _IQmpy(v.Ki,v.Up) + _IQmpy(v.Kc,v.SatErr);也即是// Compute the integral output
v->Ui = v->Ui +v->Ki*v->Up + v->Kc*v->SatErr;其中的v->Kc*v->SatErr;怎么理解啊,为什么加上v->Ki*v->Up + v->Kc*v->SatErr,加上当前误差乘以Ki不就可以了吗?
5、// Compute the derivative output
v->Ud = v->Kd*(v->Up - v->Up1);计算微分的时候为什么用的是比例输出。
6、_iq换成了float32, _IQ(1.3)换成1.3也可以吧。想换成浮点型的。
谢谢




