On Fri, Jan 15, 2010 at 10:34:12AM +0000, Mike Harrison wrote: > I'm trying to get my head round how to damp a cyclic compass heading > value without odd things happening around the transition from 0 to 359 - > I'm sure there is a simple trick to it but can't figure out what it > is.... > > What I normally do for non-cyclic values is a simple IIR filter > new_value=old_value*damp+last_reading*(1-damp) This is equivalent to: new_value = old_value + (1-damp)*(last_reading-old_value) ie add a fraction of the difference between lastest and old to get the new value. This will still work if you calculate the difference so that it's between -180 and 180, and of course wrap the final addition. Regards, Chris -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist