I wanted to navigate a robot by just using Digital Compass. My application required that the robot makes exact 90 degrees turns and moves dead straight. I used a 10 Degrees of Freedom Module ( 10 DOF) which has 3 axis - Accelerometer, 3 - axis Gyro , 3 - axis Digital Compass and a Pressure sensor.
After experimenting with this approach for a couple of weeks, I have come up with some insight that will be helpful in using Compass for Navigation.
-> Mount the Compass - at considerable height from the robot chases and motors:
The digital compass is very sensitive to any magnetic field. During my experiments, I felt that bring a metal too close to the compass module disturbs its reading. For this some plastic spacer can be used.
-> Implement Tilt Compensation :
The magnetic compass give stable reading when it is parallel to the surface. But as the compass is mounted on the robot which moves on surfaces that need not be planar. So the compass is not in its ideal operating condition and the reading which it gives are offset from the real value.
So, I used the accelerometer output in conjunction with the digital compass to have a very sense of reference.
You need to calculate the pitch and roll from the accelerometers output and then use it get have a tilt compensated digital compass output.
-> Take Care of the Error in orientation in the code :
Even tilt compensation was not enough of move the robot in a deterministic way. The reason was the use of differential drive in the robot. The motor used were not perfect, I mean the actual rpm of the 2 motor was not precise as per the specification.
So, I used PID Feedback Controller ( proportional, integral and derivative - feedback controller) to make the robot move dead straight with respect to the starting position.
However, I could not implement the PID Controller for pivot turn of the robot. I guess one need to find the differential kinematics equations for the pivot turn.
So, I implement my own error correction algorithms to dead with the few degrees error in the heading after each movement made by the robot.
For the future iterations on my project, I think of using rotary encoders and digital compass to have combined data for better reliability.
Hope that this information is useful.