机器人专用 Python#

所有标准 VEXcode VR 命令均可在VIQRC 虚拟技能 - 快速接力游乐场中使用。

运动#

motor.spin()#

The motor.spin(direction) command is used to spin a motor indefinitely.

这是一个非等待命令,允许任何后续命令无延迟地执行。

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.spin(direction).

对象

描述

intake_motor

旋转 Swish 的进气口来收集球并将它们放在弹射器上。

catapult_group

升高或降低 Swish 的弹射器来发射球。

参数

描述

方向

The direction for the motor to move in: FORWARD or REVERSE.

**返回:**无。

# Spin the Intake Motor to bring a Ball onto the Catapult.
intake_motor.spin(FORWARD)

wait(2, SECONDS)
intake_motor.stop

motor.spin_for()#

The motor.spin_for(direction, distance, units, wait) command is used to spin a motor for a given amount of degrees or turns.

This is can be a non-waiting or waiting command depending on if the wait parameter is used.

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.spin_for(direction, distance, units, wait).

对象

描述

intake_motor

旋转 Swish 的进气口来收集球并将它们放在弹射器上。

catapult_group

升高或降低 Swish 的弹射器来发射球。

参数

描述

方向

The direction for the motor to move in: FORWARD or REVERSE.

距离

电机移动的距离,为整数。

单位

The units that the motor will use: DEGREES or TURNS.

等待

Optional. The wait parameter determines whether the command will block subsequent commands (wait=True) or allow immediate execution (wait=False). If unspecified, the default for the wait parameter is wait=True.

**返回:**无。

# Launch the Ball currently loaded on the Catapult.
catapult_group.spin_for(REVERSE, 5, DEGREES)

# Lower the Catapult to prepare to load another Ball.
catapult_group.spin_for(FORWARD, 1350, DEGREES)

motor.spin_to_position()#

The motor.spin_to(angle, units, wait) command is used to spin a motor to a given position.

This is can be a non-waiting or waiting command depending on if the wait parameter is used.

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.spin_for(angle, units, wait).

对象

描述

intake_motor

旋转 Swish 的进气口来收集球并将它们放在弹射器上。

catapult_group

升高或降低 Swish 的弹射器来发射球。

参数

描述

角度

电机旋转的特定角度或圈数。

单位

The units that the motor will use: DEGREES or TURNS.

等待

Optional. The wait parameter determines whether the command will block subsequent commands (wait=True) or allow immediate execution (wait=False). If unspecified, the default for the wait parameter is wait=True.

**返回:**无。

# Launch the Ball currently loaded on the Catapult.
catapult_group.spin_to_position(-90, DEGREES)

# Lower the Catapult to prepare to load another Ball.
catapult_group.spin_to_position(1260, DEGREES)

motor.stop()#

The motor.stop() command is used to stop a motor.

这是一个非等待命令,允许任何后续命令无延迟地执行。

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.stop().

对象

描述

intake_motor

旋转 Swish 的进气口来收集球并将它们放在弹射器上。

catapult_group

升高或降低 Swish 的弹射器来发射球。

**返回:**无。

# Spin the Intake Motor to bring a Ball onto the Catapult.
intake_motor.spin(FORWARD)

wait(2, SECONDS)
intake_motor.stop

motor.set_position()#

The motor.set_position(position, units) command is used to set a motor’s encoder position to the given position value.

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.set_position(position, units).

对象

描述

intake_motor

旋转 Swish 的进气口来收集球并将它们放在弹射器上。

catapult_group

升高或降低 Swish 的弹射器来发射球。

参数

描述

位置

要设置的电机编码器的具体整数。

单位

The units for the motor to use: DEGREES or TURNS.

**返回:**无。

# Launch the Ball currently loaded on the Catapult.
catapult_group.spin_for(REVERSE, 5, DEGREES)

# Lower the Catapult to prepare to load another Ball.
catapult_group.spin_to_position(1260, DEGREES)

# Set the new Catapult position to be 0 degrees.
catapult_group.set_position(0, DEGREES)

motor.set_velocity()#

The motor.set_velocity(velocity, units) command is used to set the speed of a motor.

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.set_velocity(velocity, units).

对象

描述

intake_motor

旋转 Swish 的进气口来收集球并将它们放在弹射器上。

catapult_group

升高或降低 Swish 的弹射器来发射球。

参数

描述

速度

电机旋转的速度,范围从 -100 到 100。

单位

The unit for the Motor’s velocity, PERCENT.

**返回:**无。

# Start spinning the Intake Motor to prepare
# for picking up a Ball.
intake_motor.set_velocity(100, PERCENT)
intake_motor.spin(FORWARD)

motor.set_timeout()#

The motor.set_timeout(value, units) command is used to set a time limit for a motor’s movement commands.

