💻 Programming · Engineer · Beginner → Intermediate
IMU Setup & Calibration
Your autonomous turns are only as accurate as your IMU. A miscalibrated or misread IMU drifts 5–10° per turn — that compounds across a 15-second auton into a robot that misses its target by a foot.
Before this guide: You should have working drive code from the
Setup Guide and have run your first auton from
First 30 Minutes. This guide fixes inconsistent turns.
The V5 IMU (Inertial Measurement Unit) tracks the robot's heading in degrees. EZ Template uses it to execute turns like pid_turn_set(90, 90) accurately. Without it, turns rely on encoder ticks alone — which drift under any wheel slip, carpet variation, or battery difference.
EZ Template uses the IMU automatically once it's declared in the Drive constructor. You don't call IMU functions directly — EZ Template reads it internally for every pid_turn_set() call.
- Mount flat — the IMU must be parallel to the ground. Even a 5° tilt causes constant heading error.
- Away from motors — motors generate magnetic interference. At least 3 inches of clearance from any motor.
- Away from high-current wires — power cables near the IMU corrupt readings. Route them separately.
- Rigid mounting — the IMU must not flex or vibrate relative to the robot frame. A loose IMU drifts constantly.
- Center of the robot is ideal — it minimizes rotational effects from acceleration at the edges.
⚙ Configuration in EZ Template
// In include/globals.hpp — the 5th parameter is the IMU port
ez::Drive chassis ({-1, -2, -3}, // left motors
{4, 5, 6}, // right motors
7, // ← IMU port number here
3.25, 0.75, 360);
// EZ Template handles calibration automatically in initialize():
// ez::as::initialize() triggers IMU calibration.
// Do NOT touch the robot until Brain shows "Calibrated"
❌ Calibration Failure — 4 Causes
| Symptom | Cause | Fix |
| Calibration never finishes | Robot moved during calibration | Upload code, set robot down, wait for "Calibrated" before touching it. Never pick up the robot mid-calibration. |
| Turns are consistently X° off | Tilt in IMU mounting — not flat to ground | Use a level to check IMU surface. Re-mount so IMU is completely horizontal. |
| Heading drifts mid-run even with no turns | Motor magnetic interference or loose mount | Move IMU further from motors. Check all mounting screws are tight. |
| Brain shows port error on IMU port | Wrong port number in globals.hpp or bad cable | Check physical port matches the number in code. Reseat cable firmly. |
🔄 Resetting Heading Mid-Auton
// Reset heading to 0 at any point in auton (useful after wall alignment)
chassis.drive_imu_reset();
// Set heading to a specific value (e.g. after aligning to wall)
chassis.drive_imu_set(90.0);
// Read current heading (for debugging)
float heading = chassis.drive_imu_get();
Wall reset pattern: Drive into a wall, call chassis.drive_imu_reset(), then proceed. This eliminates accumulated drift from the first portion of the auton. Used by most top teams on every skills run.
✅ Pre-Match Calibration Checklist
- Robot is placed on the field, not moving, before you plug in the Brain cable to upload.
- After upload completes, wait for the Brain screen to show your auton selector — this means calibration finished.
- Do not move the robot during the first 3 seconds after powering on (calibration runs on startup).
- Check the Brain port screen — IMU should show a green heading value, not "?".
- Run a quick 90° turn test before queuing. If it overshoots or undershoots, your mount shifted.
IMU calibration establishes a reference frame — the coordinate system relative to which all subsequent measurements are defined. If movement occurs before calibration completes, the reference frame is corrupted: all heading corrections reference a wrong zero. This is identical to why a compass must be held still during initialization.
🎤 Interview line: “We always wait for IMU calibration to complete before any autonomous movement — confirmed by a Brain screen indicator. We also run a calibration accuracy test after every robot change: drive 48 inches straight and read the reported heading. If it drifts more than 1 degree, we investigate the cause. We have this test data for every major robot version.”
Why must you wait for IMU calibration to complete before starting any autonomous movement?
⬛ Moving before calibration drains the battery faster
⬛ The IMU sets its zero-heading reference during calibration — movement before completion causes all subsequent corrections to use a wrong baseline
⬛ PROS will throw an error if autonomous starts before calibration
📝Notebook entry tip: Build & Program — Orange slide — Write a sensor initialization entry: your IMU setup call, calibration delay, and how you verified completion (Brain screen indicator or terminal print). Include one data point: heading accuracy over 48 inches with and without IMU correction. A before/after comparison for any sensor makes the Test & Evaluate entry credible and specific.