What the PROS competition template actually is, how the five hook functions work, when to use a competition switch, and what happens to your code at a real match.
initialize, autonomous, opcontrol, etc.) that controls when code runs. The EZ Template is the drive library that lives inside it. You always use both together.When you create a PROS project, src/main.cpp contains five special functions. PROS calls these at specific moments during a match — you do not call them yourself. The field control system triggers them.
| Function | When it runs | What to put here |
|---|---|---|
| initialize() | Once, when the Brain powers on or program starts | Motor configurations, sensor setup, EZ Template chassis init, auton selector registration. Runs before anything else. |
| competition_init() | Once, when connected to a field controller | Usually empty for most teams. Can be used to reset variables or show a message when plugging into the field at a competition. |
| disabled() | Repeatedly, during any disabled period | The EZ Template auton selector runs here automatically. You can add a loop to update the Brain screen or blink an LED. Motors cannot be commanded during disabled. |
| autonomous() | Once, at the start of the 15-second autonomous period | Call ez::as::auton_selector.call_selected_auton() to run whichever routine was selected. All autonomous movement commands go in your separate auton functions. |
| opcontrol() | Repeatedly, during the 1:45 driver control period | Controller input loop: chassis.opcontrol_tank(), mechanism controls, button handling. This is the main driver control loop. |
initialize() indefinitely. If your initialize function never returns, your robot is stuck in initialize forever and neither autonomous nor opcontrol will ever run. Keep initialize fast and non-blocking.disabled() function runs in a loop here.autonomous() function exactly once. Your selected routine runs. The driver cannot touch the controller — any button press is ignored. After 15 seconds, the field disables autonomous whether your routine finished or not.opcontrol(). Your driver control loop starts. The driver can now use the controller. This period runs until the match ends at 2:00. If opcontrol() somehow returns early, the robot stops responding — always keep it in a while(true) loop.The V5 Competition Switch (VEX part #276-2338 or equivalent) is a small box with two ports and a toggle switch. It connects between your robot and acts as a simplified field controller:
disabled() → autonomous() transition that happens at a real event. It also bypasses competition_init(). Always test with the switch before competing.At a competition, the tournament staff runs field management software that controls all robots simultaneously from a central computer. When the referee enables autonomous or driver control, the FMS sends a signal through a cable in the field perimeter to your robot's controller. Your code responds exactly as it did with the competition switch — because it is the same signal protocol.
disabled() and the auton selector appears.autonomous() function runs.opcontrol() loop begins. The driver has 1:45.initialize() before autonomous was registered, or call_selected_auton() is not in your autonomous() function.opcontrol() has a while(true) loop with pros::delay(). If opcontrol returns immediately, the loop exits and the robot stops responding.initialize(). If you plug into the field after initialize() already ran on a running robot, the IMU may not be fresh. Always let the robot restart (power cycle) before connecting to the field for a match.disabled() → autonomous() → opcontrol() is a state machine with three states. The field controller is the external event source — your robot is the reactive system.autonomous() function works when you run it manually on the Brain, but does nothing at a competition. The most likely cause is:autonomous() was not declared in the right fileez::as::auton_selector.call_selected_auton() is missing from autonomous(), so the function runs but executes nothing