首页 上一页 1 2 3 下一页 尾页

标准PID源程序:) 点击:10120 | 回复:49



gongkongedit

    
  • 精华:1099帖
  • 求助:0帖
  • 帖子:14392帖 | 54470回
  • 年度积分:0
  • 历史总积分:622
  • 注册:2008年9月08日
发表于:2004-02-24 12:57:00
楼主
标准的PID处理例程 --- 工业控制中常用算法 --- /*==================================================================================================== 这是从网上找来的一个比较典型的PID处理程序,在使用单片机作为控制cpu时,请稍作简化,具体的PID 参数必须由具体对象通过实验确定。由于单片机的处理速度和ram资源的限制,一般不采用浮点数运算, 而将所有参数全部用整数,运算到最后再除以一个2的N次方数据(相当于移位),作类似定点数运算,可 大大提高运算速度,根据控制精度的不同要求,当精度要求很高时,注意保留移位引起的“余数”,做好余 数补偿。这个程序只是一般常用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 { 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计算部分 =====================================================================================================*/ 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 } }



实验箱

  • 精华:0帖
  • 求助:0帖
  • 帖子:3帖 | 349回
  • 年度积分:0
  • 历史总积分:458
  • 注册:2005年10月28日
发表于:2006-01-15 13:54:00
41楼
hao  好

沙漠的风雨

  • 精华:0帖
  • 求助:0帖
  • 帖子:24帖 | 461回
  • 年度积分:0
  • 历史总积分:1069
  • 注册:2003年10月23日
发表于:2006-01-17 09:28:00
42楼
真的很好!支持!

120110

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 2回
  • 年度积分:0
  • 历史总积分:2
  • 注册:2006年2月24日
发表于:2006-02-24 13:41:00
43楼
大哥 有pid的温度控制的c语言编程么  资料也行 我找了好久  他和普通的c语言编程一样么  用调用一些库函数么 我的email:sunshengquan110@126.com  谢谢 !!!!!!!!

120110

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 2回
  • 年度积分:0
  • 历史总积分:2
  • 注册:2006年2月24日
发表于:2006-02-25 09:53:00
44楼

canfly

  • 精华:0帖
  • 求助:0帖
  • 帖子:12帖 | 195回
  • 年度积分:0
  • 历史总积分:321
  • 注册:2005年5月12日
发表于:2006-04-01 09:28:00
45楼
谢谢了

hymin

  • 精华:0帖
  • 求助:0帖
  • 帖子:2帖 | 39回
  • 年度积分:0
  • 历史总积分:97
  • 注册:2006年5月22日
发表于:2006-05-24 12:16:00
46楼
很好,学习!

DEWAYTANG

  • 精华:1帖
  • 求助:0帖
  • 帖子:10帖 | 136回
  • 年度积分:0
  • 历史总积分:178
  • 注册:2004年11月16日
发表于:2006-05-24 12:42:00
47楼
我得好好学习!

落尘丶

  • 精华:0帖
  • 求助:0帖
  • 帖子:0帖 | 128回
  • 年度积分:28
  • 历史总积分:242
  • 注册:2020年9月01日
发表于:2023-02-14 11:18:16
48楼

感谢楼主的经验分享

zyuanlong11

  • 精华:0帖
  • 求助:0帖
  • 帖子:1帖 | 211回
  • 年度积分:6
  • 历史总积分:379
  • 注册:2010年11月10日
发表于:2023-11-20 13:25:10
49楼

很好,支持


热门招聘
相关主题

官方公众号

智造工程师
    首页 上一页 1 2 3 下一页 尾页