Lachlan Micromouse Sensors Velocity

Velocity

Velocity is the main sensor reading you want for your controller. It is important to get a good estimate of velocity as it increases the reliability of your controller, and the more likely you will be able to push it to it's limits.

Filtering

You will want to filter your velocity in order to improve/predict it's intermediate values. A simple filter to use is a low pass IIR filter that is 10 times faster than your motor can react. For example our translational motor transfer function was:

LaTeX Equation

This makes our desired filter the following (notice the DC term to eliminate the DC gain):

LaTeX Equation

The s-plane is continuous time, and not realisable on a microcontroller, so we need to take the z-transform to bring it into discrete time which is directly realisable. The realisation is simple because it's only a first order filter. Taking the z-transform for a sampling period of 5 ms gives:

LaTeX Equation

This can then be directly realised on the microcontroller using a timer generated every 5 ms to filter the velocity with the following difference equation:

y[n] = 0.1423 * x[n] + 0.8577 * y[n - 1];

This filter will have the following response:

Bbcode image

quote:

A couple of notes:

  • Firstly, check for stability, the pole at |0.8577| is less than 1 meaning all poles are stable,
  • Secondly, there is a floating point relationship in there, be careful when using floating point on fixed point architectures such as a cheap microcontroller like the Atmel AVR or the PIC Micro. These microcontrollers do not have floating point hardware and can take thousands of clock cycles to process a floating point multiplication, even with a hardware multiplier like the Mega AVR's have. There is a comparison of the performance on an ATMEGA16 using avr-gcc at the following link: efficiency.txt

Special thanks to Twig whose idea it was to use a single pole, and thanks to Plex for suggesting using a lookup table to get rid of that nasty floating point operation.


Last Modified: June 20, 2009 with 3 page views.

Creative Commons Attribution - Non-commercial No Derivs (3.0) Suitable for Everyone