View Single Post
  #3   Spotlight this post!  
Unread 10-09-2008, 15:22
EricVanWyk EricVanWyk is offline
Registered User
no team
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Boston
Posts: 1,597
EricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond repute
Send a message via AIM to EricVanWyk
Re: Servo 'smoothing'

0705290 has given an example of a FIR Filter. Basically, the output is the weighted sum of past readings. With 07's code, you can make all sorts of filters by changing the weights.

I also like using IIR filters. These hold state a little differently, and I find the simple low pass IIR the easiest to tune.

Code:
tau = .75;  //This is the tuning variable
pwm_out = tau*sensor_in + (1-tau)*old_pwm_out;
old_pwm_out = pwm_out;
This does a passable job of modeling a resistor - capacitor filter - tau is the equivalent of the RC time constant, ish.

To tune the filter, you can link tau to a wheel input. Play with it until it feels right, and record it.

Also, I did this in floating point math, converting it to fixed shouldn't be too hard.

Have fun!