Turning a robot accurately?

So I m using a differential drive, 3 wheel robot(2 motors on two wheels). I have encoders on the wheels to get odometry readings. So I can turn the robot to roughly the degree point I want to turn to. However its not always exact. So basically if I want to say turn left by 30 degrees, I rotate the robot until the angle read from the encoders is greater than 30. eg

if(theta_angle >= 30)

The problem with this is the angle read must always be larger than 30 degrees before the robot stops. So there are 3 problems with my approach,

• The threshold is set up so wheels stop once angle is greater than desired, meaning that the angle robot stops always has to be larger than the angle i m getting to. • the slipage from momentum of wheels once motors stop. eg power is just let go meaning momentum carries wheels, and encoder readings beyound desired. • The time sample of odometry (time gap means degrees can run on. less frequent sample time means lower the sensitivity of detecting angle).

So I can lower the sample time of the odometry which improves things, but does anybody have advice on a better approach to stopping correctly at the right angle?

Wheels usually slip when a robot is turning, in which case odometry does not very accurately reflect the turn angle.

These days most people use an IMU to measure the yaw angle continuously, so you can use PID to get an accurate orientation.

I tried to use a compass for orientation but i had a lot of trouble. Firstly calibrating the compass was difficult. Then I wasnt sure how correctly it was calibrated because the compass on my IPhone was behaving strangely. Also the compass near the electronics of my robot seemed to effect it. So not only do compasses seem to be effected by electronics but also by the magnetic disturbances from a building. So even if i try to isolate the compass by putting it on a mast it will probably still be effected by indoor interference. Do you know if IMU s work well in indoor envirnments because it seems compasses are not worth using in doors. I know IMUs consist of accelerometers, gyroscopes and magnetometers but do they work well indoors?

How fast is the turn being made? Perhaps you can slow the turn to minimize the mechanical coast down of the motors and the bot.

Firstly calibrating the compass was difficult.

Follow this sophisticated but straightforward procedure, with the compass in its final location on the robot. The procedure can correct for distortions caused by local magnetic fields and nearby iron objects.

However, it is possible that indoors, there is too much magnetic interference for the compass to work. In that case, you can try a gyro. They drift, but for tens of seconds, reasonably accurate relative turn angles can be measured.

I think i will try to slow the turning down and this should improve things.

Follow this sophisticated but straightforward procedure,

Thanks for that, however I tried calibrating the compass in a similar way already from the following link http://diydrones.com/profiles/blogs/advanced-hard-and-soft-iron-magnetometer-calibration-for-dummies

It made the compass work better but still the building I m in seems to cause too much fluctuation of the heading so I might consider using a gyro.