How to turn a rover 90 degrees using wheel encoders?

I have a four wheel DC rover with two optical wheel encoders. I'm executing rover turns by controlling the direction of wheel motion on either side of the rover. To turn left, all wheels on the left rotate backwards while all right wheels rotate forward. This allows to rover to remain relatively in the same position while turning. The directions are reversed to do a right turn.

How can I use these two sensors to execute as close to a 90 degree turn as possible without fusing additional sensor data?

All theory aside, circumferences and actual distances travelled will vary with your wheel geometry since your wheels aren't perfectly tangential to their direction of travel while turning. While Ian gives some good math I think I would run tests and assign a pseudo-circumference.

I think I would just measure what the odometers read for a full 360 turn-about and then divide that up as necessary.

Also, I'd bet that different floors would give different performance from your off-tangent wheels and your pseudo circumference is probably dependent on that.

• +1, measuring instead of relying on pure calculation is an excellent practice. – Ian Apr 16 '14 at 20:56
• So all said a gyro or compass is probably the best way to go for this? I am trying to think of a ghetto way to measure turning with more accuracy/precision than driver wheel/motor odometry - could something be rigged with a floating/idling bearing and measure it moving (Ie a old style trackball or mouse)? Probably more complicated/expensive than the compass sensor though. – Danny Staple Apr 22 '14 at 20:20

If you wanted accurate turns, you should throw a gyrometer onto the rover. They're relatively inexpensive and easy to use. Here's one as an example: https://www.sparkfun.com/products/11977

No need for factors of pi. (I think in Ian's answer, the circumference would be pi*R since he defines R as the separation between the wheels which I read as the width of the robot?) You just need the width of the robot and the diameter of the wheels. The amount the robot turns is:

Ang = enc_value/enc_range * D/W * 360

Where Ang is the angle, env_value is your encoder reading, enc_range is the encoder reading for one full revolution, D is the diameter of a wheel and W is the width of the robot.

For 90 degrees you get:

enc_value= enc_range/4 * (W/D)

Calibration as another poster said, is recommended. This kind of dead reckoning without any reference points will accumulate errors pretty fast. After a few turns you'll have order unity errors.

Note that if you only drive the wheels on one side to turn, how the wheels drag on the other side is very dependent on the surface. For example on a softer surface, the wheel that has to push across the surface will dig in more than the one that is dragged and you'll rotate about the wheel not moving.

You want the wheel odometry to add up to 1/4 of the circumference of the circle whose radius is the distance between the wheels (call it $R$).

In other words, if you only drove one wheel and the wheels were $R$ units apart, then you'd leave a circular tire track whose circumference would be $2\pi R$. If the left wheel moved $\frac{2\pi R}{4} = \frac{\pi R}{2}$ then effectively you've drawn a quarter circle and are now facing 90 degrees ($\pi/2$ radians) to your right.

This also works if you rotate both wheels in opposite directions. Instead of rotating one wheel $\frac{\pi R}{2}$, rotate each wheel $\frac{\pi R}{4}$ in opposite directions. This will trace a circle of diameter $R$ (half the size of before), whose circumference is $\pi R$. Both wheels are tracing $\frac{\pi R}{4}$ or one quarter of the same circle.

My back-of-the-envelope says that this will work for any combination of left and right wheel distances. So, if your left and right wheel odometry values are $D_l$ and $D_r$, you've made a 90 degree turn to the right when $D_l - D_r = \frac{\pi R}{2}$

You should be able to calculate $D_l$ and $D_r$ from your wheel encoders since you know the wheel radius. At that point, the value of $\pi$ should be factored out of the equation.

This won't be accurate over time, but it's about the best you can do without factoring in any other sensor data.

• Which distance is R in your answer? distance between the two front wheels or the distance between the two left-side wheels? – Paul Apr 16 '14 at 19:33
• $R$ is the distance between the 2 drive wheels, which I'm assuming are also the 2 wheels that have the encoders. – Ian Apr 16 '14 at 20:54