View Single Post
  #12   Report Post  
Posted to rec.crafts.metalworking
RogerN RogerN is offline
external usenet poster
 
Posts: 1,475
Default PID calculations

"Tim Wescott" wrote in message
...

On Mon, 22 Sep 2014 21:23:51 -0500, RogerN wrote:

One way would be to have an array of error[xx] and take the difference
in change over a period of time involving several of times through the
loop.


That's a BAD way to do it. It's what's known in the more esoteric corners
of the trade as a non-minimum phase filter, which basically means that the
filter has more delay than necessary for the amount of amplitude shaping
vs. frequency. Delay is a Bad Thing in a control loop, and is to be
avoided.


I don't necessarily agree that it's a bad way because you can look up how
much time since the last change, for example using slow 100ms loop times and
a 1 degree change in temperature, at the instant of the change, rate was 1
degree per 100ms, this would trigger a strong response, next loop, one deg
per 200ms, next would be 1 degree in 300ms... and so on, decaying every loop
until further change. I think this would be similar to difference in
average error. I like the average error calculation you showed me because
it does (nearly?) the same thing without the array of previous error data.

I know a way to do this but I'm just looking for better ideas, perhaps
more efficient memory usage.


You want a band-limited derivative term. The best way to do this is
pretty simple, too (calculate this as one hunk-of-code each sample time):

derivative = (current_error - average_error);

average_error = average_error + k * (current_error - average_error);

Here "derivative" is the answer you want, "average_error" is a number that
you carry from sample to sample (a so-called "state", like your integrator
state), and k is a gain from 0 to 1 that determines the dynamics of the
differentiator. The bigger k is the faster the derivative action, so the
more noise it passes through and the more it helps fast settling. The
smaller k, the less noise, and the less helpful the derivative action is
when you're trying for high speeds.

If you need to mess with band-limited derivative terms then you really
should be doing frequency-domain design at least, but you can sometimes
make things work with seat of the pants tuning. As a rule of thumb, set k
to (10) * (sampling interval) / (settling time), where you know the
sampling interval and, the settling time is what you're trying to
achieve. If you end up computing a k greater than 1, then you need to re-
think your sampling interval or your desired settling time.

The link on my website to the article you want to read is currently
broken: send me an email and I'll reply with a pdf.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com


Thanks Tim, I figured you'd have a better way of doing what I'm wanting to
do. There is a huge relative speed difference in applications, for example
changing a room temperature at 1 degree per minute is fast but a motor
moving at 1 encoder count per minute would be very slow for a 500 line
encoder. The calculations I have seen before is amount of changer per time
period and what I thought would be more useful is amount of time per change,
or low rates of change.

Interesting demonstration on YouTube:
Raffaello D'Andrea_ The astounding athletic power of quadcopters

Thanks!

RogerN