Skip to main content

4 - Odometry

Odometry is "the use of data from motion sensors to estimate change in position over time." (Wikipedia)

Odometry allows the robot to know where it is on the field at any given time. This enables the robot to automagically correct itself if it drifts off it's autonomous course.

Odometry ExampleOdometry Example

How do?

Theres a huge variety of methods for calculating the odometry, each with their own strengths and weaknesses.

Tank Drive Odometry ParametersTank Drive Odometry Parameters

The easiest solution is to use the encoders that are also built in the robot's drivetrain. By tracking how much the wheels of a robot rotate, we can use trigonometry to figure out how far the robot has driven from its starting point.

warning

This method relies on the drive wheels having good contact and friction with the ground which is almost never the case. Drive wheels can and will slip a significant amount during the course of an autonomous run.

DO NOT rely on this method for long or complex autonomous routines.

If you're going to use this method, keep the robot slow, minimize sharp accelerations/turns, and use an IMU to help.

Example Code

// Make sure there is a tank chassis defined
TankChassis chassis = TankChassis(leftMotors, rightMotors);

// Define the radius of the drivetrain wheels (in inches)
static constexpr float WHEEL_RADIUS = 1.0f; // in

// Define the distance between the left and right drivetrain wheels (in inches)
static constexpr float WHEEL_BASE = 12.0f; // in

// Create a Tank Chassis odometry object
// (Since TankChassisOdom is an AsyncTask, we must use a shared pointer)
std::shared_ptr<TankChassisOdom> odom = std::make_shared<TankChassisOdom>(
chassis,
WHEEL_RADIUS,
WHEEL_BASE
);

MyRobot() {
odom.setTicksPerRevolution(300); // <-- Change based on your robot's gear ratio

// ...
}

Usage

Odometry provides the current heading and position of the robot on the field as a Pose object. The Pose provides x and y coordinates (in inches) representing the robot's position, as well as a heading (in degrees) representing the robot's orientation.

void opcontrol() {
while (true) {
// Get the current pose of the robot
Pose pose = odometry.getPose();

// ...
}
}

Inertial Sensor

An Inertial Sensor (IMU) can be used to improve the accuracy of odometry calculations by providing accurate orientation data that drifts significantly less over time. While optional, it is highly recommended to use an IMU for the best performance.

// Define the Inertial Sensor
InertialSensor imu = InertialSensor("IMU", 15);

MyRobot() {
// Use the IMU for odometry calculations
odometry.useIMU(&imu);

// ...
}