Python#
This guide provides detailed information on how to use the Python methods in VEXcode IQ (2nd gen). Here, you will learn how to read and understand each method, with comprehensive descriptions, parameters, and usage examples.
Note: The IQ (2nd gen) Brain runs Python through a virtual machine with limited memory. While there is a maximum source code size, whether a program will run also depends on its complexity (such as the number of functions, variables, and logic used). As a result, programs that are large or complex may fail to compile or run even if they are under the size limit. C/C++ programs are generally less affected by these limits on IQ (2nd gen).
Understanding the Method Entries#
Each method entry in the API Reference includes the following components:
Command Name – The official name of the command.
Description – A brief explanation of what the command does and what it may return.
Definition – The syntax of the command, showing how it should be written in code.
Parameter Table – Lists all inputs the command accepts.
Example Code – A usage example provided as a copy-and-paste code block.
Example Method Entry#
drive#
drive moves the drivetrain in a specified direction indefinitely.
Usage:
drivetrain.drive(direction, velocity, units)
Parameters |
Description |
|---|---|
|
The direction in which to drive:
|
|
Optional. The velocity at which the drivetrain will move as a float or integer. If the velocity is not specified, the default velocity is 50%. |
|
Optional. The unit that represents the velocity:
|
# Drive forward, then stop
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# Drive slowly in reverse then stop
drivetrain.drive(REVERSE, 20, PERCENT)
wait(2, SECONDS)
drivetrain.stop()