VEX2 Competition
| Line 20: | Line 20: | ||
There are three states that need to be handled in a user’s competition program. These are:<br /> | There are three states that need to be handled in a user’s competition program. These are:<br /> | ||
[[File:vex2_competition_overview.png]] | [[File:vex2_competition_overview.png]] | ||
| + | |||
| + | {| class="parameterTable" cellpadding="5%" | ||
| + | ! width="20%" style="color:white; background-color:#c0504d;border-style: solid; border-width: 2px 0px 1px 0px"|Parameter | ||
| + | ! width="80%" style="color:white; background-color:#c0504d;border-style: solid; border-width: 2px 0px 1px 0px"|Explanation | ||
| + | |- | ||
| + | | style="font-color:white; background-color:#c0504d; border-style: solid; border-width: 1px 0px 0px 0px"|DISABLED | ||
| + | | style="font-color:black; background-color:#d8d8d8; border-style: solid; border-width: 1px 0px 0px 0px"|text | ||
| + | |- | ||
| + | | style="font-color:white; background-color:#c0504d; border-style: solid; border-width: 0px 0px 2px 0px"|AUTONOMOUS | ||
| + | | style="font-color:black; background-color:#f4f4f4;border-style: solid; border-width: 0px 0px 2px 0px"|text | ||
| + | |- | ||
| + | |} | ||
| + | |||
{|style="border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; | {|style="border-collapse: separate; border-spacing: 0; border-width: 1px; border-style: solid; border-color: #000; | ||
Revision as of 12:50, 6 March 2012
|
Competition Template
In normal ROBOTC programming, every program is based around a “task main” function, as shown below:
task main() { } |
In a competition program, things are a little different. To keep things simple, however, a Competition Template program is built into ROBOTC for use in VEX Competitions. The template provides a common starting point for teams when competing in an event. Rather than a single “main” task, the template has three sections, each matched to a specific section of the competition:
- void pre_auton() – For running code that the robot needs to get “set up” before the competition begins
- task autonomous() – For code the robot should run during the autonomous period (20 seconds by default)
- task usercontrol() – For code the robot should run during the user control period (120 seconds by default)
The template and its accompanying “include” file handle the background work for the competition, such as monitoring the duration of each phase during a match, and communicating with the Vex Field Controller. All you need to do is tell the robot what to do in each phase.
Open a Competition Template
| To open a competition template: Go to File, select "New" and select "Competition Template" |
Set Up Competition Control and Timing
With ROBOTC, the competition control is completely user defined and controlled via software, so there are no jumpers required for testing. By changing these settings, the template can be adapted to work with any competition. The three lines above set the VEX controller into the “competition” mode and specify the timing for the match. #pragma competitionControl(competition_mode) – Controls the Competition mode that the Vex robot will function in. There are two different competition modes that you can pass to this statement:
#pragma autonomousDuration(time_in_seconds) - Defines the duration of the autonomous phase of a VEX competition. Poor performance may result if this setting does not match the Field Controller settings. #pragma userControlDuration(time_in_seconds) - Defines the duration of the user control phase of a VEX competition. Poor performance may result if this setting does not match the Field Controller settings.
|
Program and Test Competition Code
Phase 1: Pre-Competition
Place your initialization code inside this function. Phase 2: Autonomous
Place your Autonomous Period code inside this function. The AuonomousCodePlaceholderForTesting() function is only there as a placeholder and can be removed. During the autonomous period, the robot performs actions autonomously for the length of time specified by the “autonomousDuration(time)” setting. While the robot cannot accept commands from the Transmitter during this time, it still requires that the Transmitter’s signal be present as a safety precaution. You cannot skip the autonomous period during a competition by shutting the RF Transmitter off. If you shut the RF Transmitter off during the autonomous period, the VEX’s internal timers will pause, potentially causing your robot to enter the User Control period later than it should. You do not need to use any bIfiAutonomousMode commands when competition programming. Phase 3: Operator Control
Place your User Controlled Period code inside this function. UserControlCodePlaceholderForTesting() is only there for testing and can be removed once you have placed your own code inside of the while(true) loop. During the operator controlled period, the robot can accept commands from the Transmitter. This segment of code executes immediately after the autonomous period ends. If you shut the Transmitter off during this period you will not increase the length of the Operator Controller period as the Field Control System determines and controls the length of the human player period. |
Test Your Code
To test your competition code without a field control kit, follow these steps:
If you are using VEXnet, please see the "Testing with VEXnet" topics under the "Competition with ROBOTC" heading. |

