A PID Implementation Note for Beginners

Feb 18, 2009 1 Replies

After I get asked a question a certain number of times, a buffer overflows and I have to write something up...



When you're writing PID code, and you have something in your code like:



drive = updatePID(feedback, command);



you do _not_* have to follow this with:



real_drive = real_drive + drive;



What that line implements is an integrator, and you should already have one in your PID controller (see, for example, the treatment of iState in Listing 1 of

formatting link
Note the "+=" operator.).


-- whew. Now I have something I can link to in replies --


  • Or at least almost never. There are times when it's sensible to follow a PID loop with an integrator -- but you should only do it when you know what you're doing: if you need to be told, you don't know what you're doing yet.

or you could if you have something like the following in your updatePID function:

delta_u = Kp * (e(i) - e(i-1)) + Ki * e(i)

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required