智能车制作

标题: MC9S12XS128芯片利用实现速度控制PID算法 [打印本页]

作者: tomsjack    时间: 2010-4-8 21:59
标题: MC9S12XS128芯片利用实现速度控制PID算法
菜鸟恳求骨灰赐教~
作者: 锦芫    时间: 2010-4-19 20:23
新手一起学习
作者: zczc003    时间: 2010-4-23 20:58
me  too
作者: QQMElch    时间: 2010-5-3 21:11
me  too
作者: feiooyer    时间: 2010-5-3 22:50
我这有个程序,但不是很懂,拿来供大家参考一下:
#include <string.h>
#include <stdio.h>
/*====================================================================================================
PID Function
The PID (比例、积分、微分) function is used in mainly
control applications. PIDCalc performs one iteration of the PID
algorithm.
While the PID function works, main is just a dummy program showing
a typical usage.
=====================================================================================================*/
typedef struct PID
{
double SetPoint; // 设定目标 Desired Value
double Proportion; // 比例常数 Proportional Const
double Integral; // 积分常数 Integral Const
double Derivative; // 微分常数 Derivative Const
double LastError; // Error[-1]
double PrevError; // Error[-2]
double SumError; // Sums of Errors
} PID;         定义了一个PID结构体
/*====================================================================================================
PID计算部分
=====================================================================================================*/
double PIDCalc( PID *pp, double NextPoint )
{
double dError,
Error;
Error = pp->SetPoint - NextPoint; // 偏差
pp->SumError += Error; // 积分
dError = pp->LastError - pp->PrevError; // 当前微分
pp->PrevError = pp->LastError;
pp->LastError = Error;
return (pp->Proportion * Error // 比例项
+ pp->Integral * pp->SumError // 积分项
+ pp->Derivative * dError // 微分项
}      链表不是很懂
/*====================================================================================================
Initialize PID Structure
=====================================================================================================*/
void PIDInit (PID *pp)
{
memset ( pp,0,sizeof(PID));
}
/*====================================================================================================
Main Program
=====================================================================================================*/
double sensor (void) // Dummy Sensor Function
{
return 100.0;
}
void actuator(double rDelta) // Dummy Actuator Function
{}
void main(void)
{
PID sPID; // PID Control Structure
double rOut; // PID Response (Output)
double rIn; // PID Feedback (Input)
PIDInit ( &sPID ); // Initialize Structure
sPID.Proportion = 0.5; // Set PID Coefficients
sPID.Integral = 0.5;
sPID.Derivative = 0.0;
sPID.SetPoint = 100.0; // Set PID Setpoint
  for (;;)  // Mock Up of PID Processing
{
rIn = sensor (); // Read Input
rOut = PIDCalc ( &sPID,rIn ); // Perform PID Interation
actuator ( rOut ); // Effect Needed Changes
}
}
作者: tanglin2007    时间: 2010-7-14 16:27

作者: GuySunYang    时间: 2010-12-13 10:55
得先看PID推导公式,自己和书本上的介绍一步一步导出后,再看程序就很简单了
作者: zhonghua0402    时间: 2010-12-31 11:12
学习学习!
作者: tsacy    时间: 2011-3-16 00:25





欢迎光临 智能车制作 (http://111.231.132.190/) Powered by Discuz! X3.2