Python#
本指南详细介绍了如何在 VEXcode IQ(第二代)中使用 Python 方法。您将学习如何阅读和理解每种方法,并了解其详尽的描述、参数和使用示例。
了解方法条目#
API 参考中的每个方法条目都包含以下组件:
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.
示例方法条目#
drive#
drive
moves the drivetrain in a specified direction indefinitely.
Usage:
drivetrain.drive(direction, velocity, units)
参数 |
描述 |
---|---|
|
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()