Lesson 31: Dead Reckoning
Dead reckoning is estimating where the robot is by using its own movement sensors. If you know where the robot started and you measure how far it has moved, you can estimate where it is now.
The Basic Idea
Imagine the robot starts at position zero. If the encoders say the robot has driven forward 48 inches, your estimated position is 48 inches forward. If the gyro says the robot turned 90 degrees, future forward movement should be counted in that new direction.
Why It Is Only an Estimate
Dead reckoning drifts. Wheels slip, robots get bumped, carpet changes, and sensors have noise. The estimate is still useful, but it should not be treated as perfect truth.
Tracking Distance
For a simple tank drive, average the left and right encoder distances to estimate forward movement.
double leftDistance = leftEncoder.getDistance();
double rightDistance = rightEncoder.getDistance();
double averageDistance = (leftDistance + rightDistance) / 2.0;Tracking Heading
The gyro gives the robot heading. Distance tells you how far the robot moved; heading tells you which direction it was facing while it moved.
double headingDegrees = gyro.getAngle();
double headingRadians = Math.toRadians(headingDegrees);Practice
Draw a robot on graph paper. Move it forward 24 inches, turn 90 degrees, then move forward 24 more inches. Mark the final estimated position. That drawing is the same idea dead reckoning uses in code.