Home > Lego > Odometer

A LEGO Odometer

by Ole Martin Bjørndalen

With this robot, you can measure distances by rolling it along the floor. As you roll along, the display of the RCX is continually updated with the distance in your unit of choice. (Mine is decimeters.)

It measures a ten meter stretch with an accuracy of +- 2cm. With the current software, it can measure distances up to 500 meters.

Parts Needed

The robot invention kit and a rotation sensor. You also need LegOS (update: now called BrickOS) if you want to run my program.


Source code: odometer.c

Programming the robot was very easy. The rotation sensor has 16 ticks for each full rotation. LegOS has one register for each input (ROTATION_n) which it counts up for each tick of the rotation sensor. So calculating the distance is as easy as multiplying this register with a constant: the length of the wheels circumference divided by the number of ticks.

At first, there seemed to be a complication: the RCX doesn't have floating point numbers. It turns out that LegOS has software floats, so displaying the distance in meters is as easy as lcd_int(ROTATION_1 * TICKLEN_METERS). I've included constants for metric units, and for feet and inches.

The ROTATION_n registers are 16 bit signed integers. This gives a maximum distance of 215-1 = 32767 ticks, or 524.9 meters (1722.4 feet).

Detail Views

Here's the whole shebang. This is longest robot I've ever built. It's 110 studs long when you don't count the wheel. If you want to build one of these, you should adjust the length to suit you. You should be able to comfortly hold the RCX and roll the wheel along the floor without bending over.

The wheel is connected directly to the rotation sensor (the blue brick). This makes it easy to calculate the distance per tick (wheel circumference divided by number of ticks per rotation).

The assembly is not very sturdy, but it works as long as you don't apply any pressure to it as you roll it along. A redesign would probably be a good idea, though.

Ooh, the door in my office is 2.9 meters away! (Displayed as 29 decimeters, since you can't display fractions on the RCX.)