Code practices
Write robot code that your teammates can read, test, and improve
Team code
code is read by more than the person who wrote it. A teammate may need to fix it between matches, change it for a new , or explain it to a new student. Clear code makes those jobs easier.
You do not need a large architecture to start. For your first , focus on three habits:
- Name things for what they do.
leftDriveMotortells more thanmotor1. - Keep each step easy to find. Map hardware, wait for START, then run the control loop.
- Explain unusual decisions. A short comment can record why a is reversed or why a power limit exists.
Example
This fragment shows the idea. It belongs inside an OpMode after leftDriveMotor has been mapped and START has been pressed:
double forward = -gamepad1.left_stick_y;
double safePower = forward * 0.25;
leftDriveMotor.setPower(safePower);The names say what the values mean. The 0.25 limit makes the first drive test slower. If that limit is temporary, explain when the team should change it.
Small changes
- Change one behavior at a time when testing a new robot.
- Build the project, then test the changed behavior on the real robot with a safe setup.
- Review
git diffbefore committing so unrelated changes do not slip in. - Record configuration names and important measurements where teammates can find them.
Topics
| If you need to… | Read… |
|---|---|
| Pick names for motors, values, and classes | Naming conventions |
| Decide where code belongs | Code organization |
| Diagnose slow updates or stale data | Loop timing and bulk reads |
| Make code easier to scan | Formatting |
| Explain a choice in code | Comments and documentation |
| Share and review changes | Team collaboration |
Start with the guide that solves a problem your team has today. Return to the others as your robot project grows.