A PID Implementation Note for Beginners

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.
Reply to
Tim Wescott
Loading thread data ...

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)

Reply to
glu

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.