机器人专用 Python#

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

运动#

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

旋转快照的进气口以从场地拾取球。

catapult_motor

升起或降低弹射器。

catapult_tension_motor

提高或降低弹射器的张力,影响球被弹射的距离。

参数

描述

方向

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

**返回:**无。

def main():
    # Spin the intake motor forward.
    intake_motor.spin(FORWARD)
    # Wait half a second.
    wait(0.5, SECONDS)
    # Stop spinning the intake motor group.
    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_group.spin_for(direction, distance, units, wait).

对象

描述

intake_motor

旋转快照的进气口以从场地拾取球。

catapult_motor

升起或降低弹射器。

catapult_tension_motor

提高或降低弹射器的张力,影响球被弹射的距离。

参数

描述

方向

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.

**返回:**无。

def main():
    # Spin the intake motor forward for 1 turn.
    intake_motor.spin_for(FORWARD, 1, TURNS)

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_group.spin_for(angle, units, wait).

对象

描述

intake_motor

旋转快照的进气口以从场地拾取球。

catapult_motor

升起或降低弹射器。

catapult_tension_motor

提高或降低弹射器的张力,影响球被弹射的距离。

参数

描述

角度

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

单位

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.

**返回:**无。

def main():
    # Spin the intake motor to 55 degrees.
    intake_motor.spin_to_position(55, 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_group.stop().

对象

描述

intake_motor

旋转快照的进气口以从场地拾取球。

catapult_motor

升起或降低弹射器。

catapult_tension_motor

提高或降低弹射器的张力,影响球被弹射的距离。

**返回:**无。

def main():
    # Spin the intake motor forward.
    intake_motor.spin(FORWARD)
    # Wait one second.
    wait(1, SECONDS)
    # Stop spinning the intake motor group.
    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_group.set_position(position, units).

对象

描述

intake_motor

旋转快照的进气口以从场地拾取球。

catapult_motor

升起或降低弹射器。

catapult_tension_motor

提高或降低弹射器的张力,影响球被弹射的距离。

参数

描述

位置

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

单位

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

**返回:**无。

def main():
    # Set the current motor position to 90 degrees.
    intake_motor.set_position(90, DEGREES)
    # Spin the intake motor back to 0 degrees.
    intake_motor.spin_to_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_group.set_velocity(velocity, units).

对象

描述

intake_motor

旋转快照的进气口以从场地拾取球。

catapult_motor

升起或降低弹射器。

catapult_tension_motor

提高或降低弹射器的张力,影响球被弹射的距离。

参数

描述

速度

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

单位

The unit for the Motor’s velocity, PERCENT.

**返回:**无。

def main():
    # Set the intake motor velocity to 75 percent.
    intake_motor.set_velocity(75, PERCENT)
    # Spin the intake motor to 180 degrees.
    intake_motor.spin_to_position(180, DEGREES)

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_group.set_timeout(value, units).

对象

描述

intake_motor

旋转快照的进气口以从场地拾取球。

catapult_motor

升起或降低弹射器。

catapult_tension_motor

提高或降低弹射器的张力,影响球被弹射的距离。

参数

描述

价值

电机停止前等待的时间。

单位

The unit for the Motor’s timer, SECONDS.

**返回:**无。

def main():
    # Set the intake motor's timeout to 2 seconds.
    intake_motor.set_timeout(2, SECONDS)
    # Spin the intake motor to 270 degrees.
    intake_motor.spin_to_position(270, DEGREES)

活动#

intake_bumper.pressed()#

intake_bumper.pressed(callback) is the same command as bumper.pressed(callback).

The command only uses Fling’s specific bumper sensor intake_bumper to replace bumper in the standard command.

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

intake_bumper.released()#

intake_bumper.released(callback) is the same command as bumper.released(callback).

The command only uses Fling’s specific bumper sensor intake_bumper to replace bumper in the standard command.

For information on how to use the bumper.released(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_group.is_done().

对象

描述

intake_motor

旋转快照的进气口以从场地拾取球。

catapult_motor

升起或降低弹射器。

catapult_tension_motor

提高或降低弹射器的张力,影响球被弹射的距离。

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

def main():
    # Move the Arm so it doesn't block the Front Distance Sensor.
    intake_motor.spin_to_position(1000, DEGREES)
    # Wait until the intake_motor has finished moving.
    if intake_motor.is_done():
        # Print the distance from the Front Distance Sensor to the closest
        # object in front of it.
        brain.screen.print(front_distance.object_distance(MM))

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_group.is_spinning().

对象

描述

intake_motor

旋转快照的进气口以从场地拾取球。

catapult_motor

升起或降低弹射器。

catapult_tension_motor

提高或降低弹射器的张力,影响球被弹射的距离。

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

# Example coming soon.

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_group.position(units).

对象

描述

intake_motor

旋转快照的进气口以从场地拾取球。

catapult_motor

升起或降低弹射器。

catapult_tension_motor

提高或降低弹射器的张力,影响球被弹射的距离。

参数

描述

单位

The unit of the returned value, DEGREES or TURNS.

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

def main():
    # Print the current position of the intake_motor_group in degrees.
    brain.screen.print(intake_motor_group.position(DEGREES))

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_group.velocity(units).

对象

描述

intake_motor

旋转快照的进气口以从场地拾取球。

catapult_motor

升起或降低弹射器。

catapult_tension_motor

提高或降低弹射器的张力,影响球被弹射的距离。

参数

描述

单位

The unit of the motor’s velocity, PERCENT.

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

def main():
    # Print the current velocity of the intake_motor.
    brain.screen.print(intake_motor_group.velocity(PERCENT))

intake_bumper.pressing()#

intake_bumper.pressing() is the same command as bumper.pressing().

The command only uses Fling’s specialized Bumper Sensor intake_bumper to replace bumper in the standard command.

For information on how to use the bumper.pressing() command, go to its API documentation here.

distance.object_distance()#

The distance.object_distance(units) command is used to report the distance of the nearest object from the Distance Sensor.

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

参数

描述

单位

The unit of the reported distance, INCHES or MM (Millimeters).

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

def main():
    # Print the current distance to the nearest object in MM.
    brain.print(distance.object_distance(MM))

distance.is_object_detected()#

The distance.is_object_detected() command is used to report a Boolean value if the Distance sensor sees an object within its field of view.

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

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

def main():
    # Print if the Distance Sensor detects an object in its Field of View.
    brain.print(distance.is_object_detected())

color.is_near_object()#

The color.is_near_object() command is used to report a Boolean value if the Color Sensor is close enough to an object to detect a color.

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

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

def main():
    # Print if the Color Sensor is detecting a color.
    brain.print(color.is_near_object())

color.color()#

The color.color() command is used to return the color detected by a VEX IQ Optical Sensor.

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

以下颜色可用于与 IQ 光学传感器检测到的颜色进行比较:

  • 颜色.RED

  • 颜色.绿色

  • 颜色.蓝色

  • 颜色.黄色

  • 颜色.橙色

  • 颜色.紫色

  • 颜色.青色

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

def main():
    # Print the color of the object that the Front Optical Sensor sees.
    brain.print(color.color())

color.brightness()#

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

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

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

def main():
    # Print the brightness of the object in front of Fling.
    brain.print(color.brightness())

color.hue()#

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

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

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

def main():
    # Print the hue of the object in front of Fling.
    brain.screen.print("Hue: ", optical.hue())