工控安全c语言源代码,分享一个PID的C程序代码-专业自动化论坛-中国工控网论坛...

发表于:2005-12-15 10:50:00

楼主

***************************************************************************\

PID Function

This program has been written by the Technical Support Staff at Z-World in

response to several customer requests.  As such, it has NOT had the testing and

validation procedures which our "standard" software products have.  It is being

made available as a sample.  There is no warranty, implied or otherwise.

The PID (Proportional Integral Derivative) 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;

/*=========================================================================*\

Perform One PID Iteration

\*=========================================================================*/

double PIDCalc ( PID    *pp,   double NextPoint )

{  double    dError, Error;

pp->SumError += (Error = pp->SetPoint - NextPoint);

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 )

{&

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值