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 http://www.embedded.com/2000/0010/0010feat3.htm . 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.
--
http://www.wescottdesign.com

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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)

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.