⚡ EZ Template · First Steps

Your First Auton: Drive, Turn, Square

Three single-motion exercises that build on each other. By the end, your robot drives a 2-foot square on its own — and you'll see exactly why competition autons need sensors.

Before this: Complete EZ Template Fresh Setup. You need a PROS project that builds and uploads, and a chassis object configured with your motor ports, gear ratio, and wheel size.
// Section 01
Why This Guide Exists
The gentlest possible introduction to writing autonomous code. One motion per exercise, then chain them.

If you're new to PROS and EZ Template, do these three exercises first. When all three work, graduate to Clawbot Training — which combines drive and turn from the very first exercise and assumes you understand both.

What you need before starting

Get setup right first. If your chassis object has the wrong wheel size or gear ratio, every distance will be off by exactly that ratio. The robot will look like it's working — it'll just always stop short, or always overshoot. The EZ Setup guide has a chassis-constructor builder that does the math for you.

Where the code lives

All three exercises are void functions that live in src/autons.cpp. To run one, call it from inside the autonomous() function in src/main.cpp. For example:

📄 src/main.cpp
void autonomous() { drive_forward_24(); // or whichever exercise you're testing }

Whichever exercise you're testing, that's the one line that goes inside autonomous(). Swap it out as you move through the three exercises.

// Section 02
Exercise 1 — Drive Forward 24 Inches
Goal: robot moves forward 24″ and stops. Nothing else.
📄 src/autons.cpp
void drive_forward_24() { chassis.pid_drive_set(24_in, 80); chassis.pid_wait(); }

What each piece does

Run it. Call drive_forward_24() from inside autonomous(), then disable + enable the robot (or use the auton selector) to trigger it. Don't worry yet if it stops short or overshoots — that's tuning, which we do at the end. Right now we're just confirming the function compiles, uploads, and moves the robot.

Common issues

// Section 03
Exercise 2 — Turn Right 90 Degrees
Goal: from a stopped position, robot turns 90° to the right and stops.
📄 src/autons.cpp
void turn_right_90() { // Positive degrees = clockwise (right) in EZ-Template default. chassis.pid_turn_set(90_deg, 70); chassis.pid_wait(); }

What changed from Exercise 1

Run it. Swap drive_forward_24() for turn_right_90() in autonomous(), upload, run. The robot will probably overshoot or undershoot the 90°. That's expected — we'll tune turn PID at the end alongside drive PID.

Common issues

// Section 04
Exercise 3 — Drive a Square
Goal: robot drives a 24″×24″ square and ends roughly where it started, facing the original direction.

This is just Exercise 1 and Exercise 2 inside a loop. Four sides, four turns:

📄 src/autons.cpp
void drive_square() { // Loop the same 2-step pattern. Each side = 24" forward + 90° right turn. for (int i = 0; i < 4; i++) { chassis.pid_drive_set(24_in, 80); chassis.pid_wait(); chassis.pid_turn_set(90_deg, 70); chassis.pid_wait(); } }

What's happening:

💡
The hidden lesson. Even with carefully tuned PID, your square won't close perfectly. The robot will end an inch or two off, maybe rotated a few degrees. That's not a bug in your code — each of the 8 motions has a tiny error, and the errors stack up. This is exactly why competition autons use odometry and sensors to correct as they go, instead of trusting eight motions in a row to all land perfectly.

What to notice: a tight loop reveals PID error. If each turn under-rotates by 1°, four turns accumulate to 4° of heading error and the square spirals outward. The end-position miss tells you whether your turn PID is biased. Tune kP/kD in the turn PID until the error spread across 5 runs is under 2″.

// Section 05
Tune Both, Then Keep Going
Now go back and make each exercise more accurate. Drive PID and turn PID get tuned separately — they're different physics.

Tuning

Tune order: kP first, then kD, then kI only if you have steady-state error. Tune drive first, then turn. Touch one constant at a time. Re-run Exercise 3 after each round — the square will get tighter as your constants get better.

📝
Notebook habit: write down what you change and what happens. The judges will ask, and your team will need it next season.

When PID isn't enough

Tuned PID gets you within about half an inch on a 24″ move and a couple of degrees on a 90° turn. Once you've squeezed all you can out of PID and the square still drifts noticeably, it's time for closed-loop sensing:

When a single motion isn't enough