Skip to content
Week 5 · Lesson 5 55 min

Building, Testing and Debugging a Routine

Plan a path, structure an `@Autonomous` OpMode with helper methods and timers, and use telemetry, repeatability tests and logs to make it dependable.

In this lesson you will

  • Plan an autonomous path with a fixed start position and a time budget
  • Structure an @Autonomous OpMode with helper methods and ElapsedTime
  • Use telemetry and logging to see what the robot is doing at each step
  • Run a repeatability test and use the results to find and fix errors

Lesson

You now have all the pieces: encoders for distance, the IMU for heading, and P-control for accuracy. This lesson puts them together into a complete routine and shows you how to prove it works.

Scoring zoneParkStart12Generic field — not a season field
An example path on a generic tiled field: start, drive forward, turn, drive again and park.
  1. 1
    Fix the start position
    Decide exactly where the robot starts and how you will line it up, for example with its back against the wall and its side on a tile seam. Mark it with tape.
  2. 2
    List the moves
    Write each move as a line: drive 24 inches, turn to 90 degrees, drive 18 inches. Field tiles are 24 inches, which makes measuring easy.
  3. 3
    Choose where to end
    Pick a safe parking zone that does not block your alliance partner, and agree on it with them.
  4. 4
    Set a time budget
    Aim to finish well under 30 seconds, for example around 20, so slow runs still finish in time.

Structure with helper methods

Keep runOpMode() short so it reads like your list of moves. All the details live in helper methods: initHardware(), driveInches(), turnToHeading() and getHeading() from earlier lessons. Each helper has its own timeout, and one ElapsedTime called runtime measures the whole routine.

JAVA
1// Imports as in earlier lessons, plus com.qualcomm.robotcore.util.RobotLog
2@Autonomous(name = "Basic Auto", group = "Auto")
3public class BasicAuto extends LinearOpMode {
4    static final double TICKS_PER_INCH = 45.3; // your calibrated value
5    private DcMotor leftDrive, rightDrive;
6    private IMU imu;
7    private final ElapsedTime runtime = new ElapsedTime();
8
9    @Override
10    public void runOpMode() {
11        initHardware(); // map motors, set directions, init IMU, resetYaw()
12        telemetry.addData("Status", "Ready, heading %.1f", getHeading());
13        telemetry.update();
14        waitForStart();
15        runtime.reset();
16
17        step("Drive to first mark");
18        driveInches(24, 0.5, 4.0);
19        step("Turn left to 90");
20        turnToHeading(90);
21        step("Drive to parking zone");
22        driveInches(18, 0.5, 4.0);
23        step("Done");
24    }
25
26    private void step(String name) {
27        telemetry.addData("Step", name);
28        telemetry.addData("Time", "%.1f s", runtime.seconds());
29        telemetry.update();
30        RobotLog.d("AUTO %s at %.1f s", name, runtime.seconds());
31    }
32
33    // initHardware(), driveInches(), turnToHeading(), getHeading() go here
34}
A complete routine skeleton. The helpers come from the previous lessons.

Debugging with telemetry and logs

  • Show the current step name, so you know exactly where the routine stopped or went wrong.
  • Show target and actual values: target ticks and encoder counts, target heading and yaw.
  • Show elapsed time and battery voltage, so slow runs can be explained.
  • While debugging, add sleep(500) between steps to slow things down and read the screen.
  • Use RobotLog.d() to write messages to the robot log (logcat), which you can read later in Android Studio even after telemetry has changed.

Repeatability testing

One good run proves very little. Run the full routine at least 10 times in a row from the same start position and measure where the robot stops each time. If the robot always misses in the same direction by about the same amount, that is a consistent error, and you can fix it by calibration. If it lands in a different place each time, look for random causes such as wheel slip, loose parts or careless start alignment.

Column in your logWhat to recordWhy it helps
Run number and code versionWhich run and which version of the codeLinks results to the exact code you tested
Battery voltageVoltage before the runShows whether weak batteries cause errors
Distance errorHow far the robot stopped from the target, in inchesShows encoder calibration and slip
Heading errorFinal yaw minus target heading, in degreesShows turn tuning and IMU setup
Total timeSeconds from START to finishChecks that you stay inside 30 seconds
NotesAnything unusual: bumps, slips, alignment problemsHelps explain outliers
SymptomLikely causeWhat to try
Error message when pressing INITA name in hardwareMap.get() does not match the robot configurationCheck spelling and capital letters in the configuration and the code
Robot drives until the timeoutEncoder cable unplugged or a motor direction reversedWatch encoder counts in telemetry while pushing the robot
Robot turns the wrong wayMotor directions or IMU orientation set incorrectlyRe-test yaw by hand and check motor directions
Robot wobbles around the target headingkP too highLower kP and test again

Key terms

Helper method
A small method that does one job, like driveInches(), so the main code stays short and readable.
Telemetry
Data the robot sends to the Driver Station screen while it runs, used for monitoring and debugging.
Repeatability
How closely the robot ends in the same place when the same routine is run many times.
Consistent error
An error that has about the same size and direction every run, which calibration can fix.
`RobotLog`
An SDK utility that writes messages to the robot's log file, which you can review after a run.

Practical exercise

Build and prove your routine

  1. 1Sketch your path on paper with a fixed start position, the list of moves and a parking zone.
  2. 2Write the BasicAuto OpMode using your helpers and calibrated TICKS_PER_INCH and kP.
  3. 3Run it 10 times from the taped start position and fill in the log table after every run.
  4. 4Decide whether your main error is consistent or random, make one change, and run it 5 more times.
  5. 5Compare the averages before and after your change.
Deliverable: The final Java file, your path sketch, and a log of at least 15 runs with a short note on what you changed and whether it helped.

Knowledge check

Answer every question, then check your answers.

  1. Q1Your robot stops about 2 inches short of the target on every run. What kind of error is this?
  2. Q2Why should you aim to finish your routine well before 30 seconds?
  3. Q3What is the main benefit of a step() method that shows the current step name?
  4. Q4The robot drives until the timeout every time and never reaches its target. What should you check first?

Further resources

Mark lesson complete