Python#

本指南详细介绍了如何在 VEXcode V5 中使用 Python 方法。您将在此学习如何阅读和理解每个方法,包括其全面的描述、参数和使用示例。

了解方法条目#

API 参考文档中的每个方法条目都包含以下组件:

  • 命令名称 – 该命令的正式名称。

  • 描述 – 简要说明该命令的作用以及它可能返回的结果。

  • 定义 – 命令的语法,展示如何在代码中编写该命令。

  • 参数表 – 列出该命令接受的所有输入。

  • 示例代码 – 提供一个可复制粘贴的代码块作为使用示例。

示例方法输入#

驾驶#

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

可选。传动系统运动的速度,以浮点数或整数表示。如果未指定速度或先前设置为,则默认速度为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)