point A the second phase is logic high. We’ll call this
reverse. My decision about which quadrature sense line is
the “first” one, and which logic level is which direction, are
both arbitrary and can be set up in any way that is most
convenient to programming.

The Test: Can We Actually
Measure the Distance?

Okay, we’ve got the code working, now does the
odometry actually work? Let’s do some basic math first. I
measured my wheels and they are 5 cm in diameter. This
means that the circumference of the wheel is πD, which is
5π = 15. 71 cm. In Listing 3, we see that I tell the robot to
go forward 1,000 tics and then back in reverse 1,000 tics. If
we have 360 tics per revolution, this means that 1000/360
= 2. 78 wheel revolutions; 2. 78 x 15. 71 cm is 43. 6 cm. On
my wood floor, I marked out 43 cm with a couple of loose
pieces of scrap debris and hit the reset button. My little
robot faithfully rolled forward and stopped right at my mark
and rolled back, but overshot its starting position because
the flywheel in the LEGO NXT servo motor just kept on
turning after I shut off the power.

The way the 754410 works is that it has no brake so
we just drifted past. I decided to add a little braking power
by running the motors forward again for 100 ms to act
as a brake before I turned off the power. This worked

reasonably well and my robot stopped on the dime right
where it started.

After running the motors to show that I did indeed
achieve a well functioning system, I put a loop at the
bottom of the main() function so that I could see the tic
value changing and the direction bit changing when I
spun the wheels. This was, after all, just a proof of
concept experiment. For those faithful readers of Mr.
Roboto, you may remember the November ‘08 column
where I described a simple PID algorithm that could
be used to control a motor’s speed. In that article, I
described a sensorless system that measured a motor’s
back EMF to gauge speed and direction. You can simply
use this motor’s feedback sensor data directly in those
calculations to give you another way to do a PID based
motor control system. I’ll leave that as an exercise for the
student, unless I get the urge to do such a thing and
write about it …

It is so easy with these motors, it almost seems like
cheating. The LEGO NXT servo motor is about $19 and you
get a motor, gearbox, mounting system, simple axle, and
quadrature feedback all in one package (you purchase the
wheel connection separately). The motor has decent
speed and torque for small robots and it isn’t a power hog
either. Keep those questions coming to roboto@servo
magazine.com and I’ll do my best to answer them.
Have fun and keep working on those robots! SV

Prototype Stencils

www.quickstencil.com

Proto-Basic
$94.50

Designed specifically for hand printing

Even paste distribution on any size board

Superior paste release and repeatability,
right at your desk!

Stencil comes with a squeegee
and pcb alignment tools

Convenient on-line ordering and same day shipment
*same day shipment dependant on courier availability