STM32的DSP库中PID的使用介绍

最近工程需要用到PID控制,正好STM32的DSP库有DIP函数,所以研究了下

先看数据参数:

typedef struct
{
    float32_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */
    float32_t A1; /**< The derived gain, A1 = -Kp - 2Kd. */
    float32_t A2; /**< The derived gain, A2 = Kd . */
    float32_t state[3]; /**< The state array of length 3. */
    float32_t Kp; /**< The proportional gain. */
    float32_t Ki; /**< The integral gain. */
    float32_t Kd; /**< The derivative gain. */
} arm_pid_instance_f32;

使用的时候只需要设置比例、积分、微分的比例因子即可。

/*PID库中的PID参数结构体 是float_32格式数据 */

arm_pid_instance_f32 PID;

/* 1、设置PID参数 */
PID.Kp = PID_PARAM_KP; /* Proporcional --比例参数 */
PID.Ki =  PID_PARAM_KI;         /* Integral         --积分参数*/
PID.Kd = PID_PARAM_KD; /* Derivative     --微分参数*/

/* 2、初始化PID的参数, */

arm_pid_init_f32(&PID, 1);

       void arm_pid_init_f32(arm_pid_instance_f32 * S, int32_t resetStateFlag)

      该函数是通过用户配置了Kp,Ki,Kd后,通过该函数获得A0,A1,A2。第二个参数是初始化标志位,设1即为初始化。

      

while (1) {
			/* 计算误差 */
			float pid_error = TEMP_CURRENT - TEMP_WANT;
			
			/* Calculate PID here, argument is error */
			/* Output data will be returned, we will use it as duty cycle parameter */
			duty = arm_pid_f32(&PID, pid_error);

 
 

       

猜你喜欢

转载自blog.csdn.net/zuoyioo7/article/details/80569547
今日推荐