During the VEX Robotics Competition (VRC), matches are played in two segments: one 15 second Autonomous Period where no human input is allowed, and one 105 second (1:45) Driver Control Period where human input is allowed. There are also Skills Challenges which consist of either 60 seconds of autonomous or driver controlled operation. Each of these periods of robot control is signalled from a Field Controller, Competition Switch, or from the handheld controller itself. The Competition Template is designed to make it comparatively easy to write a program that handles these competition signals and reacts appropriately.
When a user's program runs on a V5 Brain, it isn't alone. Software from VEX runs alongside it: the V5 Brain's operating system, called VEXos; and the various firmware programs on attached devices. This VEX-provided software goes a long way to determining how a robot following competition controls will act.
If no competition control device is present and the handheld controller isn't mimicking one, VEXos tells the user program that it is in Driver Control mode. In Driver Control mode, VEXos allows the user program to read values from the handheld controller and control motors. In Autonomous, the user program is not told what the joysticks or buttons on the handheld controller are doing. When the competition state is Disable, the user program isn't allowed to control motors or read values from the handheld controller. If a user program attempts to read from the handheld controller when it isn't allowed to, it will get responses as if the controller isn't being handled in any way. In all modes, sensors keep working and code keeps running.
Mode | Read Controller | Control Motors | Read Sensors |
---|---|---|---|
Driver Control | Yes | Yes | Yes |
Autonomous | No | Yes | Yes |
Disabled | No | No | Yes |
When one of the the competition commands is used for the first time in a program, the competition management thread is started. (For more information on threads, check the Threads entry under Further Reading.) The competition management thread runs in the background and watches for changes in the competition mode being reported by the handheld controller. When it notices a change in the competition mode, it then takes action appropriate to the change:
The way the user program makes use of the competition management system is by designating two chunks of code as the Autonomous and Driver Control sections. In addition to the threads created by the competition manager, the program can have other threads that run regardless of competition state. Those threads will not be managed by the competition management thread, though, so using them to do things like reading values from the handheld controller or controlling motors is not advised.
The competition commands in the vex::competition class all require an instantiated object. None are static.
Register competition mode handlers:
Manually check competition state:
Check nature of competition control hardware: