马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <Windows.h>
#include<stdio.h>
typedef struct{
float kp,ki,kd;
float ek,ek1,ek2; //ek1 是 ek 的前一次误差
float eSUM;
float out;
}PID;
PID pid = {10.0,10.0,0.0,0.0,0.0,0.0,0.0,0,0};
float PID_Loc(float SetValue, float ActualValue, PID *pid){
pid->ek = SetValue - ActualValue;
pid->eSUM += pid->ek;
pid->out = (pid->kp * pid->ek)
+ (pid->ki * pid->eSUM)
+ (pid->kd *( pid->ek1 - pid->ek));
pid->ek1 = pid->ek;
return pid->out;
}
int main()
{
int i, j;
PID t ;
int T=100;
for(i=0; i<5; i++){
for(j=4; j>0; j--){
printf ("%d\n",i);
printf ("%d\n",j);
PID_Loc(i, j , &t);
printf ("%d\n",t.out);
Sleep(T);//延时ms
}
}
}
如上代码所示 为什么这个pid out的值恒不变,讲道理应该会变得啊 |