Cruising Sailors Forum Archive

Input damping.
In Response To: PID controllers ()

On our industrial control systems we run into noisy analog inputs all the time. The noise can come from either actual fluctuations in the physical value such as pressure or from electrical noise in the signal cables. This works better than an fixed number of average reads.

Here is an excerpt from the instructions I give to our PLC programmers to filter the raw analog inputs.

How to apply analog input damping to all inputs with a special case for in-dryer board moisture.

headingraw = actual signal from the analog input

' apply damping to input
headingdamped = headingdamped + ((headingraw - headingdamped) / damptime * scantime)

damptime refers to the set damping time constant for the heading. This is the amount of time for the damped value to reach 63% of a step change For example, a sudden 10° heading change would be damped to 6.3 ° after 1 second, 8.7 ° after 2 seconds, etc. For an RC sailboat I would think something like 0.5 seconds would work

scantime is the time between heading reads. If it were 100 msec then the value would be 0.10.

For the control systems we used a repeating timer to read the inputs on a fixed time interval. On earlier PC based systems we did not use the interrupt timers but just kept track of how long our loop update times were. Depending on what functions are available in your hardware and code you can either fixed the read interval or keep track of how long since the last read and use that for the “scantime”

This method worked well to filter out the noise yet respond quickly to sudden changes. There is a pretty good write-up at: http://web.mit.edu/2.151/www/Handouts/FirstSecondOrder.pdf. About 1/10th of the way down is a graph showing the response curves.

The PID algorithm was fun to develop in the PC. The original version was using QuickBasic on a DOS system. (boy to I feel old). I might be able to dig up the original basic code for the algorithm if you are interested.

BTW I am impressed by the description of your autopilot system. If I ever get my boat projects done, the kitchen remodel done (to keep harmony at home) I might try writing up an AP system using either a PC.

Messages In This Thread