[51单片机] 马达PID控制函数问题

[复制链接]
 楼主| pmw_56 发表于 2018-4-14 16:28 | 显示全部楼层 |阅读模式
本帖最后由 pmw_56 于 2018-4-14 16:30 编辑

如下:

这是一个马达PID控制函数,这里的比例为什么是将误差除以比例,那样不是误差不是不能放大?有高手回答下吗?
// Proportional term
   Control_i = Controller_output_G + (Error / PID_PROPORTIONAL);

// PID parameters
#define PID_PROPORTIONAL (5)
#define PID_INTEGRAL     (50)
#define PID_DIFFERENTIAL (50)




void PID_MOTOR_Control_Motor(void)
{
   int Error;
   int Control_i;

   // Get the current speed value (0-255)
   Speed_measured_G = PID_MOTOR_Read_Current_Speed();

   // Get the desired speed value (0-255)
   Speed_required_G =
   PID_MOTOR_Get_Required_Speed();

   if (++Ticks == 100)
   {
      Speed_required_G = 200;
   }
   
   // Difference between required and actual speed (0-255)
   Error = Speed_required_G - Speed_measured_G;

   // Proportional term
   Control_i = Controller_output_G + (Error / PID_PROPORTIONAL);

   // Integral term [SET TO 0 IF NOT REQUIRED]
   if (PID_INTEGRAL)
   {
      Sum_G += Error;
      Control_i += (Sum_G / (1 + PID_INTEGRAL));
    }

   // Differential term [SET TO 0 IF NOT REQUIRED]
   if (PID_DIFFERENTIAL)
   {
      Control_i += (Error - Old_error_G) / (1 + PID_DIFFERENTIAL);

      // Store error value
      Old_error_G = Error;
    }

   // Adjust to 8-bit range
   if (Control_i > 255)
   {
      Control_i = 255;
      Sum_G -= Error;  // Windup protection
   }

   if (Control_i < 0)
   {
      Control_i = 0;
      Sum_G -= Error;  // Windup protection
   }

   // Convert to required 8-bit format
   Controller_output_G = (tByte) Control_i;

   // Update the PWM setting
   PID_MOTOR_Set_New_PWM_Output(Controller_output_G);

   // Update display
   PID_MOTOR_data_G[4] = CHAR_MAP_G[Speed_measured_G / 100];
   PID_MOTOR_data_G[5] = CHAR_MAP_G[(Speed_measured_G % 100) / 10];
   PID_MOTOR_data_G[6] = CHAR_MAP_G[Speed_measured_G % 10];

   PID_MOTOR_data_G[12] = CHAR_MAP_G[Speed_required_G / 100];
   PID_MOTOR_data_G[13] = CHAR_MAP_G[(Speed_required_G % 100) / 10];
   PID_MOTOR_data_G[14] = CHAR_MAP_G[Speed_required_G % 10];

   PID_MOTOR_data_G[20] = CHAR_MAP_G[Controller_output_G / 100];
   PID_MOTOR_data_G[21] = CHAR_MAP_G[(Controller_output_G % 100) / 10];
   PID_MOTOR_data_G[22] = CHAR_MAP_G[Controller_output_G % 10];

   PC_LINK_O_Write_String_To_Buffer(PID_MOTOR_data_G);
}




您需要登录后才可以回帖 登录 | 注册

本版积分规则

34

主题

215

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部

34

主题

215

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部