这可以防止未到达预定位置的运动命令阻止后续命令运行。

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.set_timeout(value, units).

对象

描述

intake_motor

旋转 Swish 的进气口来收集球并将它们放在弹射器上。

catapult_group

升高或降低 Swish 的弹射器来发射球。

参数

描述

价值

电机停止前等待的时间。

单位

The unit for the Motor’s timer, SECONDS.

**返回:**无。

catapult_group.set_timeout(2, SECONDS)

# Lower the Catapult to prepare to load another Ball.
catapult_group.spin_for(6, TURNS)

活动#

intake_optical.object_detected()#

intake_optical.object_detected(callback) is the same command as eye.object_detected(callback).

The command only uses Swish’s Optical Sensor intake_optical to replace eye in the standard command.

For information on how to use the eye.object_detected(callback) command, go to its API documentation here.

intake_optical.object_lost()#

intake_optical.object_lost(callback) is the same command as eye.object_lost(callback).

The command only uses Swish’s Optical Sensor intake_optical to replace eye in the standard command.

For information on how to use the eye.object_lost(callback) command, go to its API documentation here.

传感#

motor.is_done()#

The motor.is_done() command is used to return a True or False value if the selected motor has completed its movement.

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.is_done().

对象

描述

intake_motor

旋转 Swish 的进气口来收集球并将它们放在弹射器上。

catapult_group

升高或降低 Swish 的弹射器来发射球。

**返回:**这将返回一个布尔值。

motor.is_spinning()#

The motor.is_spinning() command is used to return a True or False value if the selected motor is moving.

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.is_spinning().

对象

描述

intake_motor

旋转 Swish 的进气口来收集球并将它们放在弹射器上。

catapult_group

升高或降低 Swish 的弹射器来发射球。

**返回:**这将返回一个布尔值。

motor.position()#

The motor.position(units) command is used to return the current rotational position of the selected motor.

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.position(units).

对象

描述

intake_motor

旋转 Swish 的进气口来收集球并将它们放在弹射器上。

catapult_group

升高或降低 Swish 的弹射器来发射球。

参数

描述

单位

The unit of the returned value, DEGREES or TURNS.

**返回:**这将返回一个数值。

# Lower the Catapult to prepare to load another Ball.
while not catapult_group.position(DEGREES) == 1260:
    catapult_group.spin(FORWARD)

motor.velocity()#

The motor.velocity(units) command is used to return the current velocity of the selected motor.

To use this command, replace motor with the desired motor or motor group, for example: intake_motor.velocity(units).

对象

描述

intake_motor

旋转 Swish 的进气口来收集球并将它们放在弹射器上。

catapult_group

升高或降低 Swish 的弹射器来发射球。

参数

描述

单位

The unit of the motor’s velocity, PERCENT.

**返回:**这将返回一个数值。

brain.screen.print(catapult_group.velocity(PERCENT))

intake_optical.is_near_object()#

The intake_optical.near_object() command is used to report a Boolean value if the Optical Sensor is close enough to a Ball to detect it.

这是一个非等待命令,允许任何后续命令无延迟地执行。

**返回:**报告一个布尔值。

# Launch a loaded Ball once the Intake Optical Sensor
# detects a Ball in the Intake.
if intake_optical.is_near_object():
    catapult_group.spin_for(REVERSE, 5, DEGREES)

intake_optical.color()#

The intake_optical.color() command is used to return the color detected by the Intake Optical Sensor.

以下颜色可用于与检测到的颜色进行比较:

  • RED

  • GREEN

  • BLUE

  • YELLOW

  • ORANGE

  • PURPLE

  • CYAN

**返回:**以字符串形式返回检测到的颜色的名称。

# Launch a loaded Ball once the Intake Optical Sensor
# detects a Ball in the Intake.
if intake_optical.color() == YELLOW:
    catapult_group.spin_for(REVERSE, 5, DEGREES)

intake_optical.brightness()#

The intake_optical.brightness() command is used to report the amount of light detected by an Optical Sensor within a range of 0 to 100 percent.

**返回:**这将返回一个数值。

# Launch a loaded Ball once the Intake Optical Sensor
# detects a Ball in the Intake.
if intake_optical.brightness() > 0:
    catapult_group.spin_for(REVERSE, 5, DEGREES)

intake_optical.hue()#

The intake_optical.brightness() command is used to report the hue of the object detected by an Optical Sensor within a range of 0 to 359. This number represents the location of the detected color on a color wheel.

**返回:**这将返回一个数值。

# Launch a loaded Ball once the Intake Optical Sensor
# detects a Ball in the Intake.
if intake_optical.hue() > 100:
    catapult_group.spin_for(REVERSE, 5, DEGREES)