S.Tarafdar
12-30-03, 04:51 AM
Hello everyone,
Do anyone of you have an idea about PID algorithm?It is basically like this:
output(i)=Kp*error(i)+Ki*delT*(summation from 1 to i)error(i)+Kd/delT*(e(i)-e(i-1))
This is what I wrote:
#include<iostream>
using namespace std;
int main(){
float error,Paction,Daction,Iaction,lastError,delT;
float Kp,Ki,Kd,setPoint;
float measurement=0,output=0;
int i;
cout<<"Enter the value of Kp,Ki,Kd,delT:";
cin>>Kp>>Ki>>Kd>>delT;
cout<<"Enter the Value of Set Point:";
cin>>setPoint;
Iaction=0;
lastError=0;
for(i=0;i<4;i++){
error=setPoint-measurement;
Paction=error*Kp;
Iaction+=Ki*delT*error;
Daction=Kd*(error-lastError)/delT;
output=Paction+Iaction+Daction;
lastError=error;
measurement=output;
}
cout<<"Output:"<<output<<endl;
return 0;
}
I am confused.Is it ok?
Thanks
Do anyone of you have an idea about PID algorithm?It is basically like this:
output(i)=Kp*error(i)+Ki*delT*(summation from 1 to i)error(i)+Kd/delT*(e(i)-e(i-1))
This is what I wrote:
#include<iostream>
using namespace std;
int main(){
float error,Paction,Daction,Iaction,lastError,delT;
float Kp,Ki,Kd,setPoint;
float measurement=0,output=0;
int i;
cout<<"Enter the value of Kp,Ki,Kd,delT:";
cin>>Kp>>Ki>>Kd>>delT;
cout<<"Enter the Value of Set Point:";
cin>>setPoint;
Iaction=0;
lastError=0;
for(i=0;i<4;i++){
error=setPoint-measurement;
Paction=error*Kp;
Iaction+=Ki*delT*error;
Daction=Kd*(error-lastError)/delT;
output=Paction+Iaction+Daction;
lastError=error;
measurement=output;
}
cout<<"Output:"<<output<<endl;
return 0;
}
I am confused.Is it ok?
Thanks