sum_error in pid controller
Hi all,
I'm trying to implement a PID controller by myself and I've a question about the sum_error in I control. Here is a short code based on the PID theory.
void pid()
{
error = target - current;
pTerm = Kp * error;
sum_error = sum_error + error * deltaT ;
iTerm = Ki * sum_error;
dTerm = Kd * (error - last_error) / deltaT;
last_error = error;
Term = K*(pTerm + iTerm + dTerm);
}
Now, I start my commands:
- Phase 1, If at t=0, I set target=1.0, and the controller begins to drive motor to go to the target=1.0,
- Phase 2, and then, at t=N, I set target=2.0, and the controller begins to drive motor to go to the target=2.0
My question is, in the beginning of phase 1, the error=1.0, the sumerror=0, and after the phase 1, the sumerror is not zero anymore, it's positive. And in the beginning of phase 2, the error=1.0 (it is also the same with above), but the sum_error is positive. So, the iTerm at t=N is much greater than iTerm at t=0.
It means, the curves between phase 2 and phase 1 are different!!!
But to end-user, the command 1, and the command 2 is almost the same, and it should drive the same effort.
Should I set the sumerror to zero or bound it? Can anyone tell me how to handle the sumerror in typical?
Any comment will be much appreciated!!
Kevin Kuei
Asked by kevin.kuei.0321@gmail.com on 2015-12-07 20:15:30 UTC
Comments
We try to keep this site on-topic as much as possible, and this seems not specific to ROS.You probably want to ask this over at robotics.stackexchange.com or a similar site. I'll close this now. If you feel this does belong here, please clarify.
Asked by gvdhoorn on 2015-12-08 03:38:33 UTC