sum_error in pid controller [closed]

asked 2015-12-07 19:15:30 -0500 gravatar image

updated 2015-12-07 19:16:21 -0500

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:

  1. 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,
  2. 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 sum_error=0, and after the phase 1, the sum_error 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 sum_error to zero or bound it? Can anyone tell me how to handle the sum_error in typical?

Any comment will be much appreciated!!

Kevin Kuei

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant. Please see for more details. by gvdhoorn
close date 2015-12-08 02:48:10.754629


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 or a similar site. I'll close this now. If you feel this does belong here, please clarify.

gvdhoorn gravatar image gvdhoorn  ( 2015-12-08 02:38:33 -0500 )edit