View Single Post
  #21   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 Tue, 23 Sep 2014 20:22:38 -0500, RogerN wrote:

"Tim Wescott" wrote in message
...

snip

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.


Well, if what you want to do is find a fascinating array of subtle and not-
so-subtle pitfalls, then by all means give it a whirl.


I didn't like my idea because of the memory usage and processing of the
array on every loop, but I don't think it would necessarily be bad due to
responsiveness because you can respond strongly to the results of the last
loop, I like your way with the average error much better though, less
processing and less memory usage.

But here's some reasoning that I feel is valid, though it wouldn't
necessarily demand a large array. Lets say the application was a room
temperature control and the maximum rate of change was no more than 1 degree
per minute. So if it used the change for the last minute or so, it could
give the strongest response needed for the rate of change, any faster rates
of change would just be from noisy readings.

Another weird thought I had was using the reading array data to calculate
mean and standard deviation to have weak response to ~ +/- 3 sigma and
stronger response to readings representing real change. If I used something
like that in a R/C helicopter gyroscope, the noise level could also be an
indication of out of balance blades, vibration levels that would be more
harmful the the model and the controls. Of course not responding to noise
would also reduce battery drain and wear on the servos.

snip

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.


I forgot to mention that if you're really going to sample at 1kHz and
close a loop with a settling time of a minute, then your 'k' value is
going to be damned small -- like on the order of 1/6000.

This, in turn, means that you are exposed to your "average_error" term not
having enough precision to keep track of changes. If your current_error
is good to 12 bits, then your current_error * k must be good to 25 bits or
so. That's barely within the ability of a single-precision floating point
number to keep track. Even if you're only measuring temperatures with 8-
bit ADCs, you're beyond the ability to keep track with 16-bit integers.

With modern processors, at a 1kHz sampling rate, you can take care of this
by using double-precision floating point numbers (with something like a 53-
bit mantissa). If you're using an older processor, using 32-bit numbers
and playing lots of scaling games will work.

Speaking of subtle pitfalls.

--

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


What got me thinking about this was Allen Bradley's PID control, I believe
the motion control cards close the loop in the card itself, but the PID in
the processor uses an I time and a D time instead of Ki and Kd. On a
temperature controller or other slower systems, measurements would be more
like a little change over a longer period of time instead of quite a bit of
change in a short period of time.

I'm hoping to use the info in some temperature control applications as well
as some R/C model stabilization applications. I bought some 3 axis gyro + 3
axis accelerometer modules from HobbyPartz for a reasonable price. I had
the Arduino reading the data but I haven't done anything interesting with it
yet. Thought I might start out by trying to get my boe-bot to operate on 2
wheels.

Thanks,

RogerN