|
#include
#include
struct _pid()
{
float SetWater; //定义设定值
float Water;
float incrementWater;
float result; //定义实际值
float err; //定义偏差值
float err_next; //定义上一个偏差值
float err_last; //定义最上前的偏差值
float Kp,Ki,Kd; //定义比例、积分、微分系数 }pid;
void PID_init()
{
pid.SetWater=0.0;
pid.result=0.0;
pid.err=0.0;
pid.err_last=0.0;
pid.err_next=0.0;
pid.Kp=0.2;
pid.Ki=0.015;
pid.Kd=0.2;
}
}
float PID_realize(Water)
{
pid.SetWater=Water;
pid.err=pid.SetWater-pid.result;
incrementWater=pid.Kp*(pid.err-pid.err_next)+pid.Ki*pid.err+pid.Kd*(pid.err-2*pid.err_next+pid.err_last);
pid.err_last=pid.err_next;
pid.err_next=pid.err;
return incrementWater;
}
compiling pid.c...
PID.C(3): error C141: syntax error near ')'
PID.C(24): error C141: syntax error near '}'
pid.c - 2 Error(s), 0 Warning(s).
怎么改啊,刚学不太懂
|
|