Lesson 04 · 60 minutes
Every Robot Is Different
Measuring your own robot's numbers
Today's goal
Let the IMU measure your robot's own motors, check one distance with a tape measure, and explain why one trial is not enough.
Ideas in this lesson
- A number in the code is a guess until you measure it
- Motors are not straight lines: half power is much more than half speed
- A gyro can measure turning, but not distance
- Mecanum wheels lose a lot when strafing: on our robot about 55%
- Several trials and an average beat one careful trial
Sense → Think → Do
The robot can SENSE its own turning with the IMU, so it can calibrate most of itself: that is the closed loop from lesson 3, pointed at its own motors. Distance it cannot sense, so for that you are the sensor, with a tape measure.
How the session runs
- Flash calibration.ino (the calibration program: no sensors or demos, just measuring). Open the Calibrate tab. Type the robot's name, then press the surface it is standing on (carpet, rug, hardwood, tile, concrete). The top panel always says which numbers the robot is driving with: the fleet defaults until it is calibrated.
- Step 1, speed curve: clear a space, press the button and stand back. For about 20 seconds the robot spins: first it hunts for the lowest power that gets it moving at all (ours: nothing at PWM 64, then suddenly 46 degrees a second at 72), then half, three-quarter and full power. Is half power half the speed? Usually it is much more: motors are not straight lines.
- Step 2, drive straight: it drives forward and back, then strafes left and right, slow and fast, with heading hold off. A stronger side makes it turn when it should go straight; the gyro measures how much, and each wheel gets its own trim. Watch the turn numbers shrink from round to round.
- Step 3, distance: press Drive it, measure from the start mark to the tail, and how far it ended up to the side. Enter both and Apply. Drive it again: closer?
- Every step changes the robot straight away and saves the numbers in its EEPROM. Flash mecanum_holonomic.ino again: it reads them at power-on (the top panel says 'saved in the robot's EEPROM'). Uploading a new version later keeps them.
- Now pick a different surface and do it again. Compare the two sets: which numbers change, and why?
- No IMU, or to see the science by hand: open 'Without an IMU' for the tape-measure runs (cf full power, ch half, cs strafe, cr spin), three trials each; the app averages them. Our robot strafed about 615 mm sideways for 1380 mm forward: 0.45. Why? The rollers slip sideways.
- Compare with another group's robot. Same kit, different numbers.
Try this
- Carpet against a hard floor: which number changes most, and why?
- Why do we average three trials instead of doing one very carefully?
- Run the IMU showdown square with heading hold off, before and after calibration. How much closer does it get to closing the square?
When it goes wrong
| What you see | What it means |
|---|---|
| Steps say 'Pick the surface first' | Press the surface the robot is on, at the top of the Calibrate tab. |
| Speed curve says the robot hardly turned | Wheels off the floor, battery flat, or no IMU found (Sensors tab, top panel). |
| Drive straight never gets there | A wheel rubbing or a loose motor: check by hand. Then run it again; it carries on from where it got. |
| Trials disagree by a lot | Battery is dropping, or the floor changes. Charge up and use the same patch of floor. |
| A wheel goes backwards in t0-t3 | Tick 'backwards' for that corner in the wiring table and paste the new table into the sketch. |
Notes for the grown-up
Measuring is the scientific method in miniature: predict, measure, repeat, average, check. The speed curve and drive-straight steps do most of it for you, which is the point to make: a robot that can sense itself can measure itself. Make the prove-it runs a small celebration; it is satisfying when the robot lands on the mark.
Ages: K-5: watch the speed curve and drive-straight steps, then the class guesses where the 1 m run will stop before measuring it. 6-12: compute STRAFE_EFFICIENCY by hand from the tape-measure steps, and discuss why the IMU's accelerometer cannot measure distance (a 0.01 g error, summed twice, is about 0.8 m off after 4 seconds).
Materials: Robot with MPU-6050 or BNO055, app, tape measure (mm), masking tape for marks, charged battery, a consistent floor patch about 2 m by 2 m.