Now that the encoders and PID controller are working so well I was anxious to put them to use so I threw together some very crude dead reckoning code.

The goal was to make the bot to traverse a square of 60 cm, i.e move 60cm and turn 90 degrees, four times.

First step was to create a function to convert millimeters to encoder ticks.

The diameter of each wheel plus its track is 38.5 mm which makes the distance travelled per revolution:

diameter × Π = circumference

38.5 × Π = 120.95 mm

Previously I’d estimated there are 1204 encoder ticks per revolution, so to get ticks from millimeters:

ticks = (mm/120.95) × 1204

For moving in a straight line for 60 cm we can calculate the number of ticks needed, which is 5972.

Turning is a little be more complicated. To turn in place we drive one wheel forward and the other in reverse. The bot should turn at the center point between the tracks. I’m assuming that tracks are in essence going to move around the arc of a circle that is centered between the tracks and having the diameter of the distance between the mid points of each track, like this:

So we can calculate the distance each wheel needs to move to turn D degrees as:

distance = (85 × Π × D)/360

Which for 90 degrees is 66.76 mm, which is 565 ticks.

So much for theory, what was the practice?

This is a run using the above calculations:

The turns are not 90 degrees – not by a long shot. I think the problem is loss of traction during the turns. However, the travel distance is also off. Instead of going 600mm the bot actually travels 575mm.

Obviously I have some more work to do. Still, I fudged the track width in the calculations till I got 90 degrees turns. (Nothing like a little fudging.) Instead of 85cm I ended up with a width of 108.5cm and this is the result:

It wasn’t always that perfect but pretty close.

Very excited about implement a full navigation/dead reckoning/mapping/waypoint system. Lots of ideas on how to put it all together.

Very happy with Zumo Bot right now.

The code is available on GitHub.

Pingback: NavBot – Initial Software Design | Solder Spot

Pingback: NavBot: Navigator | Solder Spot