Skip to main content

Section 5.4 ActiveCode Exercise: Simulating Random Heading Drift

This exercise simulates a robot that estimates its position purely from wheel encoder readings, with no external correction. At each timestep, a small random error is added to the estimated heading and distance traveled, and students observe how these small errors accumulate into large position error over time.

Subsection 5.4.1 Simulation Setup

The true robot path is a straight line at constant velocity. At each timestep, the estimated pose is updated using the commanded velocity plus a small random noise term added to heading. Students plot the true path and the estimated path on the same axes after 50, 100, and 200 timesteps.

Subsection 5.4.2 Try It

Run the simulation below, then try changing HEADING_NOISE_DEGREES to see how the drift grows or shrinks.

Subsection 5.4.3 Interpreting the Drift

Because each timestep’s small heading error carries forward into every future position estimate, the gap between true and estimated position grows roughly with the square root of elapsed time for random noise, and grows linearly if there is a small constant bias. Students should identify which growth pattern their simulation shows and explain why a single bad turn early in a run causes more long-term error than the same-sized error late in a run.

Subsection 5.4.4 Test Case Interpretation

With a heading noise of 0.5 degrees per timestep and a run of 200 timesteps, the simulated position estimate typically ends up tens of centimeters away from the true position, even though no single timestep’s error looks significant on its own. This motivates the need for external correction, which later sections and Chapter 5’s aligned lab connect to landmark-based and sensor-fused localization.
You have attempted of activities on this page.