IMU must be calibrated before use — it takes ~3 seconds. Mount it flat, calibrate at init, and don't bump it during the calibration window.
flowchart TD
Start([New bot, IMU mounted]) --> Mount[Verify mounting:
flat surface, secured
not over a motor]
Mount --> Init[In initialize:
chassis.drive_imu_calibrate true
blocks ~3 seconds]
Init --> Idle[Don't move robot
during calibration
'IMU calibrating' message on LCD]
Idle --> Test[Test: turn robot 90 degrees
read chassis.drive_imu_get]
Test --> Q1{Reading close
to 90?}
Q1 -->|"Yes, within ±2°"| Done([IMU good to use])
Q1 -->|"No, way off"| Q2{Drift over time?}
Q2 -->|"Yes, slowly drifts"| Drift[Normal — IMU drift is real
reset between auton steps
chassis.drive_imu_reset]
Q2 -->|"No, instantly wrong"| Mount2[Mounting issue
recalibrate flat]
Mount2 --> Init
style Start fill:#1e293b,stroke:#22d3ee,stroke-width:2px,color:#e2e8f0
style Done fill:#1e293b,stroke:#22c55e,stroke-width:2px,color:#e2e8f0
style Q1 fill:#fbbf24,color:#0f172a,stroke:#fbbf24
style Q2 fill:#fbbf24,color:#0f172a,stroke:#fbbf24
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.
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.
pid_turn_set() call.// 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"
| 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. |
// 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();
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.