# Odometry

Assuming that you have wrestled the various technical issues of getting a good reading out of the encoder, you can use those readings for use in the fine art of odometry. Though odometry and mapping were mentioned in Applied Robotics, it is a topic worthy of a quick reprise here.

Odometry is the art of translating the individual wheel motions of differential (i.e. tank) drive robots into the change in position and orientation of those robots. As in all things mathematical, the odometry equations describe the behavior of an idealized robot (as shown to the right). In this ideal robot there are two infinitesimal contact points, one on each wheel where it touches the ground. In the real world, our wheels are several inches wide and there is no telling where the actual contact point is. Anyway, the space between the contact points is the width W of the robot. At the midpoint between these contacts is the center of the robot (at least, as far as the odometry is concerned).

To calculate the change in position and orientation of the robot across a given span of time, you merely take the linear distance DR and DL each wheel has traveled (calculated from the number of ticks from the encoders and the diameter of the wheels; you figure it out!) and plug it into the following equations.

The new orientation (which is in radians) is calculated by:

```OT+1 = OT + (DR - DL) / W
```

The distance traveled during this time span is:

```DT,T+1 = (DR + DL) / 2
```

In the case of the distance traveled, we are calculating a linear approximation of a curved path. As such, the longer the interval between calculations the worse this approximation is going to be.

If you are working with a map (or are trying to build one as you travel), the new Cartesian coordinate of the robot is calculated as:

```XT+1 = XT + DT,T+1cos(OT+1)
YT+1 = YT + DT,T+1sin(OT+1)
```

The internal ticking (from time T to time T+1, T+2, and onward into infinity) that drives the odometry can also be used to collect other impressions from the senses. These can be correlated with the robot's position in space and time, to build up a map of space and the events that occur in it.

Of course, this is all easier said than done.