Using the Python Competition Template in VEXcode V5

The Competition Template is an example project that has commands already included to communicate with the Field Control System during competitions, ensures commands are in compliance with field regulations, and aids in setting up projects in order to avoid complications and disqualification ("competition" refers to a VRC event using the official field control hardware).  


Open the Competition Template from the Examples Page

VEXcode V5 Toolbar with the File menu open and the Open Examples option highlighted. Open Examples is the fifth option in the menu, below New Blocks Project, New Text Project, Open, and Open Recent.


Example Projects menu in the Templates category with the Competition Template example project highlighted.


Three sections of the template: Pre-autonomous, Autonomous Mode, and Driver Control

# Begin project code

def pre_autonomous():
  # actions to do when the program starts
  brain.screen.clear_screen()
  brain.screen.print("pre auton code")
  wait(1, SECONDS)
  
def autonomous():
  brain.screen.clear_screen()
  brain.screen.print("autonomous code")
  # place autonomous code here
  
def user_control():
  brain.screen.clear_screen()
  # place driver control in this while loop
  while True:
    wait(20, MSEC)
    
# create competition instance
comp = Competition(user_control, autonomous)
pre_autonomous()

Note: In order for your project to work at a competition, you must leave these functions in your project. Add commands where the comments indicate for each section.


Use the pre_autonomous Function for any Setup

def pre_autonomous():
  # actions to do when the program starts
  brain.screen.clear_screen()
  brain.screen.print("pre auton code")
  wait(1, SECONDS)

The pre_autonomous function is used for any set-up your robot may need such as calibrating a Gyro, setting variables, or other device settings. These commands will run immediately when the project is started, before the autonomous portion of the match begins.

VEXcode V5 Python Competition Template project with the pre_autonomous() function shown. The indented lines after the function declaration are highlighted to indicate that every line inside a function should be indented.

Ensure that all commands are properly indented to that the guiding line is visible between the pre_autonomous and autonomous functions.

Note: If no setup is needed, this function can remain empty.


Autonomous

def autonomous():
  brain.screen.clear_screen()
  brain.screen.print("autonomous code")
  # place autonomous code here

The autonomous function is used for controlling your robot during the autonomous portion of a VRC match. Commands within this function will run when the match begins the Autonomous period.

VEXcode V5 Python Competition Template project with the autonomous() function shown. The indented lines after the function declaration are highlighted to indicate that every line inside a function should be indented.

Ensure that all commands are properly indented to that the guiding line is visible between the pre_autonomous and autonomous functions.

Note: If no setup is needed, this function can remain empty.


User Control

def user_control():
  brain.screen.clear_screen()
  # place driver control in this while loop
  while True:
    wait(20, MSEC)

The user_control function is used for controlling your robot during the driver control portion of a VRC match.  Commands within this function will run when the match begins the Driver Control period.

Note: The while True loop is shown above so the robot will respond to input from the V5 Controller for the entirety of the match.

VEXcode V5 Python Competition Template project with the user_control() function shown. Several blank, double-indented lines inside of the while True loop are highlighted to indicate that every line inside this loop should be indented twice.

Ensure that all commands are properly indented within the while True loop while coding the user control portion. Two guiding lines should be visible as shown here. One because the while True is within the user_control function. The other to ensure commands are within the while True loop.

For more information, help, and tips, check out the many resources at VEX Professional Development Plus

Last Updated: