Gyro Precision

SPIKE Prime Robotics Camp — Day 3

 

 

 

 

Give your robot an inner compass

The Camp

  1. First Drive
  2. Maze Runner
  3. Gyro Precision (today!)
  4. Obstacle Avoidance
  5. Line Following + Showcase

Each day upgrades our robot.

Today's Mission

Upgrade your robot's inner compass:

  • Turn on the gyro
  • Prove it makes turns more accurate
  • Read the robot's heading

Honest truth: the gyro isn't magic. We'll tune it.

Rule of the Week

Bugs are sensor data.

The robot did exactly what the code said.
What did the code actually say?

Debug the Drawing

Here's a drawn sequence of robot moves.

One step is wrong. Find it.

A small early error throws off everything after it — that's sensor data!

Catch-Up: Where We Are

The robot can already:

  • Drive a straight() distance
  • turn() an angle
  • Run named moves to solve a maze

Connect, drive, and turn — then we add the gyro.

Blocks or Python?

  • Blocks — drag and drop
  • Python — type it out

Same robot, same ideas. Pybricks shows the Python next to your blocks.

What Is a Gyro?

A gyroscope senses how the robot is turning.

It lets the robot feel which way it's facing instead of just counting wheel-spins.

Why Turns Drift Without It

  • Wheels slip a little
  • The floor isn't perfectly even
  • Small errors add up over many turns

The gyro corrects as it goes.

Turn It On


robot.use_gyro(True)   # now turns/straights use the gyro
					

One line. Same straight() and turn() after that.

Off vs. On

Run the same moves twice — gyro off, then gyro on.

Measure how far off each one ends up.

The Experiment

  1. Run your square with the gyro off
  2. Mark where it really ended
  3. Add use_gyro(True) and run again
  4. Chart the error — off vs. on

Read the Heading

The robot can tell you the direction it's facing.

Print the Heading


print(hub.imu.heading())   # degrees
					
  • Starts at 0
  • Positive = clockwise
  • Output shows in the Pybricks console

Calibrate the Turn

The gyro is better — but not perfect.

Tune a True 360°

  1. Run robot.turn(360)
  2. Check hub.imu.heading() — back to 0?
  3. Over-spun? Try turn(357).
    Under-spun? Try turn(362).

Your Number Is Yours


robot.turn(357)   # one hub's true full turn
					

Could be 355-363 on yours. It's calibration, not a bug.

Energizer + Snack

Get up, move, refuel.

Keep food away from the kits and laptops!

Build It

Prove the gyro helps, then tune a true 360°.

The Loop That Matters

  1. Run gyro off
  2. Run gyro on
  3. Chart the error
  4. Tune your true 360°

The chart is the proof.

Demo + Wrap-Up

What We Learned

  • A gyro senses turning
  • use_gyro(True) makes turns more accurate
  • hub.imu.heading() reads the heading (starts at 0)
  • A true 360° is a per-hub calibration

Coming Up Next

Obstacle Avoidance

We'll give your robot eyes with the distance sensor —
so it can react to the world and change
what it does instead of running a fixed script.

Questions?

Great driving!