# Odom
Odometry is the use of motion sensors to continuously calculate how far and in what direction a robot has moved from its starting point. It does this by taking info from sensors like [motor encoders](MotorEncoders.md) and inertial measurment units [(IMUs)](IMUs.md).

**The Math**

Odometry relies on turning rotational data into a grid position (x, y) on the field. The core calculations for odometry involves tracking the rotations of the wheels and multiplying the rotations of the wheels by the wheel circumference to get linear distance traveled.

![Rolling](/images/OdomImg1.jpg)

```math
\text{Distance} = \text{Rotations} \times (\pi \times \text{Wheel Diameter})
```

After finding linear distance traveled, the [IMU](IMUs.md) or [gyroscope]() tracks the robots heading (angle) in relation to the field. You can use trigonometry to find the change in horizontal and vertical location with the following equations.

Add visual for math maybe
 ```math
\text{Horizontal Distance} = \text{Total Distance} \times \cos(\text{Heading})
```
```math
\text{Vertical Distance} = \text{Total Distance} \times \sin(\text{Heading})
 ```
 By adding these values to the robots starting position, you can calculate the robots new location.

**Limitations**

If you use the [encoders](MotorEncoders.md) inside your drivetrain motors for odometry, you may run into wheel slipping if your robot accelerates too quickly or gets pushed by another robot. This would cause your location to be slightly off because your robot thinks it is moving while it is not.

To fix this, you could use dead wheels. Dead wheels freely spin and are attached to optical encoders (might add link here but not sure if a wiki on this is necessary). Because there is no motor driving these wheels, they only spin when the robot is actually moving, eliminating wheel slip issues. Additionally, the robot should be placed in the correct starting position to ensure all future calculations are correct.

Another issue can come from the math of odometry relying on knowing the exact distance form the center of the robot to each tracking wheel. If the robot ends up tilting, changing its center of gravity, or lifting heavy game pieces, odom calculations may become inaccurate.
