# How do cleaning robots accurately measure the distance they’ve travelled?

## Why is distance measurement important for cleaning robots?

To save time and battery power, cleaning robots must follow the most efficient path (pictured below) as they navigate through a room. To follow this path, the robot needs to take a turn and travel a small distance after colliding with the wall. By doing so, the robot can easily avoid overlap when cleaning. This small distance is highlighted in blue in the picture.

To accurately measure this distance, an incremental magnetic wheel encoder is used inside the robot. This wheel encoder is attached to the driving motor’s shaft to help the robot by counting the wheel rotation.

Inside the wheel encoder, a ring magnet (which looks like a metal washer) is connected to the motor shaft. This ring magnet is specially created with multiple pairs of N-S poles, as shown below.

To sense, a Hall effect sensor connected to the main controller is placed closer to this ring magnet. This sensor generates an electrical pulse when the ring’s magnetic field is rotated.

## Mathematics behind the rotation count:

How is the robot able to count the wheel rotation with the help of this wheel encoder? Suppose the magnetic ring has 4 separate magnetic poles inside it. In one full rotation of the magnetic ring, the Hall effect sensor will generate 4 electrical pulses due to the change of magnetic field.

On the other side of the motor shaft, the wheel of the robot is connected through a gear reduction box. Let’s assume it has a 20:1 gear reduction ratio, meaning that the motor shaft needs to rotate 20 times for one revolution of the wheel. Then the total no. of electric pulses generated for one revolution or 3600-degree rotation of the wheel is 80 (4 electric pulse generated per motor shaft rotation X 20 motor shaft rotation per wheel rotation) and in each electric pulse, the wheel rotates by 4.50 (3600/80) degrees.

If the controller knows the circumference of the wheel, it can easily convert the generated electric pulse into the distance travelled simply dividing the circumference of the wheel with the total no. of generated pulses in one rotation.

Distance travelled on each pulse = circumference of the wheel / Total no. of generated electric pulse

= (𝝅 X d) / 80

= (𝝅 X 50) / 80    (Assuming the diameter is 50mm)

= 1.96 mm

Therefore, on each pulse generated by the magnetic wheel encoder, the robot travels approximately 2 mm. The robot can easily combine the distance value with the other sensor data to follow the most efficient path around the room, go back to its charging station, detect unclean areas, and do some other cool stuff.