Python#

This guide provides detailed information on how to use the Python methods in VEXcode V5. Here, you will learn how to read and understand each method, with comprehensive descriptions, parameters, and usage examples.

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 forward or in reverse using the current drive velocity. This method runs continuously until another Drivetrain method interrupts it or the project stops.

Usage:
drivetrain.drive(direction, velocity, units)

参数

描述

direction

The direction in which the robot drives:

  • FORWARD
  • REVERSE

velocity

Optional. The velocity at which the drivetrain will move as a float or integer. If the velocity is not specified or previously set, the default velocity is 50%.

units

Optional. The unit to represent the velocity:

  • RPM (default) – Rotations per minute
  • PERCENT
  • VelocityUnits.DPS – Degrees per second
# Drive forward, then stop
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()

# Drive forward at 360 degrees per second
drivetrain.drive(FORWARD, 360.0, VelocityUnits.DPS)