Source code for PID

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I am looking a good origin for PID C source code.
It would be nice if it also includes software which will help tuning the PID
loop.
I may also consider self tuning algorithm.

I consider to include it in our RTU (remote terminal unit)

Thanks,
Martin Roth
Motorola Israel




Re: Source code for PID
Quoted text here. Click to load it

It's really not that hard - if you understand what PID is.

There are some wrinkes (e.g. look into integral wind-up, parallel/serial
PID, etc) and think carefully about the range/precision (and where
necessary, limiting) of your variables. Also consider your input filtering
very carefully - input noise will translate into D-term activity...

Steve
http://www.fivetrees.com



Re: Source code for PID

Quoted text here. Click to load it

There was an article in Embedded Systems Programming magazine a while back
entitled "PID without a PHD" which is probably Google-able.


Bob


Re: Source code for PID

Quoted text here. Click to load it
http://www.wescottdesign.com/articles/pidwophd.html

--

Tim Wescott
Wescott Design Services
We've slightly trimmed the long signature. Click to see the full one.
Re: Source code for PID



Quoted text here. Click to load it

A good book on the PID theory and practice:

"Advances in PID Control"
TK Jiong, W. Quing-Guo, HC Chieh and TJ HE4%gglund

As for the PID implementation in C, it is very trivial and20%
straightforward. It is just a few lines of code once you know how to do i=
t.

Vladimir Vassilevsky

DSP and Mixed Signal Design Consultant

http://www.abvolt.com


Re: Source code for PID
Quoted text here. Click to load it

Yes Very Trivial.  When I first wrote one > wade through may Math filled
articles.  Followed by many with fully optimized poorly commented code.
Then I found a few comments on implementation.
And learned how easy it was. The Moral: Easy when you know how.
Then there is tuning..................

Re: Source code for PID
Quoted text here. Click to load it

There's a very complete article in the new Embedded Systems magazine. I
just got it today, and it's at work, so I don't have any more info than
that. It covered speed control of a DC motor, including simulation and
tuning.

GS

Re: Source code for PID

Quoted text here. Click to load it

Article:
http://www.embedded.com/shared/printableArticle.jhtml?articleID17%5801127

Code:
ftp://ftp.embedded.com/pub/2006/01rosales/PIcontrollerESD.asm

Jon

Re: Source code for PID
Hi, Martin,

Quoted text here. Click to load it

Are you SURE you really want a PID controller?  There are many
other control technologies (bang-bang, SPC, etc.) -- each has
characteristics suitd to different types of control problems.

And, even if you *think* you want a PID controller, are you sure
ou need all three terms (i.e. P and PI controllers are far more
commonplace).

You'll also need to learn the basics about PID controllers if
you ever expect to deploy anything non-trivial.  I.e., tuning
can be a real chore.  And, there are many ways the controller
can "fail" (to perform adequately) if not designed well
(e.g., bumpless transfer, anti-windup, etc.)

Do yourself -- and your project -- a favor and research control
theory before trying to *apply* that theory...  :-/

HTH,
--don

Quoted text here. Click to load it

Re: Source code for PID

Quoted text here. Click to load it

I respectfully disagree, sorta.

I disagree because I have seen or heard about a great number of
successful control loops that are closed by people without much control
theory background, or that are closed by people who took the classes but
don't use the knowledge.  When they work it's because the performance
that's required from the loop is well below the performance that the
hardware is capable of, in which case a casual PID tuning will suffice.

I only sort of disagree because if you don't have the control theory (or
if you don't use it) then you won't really know if your solution is
correct until after you've built your product and tested it.  Since
well-behaved control loops often depend on the hardware that they're
built of as much as they depend on the control rules in software this
can be a bad time for such discoveries.

At any rate there is some code for implementing PID controllers in
http://www.wescottdesign.com/articles/pidwophd.html .  There are also a
few guidelines for choosing sampling rates and data path depths in there.

--

Tim Wescott
Wescott Design Services
We've slightly trimmed the long signature. Click to see the full one.
Re: Source code for PID
Quoted text here. Click to load it

It's easy to get a loop running well "near steady-state".
And, with any sort of an "I" term, the error term *will* be
driven to "0".

Quoted text here. Click to load it

The problem lies in how you handle the *dynamics* of the loop.
Classic PID theory is, in my experience, *rarely* implemented
directly in software -- because it has too many inherent flaws;
too many "missing features" which can be fixed in a software
implementation (e.g., how/when to reset the integrator, how/when
to disable the "D" term, etc.).  Poorly designed control loops
fail when the controlled process is NOT behaving well -- or,
when setpoint changes are made.  And, poorly *tuned* loops
often make the controlled process respond poorly (severely
overdamped responses are common -- because the tuning has
been done on the "safe" side; or, underdamped responses if
tuned to casually).

You can drive a car without knowing how it works.  You can
even drive a HIGH PERFORMANCE car without knowing how it works!
But, the car's driver is the equivalent of the *tuned*
control loop's USER -- not the mechanic/engineer that
*designed* the car!  On the race course (or highway) is a
really BAD time to find out that the engine mounts can't
handle the torque of a jackrabbit start...

--don

Re: Source code for PID
Hi, Martin,

[apologies  to cae if this is a duplicate post...:<]

Martin Roth wrote:
Quoted text here. Click to load it

Are you SURE you really want a PID controller?  There are many
other control technologies (bang-bang, SPC, etc.) -- each has
characteristics suitd to different types of control problems.

And, even if you *think* you want a PID controller, are you sure
ou need all three terms (i.e. P and PI controllers are far more
commonplace).

You'll also need to learn the basics about PID controllers if
you ever expect to deploy anything non-trivial.  I.e., tuning
can be a real chore.  And, there are many ways the controller
can "fail" (to perform adequately) if not designed well
(e.g., bumpless transfer, anti-windup, etc.)

Do yourself -- and your project -- a favor and research control
theory before trying to *apply* that theory...  :-/

HTH,
--don

Quoted text here. Click to load it

Site Timeline