One of the initial goals of the rover was to be able to turn a precise angle, on the spot. One simple (albeit inaccurate) way of doing this is to measure the distance between the two wheels.This will tell you the diameter of the circle it will rotate in, from which you can work out the circumference and thus how many times you need to rotate the wheels to have turned a full circle.

(The rover's "inertial measurement unit")
Often the numbers don't match up as much as one would like especially with errors in measuring the exact distance between the wheels and their diameters. This leads you down a route of trial and error, tuning the number of revolutions or pulse counts from a quadrature encoder required for a full rotation. There might not be a linear relationship between the number of pulses required for half or a quarter of a circle either. Finally, depending on the surface the wheels could slip and give false pulse counts which would affect the angle we think we've turned. A better solution is required.
With the advent of MEMS technology, inertial sensors like gyroscopes and accelerometers are available at reasonable prices, however they come with the added cost of being less accurate than their military- or aviation-grade counter-parts. Luckily we can offset this problem through things like calibration and oversampling to reduce noise.
I decided to use the ITG-3200 triple axis gyroscope and ADXL345 triple axis accelerometer to create my inertial measurement unit, or IMU, for the rover. Both sensors are cheap and have ADCs built into them providing a digital interface over I2C and SPI. This has the benefit of reducing the load on the mbed, and also reducing the noise which would be picked up over long flying leads if the signal read was an analog one.
The IMU would be able to determine the current orientation by of the rover, including its heading, which would change as it rotated. In this way I would be able to make the rover turn a precise distance and also, in the future, be able to determine if it was going over any particularly rough or sloped terrain!
A recent orientation filter with novel features by Sebastian Madgwick as outlined in his paper "An efficient orientation filter for inertial and inertial/magnetic sensor arrays" provided an excellent way to fuse the data from both the gyroscope and the accelerometer to give a result that was greater than the sum of the parts.
The filter calculates the Euler angles: roll, pitch and yaw. It is abstracted in the mbed IMUfilter library making it available for anyone who wants to calculate orientation but doesn't want to worry about quaternions!
You can find more information about the IMU filter library, including an example program and a video of it in action on the IMU mbed cookbook page.
My next post will look at the internals of the rover's application code, including its extensible state machine.
Other posts in this series:
1. Introduction
2. Chassis
3. Quadrature encoders
4. PID velocity control
5. Inertial measurement unit
6. Rover State Machine
7. Conclusion
8. Technical Details