打印
[MM32生态]

PID 算法C 语言

[复制链接]
234|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jimmhu|  楼主 | 2024-7-31 11:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式


typedef struct PID{intSetPoint; //设定目标 DesiredValuelongSumError; //误差累计doubleProportion; //比例常数Proportional ConstdoubleIntegral; //积分常数 IntegralConstdoubleDerivative; //微分常数Derivative ConstintLastError; //Error[-1]intPrevError; //Error[-2]} PID;static PID sPID;static PID *sptr = &sPID;/*====================================================================InitializePID Structure PID 参数初始化===================================================================*/void IncPIDInit(void){sptr->SumError= 0;sptr->LastError= 0; //Error[-1]sptr->PrevError= 0; //Error[-2]sptr->Proportion= 0; //比例常数Proportional Constsptr->Integral= 0; //积分常数IntegralConstsptr->Derivative= 0; //微分常数Derivative Constsptr->SetPoint= 0;}/*==================================================================== 增量式PID 计算部分====================================================================*/int IncPIDCalc(int NextPoint){registerint iError, iIncpid; //当前误差iError= sptr->SetPoint - NextPoint; //增量计算iIncpid= sptr->Proportion * iError //E[k]项        -sptr->Integral * sptr->LastError //E[k-1]项         +sptr->Derivative * sptr->PrevError; //E[k-2]项//存储误差,用于下次计算sptr->PrevError= sptr->LastError;sptr->LastError= iError;//返回增量值return(iIncpid);}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

16

主题

3461

帖子

4

粉丝