wpfcom2008
发表于 2008-11-17 15:02
楼主是辛苦了 但是内容太普通了
lzmyl
发表于 2008-11-19 17:12
那么附上一个PID的程序吧
这个程序只是一般常用pid算法的基本架构,没有包含输入输出处理部分。
=====================================================================================================*/
#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 {
doubleSetPoint; //设定目标 Desired Value
doubleProportion; //比例常数 Proportional Const
doubleIntegral; //积分常数 Integral Const
doubleDerivative; //微分常数 Derivative Const
doubleLastError; //Error[-1]
doublePrevError; //Error[-2]
doubleSumError; //Sums of Errors
} PID;
/*====================================================================================================
PID计算部分
=====================================================================================================*/
double PIDCalc( PID *pp, double NextPoint )
{
doubledError,
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
Im_JiHye
发表于 2008-12-22 08:55
十分的感谢楼主分享!
ilyntmy
发表于 2008-12-24 01:24
文件內容很實用...但在電路上到底要如何實現呢...
pi在單片機要如何處理呢
gohoot
发表于 2008-12-24 21:27
写的不错,谢谢
gohoot
发表于 2008-12-24 21:32
谢谢 分享,楼住辛苦了
lvlinbt
发表于 2009-1-3 12:13
很好!楼主辛苦了
emondo
发表于 2009-4-22 21:51
谢谢楼主的无私分享,学习喽
haohao0504
发表于 2009-5-5 17:18
谢谢楼主分享
xiaojun0618
发表于 2009-5-12 13:35
总结得不错,顶一个~
shun-0306
发表于 2009-5-26 08:53
要是能举一个具体的实例就好了
谢谢楼主
wpfcom2008
发表于 2009-7-5 20:36
还行 讲得不错呀
liangzaixl
发表于 2009-7-6 17:20
写得不错,受教了!
mesy
发表于 2009-7-6 18:15
呵呵,学习了!
yyql008
发表于 2010-1-9 08:43
不错,记号,研究研究
ah_thunder
发表于 2010-1-13 10:12
写得很一般,很常规的东西。。。。没有自己的见解。。。。
zxfzb828
发表于 2010-1-15 12:38
19楼的,您上面的公式没显示啊
zxfzb828
发表于 2010-1-23 17:21
留下脚印 谢谢分享
zhangrui_hunt
发表于 2010-1-29 22:11
长了不少知识,谢谢
wweihit
发表于 2010-4-16 10:40
你赖东东不错嘛