Three-Wheel Odometry

advanced55 min

Why Use Three Wheels?

Two parallel encoders measure forward travel and rotation; a perpendicular wheel measures lateral motion. Together they support full planar pose (X, Y, heading) on the field.

Mathematics of Three-Wheel Odometry

Each control loop, take the delta (change) in ticks since the last loop and plug them into kinematics that separate forward, lateral, and rotational motion. See gm0: Odometry for the full derivation.

Basic Position Update Logic

Core update using encoder deltas (simplified; units depend on your calibration):

// Assume previous and current encoder values are stored
double leftDelta = currentLeft - previousLeft;
double rightDelta = currentRight - previousRight;
double centerDelta = currentCenter - previousCenter;

double forwardMovement = (leftDelta + rightDelta) / 2.0;
double headingChange = (rightDelta - leftDelta) / trackWidth;
double lateralMovement = centerDelta - (headingChange * centerWheelOffset);

// Update robot's position
robotX += forwardMovement * Math.cos(robotHeading) - lateralMovement * Math.sin(robotHeading);
robotY += forwardMovement * Math.sin(robotHeading) + lateralMovement * Math.cos(robotHeading);
robotHeading += headingChange;

Implementing Three-Wheel Odometry in Android Studio

Read encoders every loop in runOpMode(), compute deltas against the previous sample, then update pose and store the new encoder values for the next iteration.

Sample Loop for Odometry Update

Typical loop structure:

@Override
public void runOpMode() {
    // Initialize encoders and variables...
    waitForStart();
    while (opModeIsActive()) {
        // Read current encoder values
        int left = leftEncoder.getCurrentPosition();
        int right = rightEncoder.getCurrentPosition();
        int center = centerEncoder.getCurrentPosition();
        // Calculate deltas and update position (see above)
        // ...
        telemetry.addData("X", robotX);
        telemetry.addData("Y", robotY);
        telemetry.addData("Heading", Math.toDegrees(robotHeading));
        telemetry.update();
        // Store previous values for next loop
        // ...
    }
}

Calibration and Tuning

Measure track width (parallel wheels) and center wheel offset with a tape measure or CAD. Drive straight and in place turns; if pose drifts, tweak constants before long auto paths.

Common Pitfalls and How to Avoid Them

Reversed encoder signs, swapped left/right, or using diameter in the wrong units are frequent bugs. Test one axis at a time—straight line, pure rotate, short strafe—before full autonomous.

Practice Exercise

Write a function that takes in the previous and current encoder values for all three wheels and returns the robot's new X, Y, and heading.

  • Implement the position update logic in Java.
  • Test your function with sample encoder values.
  • Verify the output by making the robot create a simple “S” shape.