Searching \ for '[OT] PID source code' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/motors.htm?key=PID
Search entire site for: 'PID source code'.

Exact match. Not showing close matches.
PICList Thread
'[OT] PID source code'
2006\04\28@150642 by William Couture

face picon face
I'm hoping someone can shed some light on code I'm doing for work.

We make temperature controllers, and I'm doing the code for a new
board.

However, our "standard" PID code looks like nothing I've ever seen
before.

I've googled for PID code, and haven't found anything that looks like
our algorithm.  And, of course, I can't let someone else see our
"trade secret" code.

The comments say that it's a "textbook PID algorithm" with "rate
and reset in seconds".  But it never says which textbook, and the
original programmer (1994) is long gone...

Can anyone point me to PID source code so that I could figure out
what is going on?  Anything that looks like the standard:
  error = value - set_value;
  p = kp * error;
  i += ki * error;
  d = kd * (error - last_error);
  pid = p + i + d;
need not apply.

Thanks,
  Bill

--
Psst...  Hey, you... Buddy...  Want a kitten?  straycatblues.petfinder.org

2006\04\28@165304 by Gerhard Fiedler

picon face
William Couture wrote:

> However, our "standard" PID code looks like nothing I've ever seen
> before.

> Can anyone point me to PID source code so that I could figure out
> what is going on?  Anything that looks like the standard:
>    error = value - set_value;
>    p = kp * error;
>    i += ki * error;
>    d = kd * (error - last_error);
>    pid = p + i + d;
> need not apply.

In the end, if it's a PID algorithm, it will look like the standard, in one
way or the other. So whatever anybody could send you will look like this,
possibly with additional features and implementation differences, but
essentially like this. So if you say that anything that looks like this
need not apply, I'd guess you won't get anything :)

Seriously, maybe you can get some more specific about what is different --
of course without violating that you can't publish your code.

Sometimes, the integral part has some added features to disable or reset it
for big movements. It may not make much sense to start integrating when
you're so far away from the setpoint that on max speed it'll take half an
hour to get there.

Sometimes the differential part calculation (a simple difference of a
difference in your code above) needs a bit more sophistication to filter
out noise.

Sometimes there's a loop within a loop; say in a DC motor servo controller
you can use the motor speed to control the position, and the duty cycle to
control the speed. This may result in faster and more precise control or
easier or more robust adjustment of the controller parameters, even if it's
in the end only the duty cycle you wiggle, just as if you had only a single
loop.

Sometimes the time intervals for the different time-related calculations
(integral, differential, loop frequency) are different.

Gerhard


'[OT] PID source code'
2006\05\02@050446 by Simon.Nield
flavicon
face
>    error = value - set_value;
>    p = kp * error;
>    i += ki * error;
>    d = kd * (error - last_error);
>    pid = p + i + d;

a couple of (other) common tweaks:

the derivative term is sometimes generated from the input, rather than the
error. useful if the error term is likely to be noisy, as taking a
derivative (= highpass filter) will tend to increase noise.

the integral term can be limited to an absolute maximum, in order to
combat 'integrator wind-up'; a phenomenon which would otherwise cause big
overshoots in slow moving systems. lots of other inventive solutions may
be used to acheive the same result.

some stuff to remember / realise:
the phase (sign) of the constants may be either positive or negative,
depending on how the signal is generated.
the comments will probably not match the code, they will just give you
some hint about what the original programmer was thinking about at the
time.
the integral & derivative terms may not be calculated prior to summing,
but may be inputs to your system (i.e. externally 'calculated')
if the code does not in some way add a proportional term, and integral
term and a derivative term, then it is not a PID controller.
any changes you make to the 'PID' code, will mean the calibration for the
system will change. you may even need to change the calibration procedure.

a couple of documents I have found useful in the past (first link on each
search):
www.google.com/search?q=pid+without+a+phd
http://www.google.com/search?q=motion+control+tutorial+newport

hth,
simon

2006\05\02@075056 by Alan B. Pearce

face picon face
>if the code does not in some way add a proportional
>term, and integral term and a derivative term, then
>it is not a PID controller.

There is always the possibility that the code as it stands now is not PID,
even though the original intention when the original coder started out was
to have PID, but then found it unsuitable, and never changed the comments.

2006\05\02@090832 by Michael Rigby-Jones

picon face


{Quote hidden}

There are several variants on the classic PID, the above is the "parallel" algorithm.  There is also a "series" and the "Ideal"

http://www.expertune.com/artCE87.html should help you decide which one you have!

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

More... (looser matching)
- Last day of these posts
- In 2006 , 2007 only
- Today
- New search...