机器人专用 Python#

介绍#

英雄机器人 Disco 包括电机组、线路跟踪器、光学传感器和游戏定位系统 (GPS) 传感器。

所有标准的 VEXcode VR 方法都可以在 V5 22-23 Spin Up Playground 中使用。

以下是所有可用的机器人专用方法列表:

驱动系统——控制机器人的移动和转向。

  • 操作

    • drive — 使机器人无限向前或向后移动。

    • drive_for — 使机器人向前或向后移动指定的距离。

    • turn — 使机器人永远向左或向右转弯。

    • turn_for — 使机器人向左或向右旋转指定的度数。

    • turn_to_heading — 将机器人转向 -359 到 359 度之间的特定航向。

    • turn_to_rotation — 将机器人旋转到指定的方向。

    • stop — 停止机器人的运动。

  • 变异因子

  • Getters

    • heading — 返回机器人的当前航向,范围从 0 到 359.99 度。

    • rotation — 返回机器人的当前旋转角度。

    • is_done — 返回机器人是否已完成移动,以布尔值表示。

    • is_moving — 返回机器人是否正在移动,以布尔值表示。

    • velocity — 返回机器人行驶的速度。

运动控制——移动并跟踪机器人的电机组。

  • 操作

    • spin — 使电机组永远正转或反转。

    • spin_for — 使电机组旋转特定距离。

    • spin_to_position — 将电机组旋转到特定位置。

    • stop — 停止电机组旋转。

  • 变异因子

    • set_position — 将电机组的当前位置更改为新值。

    • set_velocity — 告诉电机组旋转的速度。

    • set_timeout — 设置电机组尝试完成动作的时间。

  • Getters

    • is_done — 返回电机组是否已完成移动,以布尔值表示。

    • is_spinning — 返回电机组是否正在旋转,以布尔值表示。

    • position — 返回电机组的当前位置。

    • velocity — 返回电机组的旋转速度。

控制台 – 将信息打印到控制台并监控数值。

感知——利用机器人的各种传感器。

  • 光学的

    • is_near_object – 返回光学传感器是否检测到范围内的物体。

    • color – 返回光学传感器检测到的颜色。

    • brightness – 返回物体反射的光量。

    • hue – 返回光学传感器检测到的色调。

    • object_detected – 注册一个当光学传感器检测到物体时要调用的函数。

    • object_lost – 注册一个当光学传感器丢失物体时要调用的函数。

  • 全球定位系统

    • x_position – 返回场地中 GPS 传感器的当前 x 坐标。

    • y_position – 返回场地中 GPS 传感器的当前 y 坐标。

    • heading – 根据 GPS 传感器的读数(0 到 359 度)返回机器人当前面向的航向。

  • 线路追踪器

本页示例使用 Playground 的默认起始位置。

传动系统#

动力系统控制着VR机器人的行驶和转向。动力系统可以前进或后退、左转或右转、转向特定航向并跟踪其旋转。

行动#

驾驶#

drive 使机器人无限前进或后退。机器人将持续移动,直到收到其他指令,例如转向或停止。

Usage:
drivetrain.drive(direction)

参数

描述

direction

机器人移动方向: FORWARD 或 REVERSE。

def main():
    # Drive forward then stop
    drivetrain.drive(FORWARD)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

驱动#

drive_for 使机器人前进或后退指定距离。程序会等待机器人完成移动后才执行下一行代码。

Usage:
drivetrain.drive_for(direction, distance, units, wait)

参数

描述

direction

机器人移动方向: FORWARD 或 REVERSE。

distance

机器人行驶的距离。这可以是整数 integerfloat)。

units

可选。距离单位: INCHES (默认)或 MM (毫米)。

wait

可选 wait=True (默认值)表示程序会等待机器人完成移动后再运行下一行代码。2 wait=False 表示程序会立即运行下一行代码。

def main():
    # Drive forward and backward
    drivetrain.drive_for(FORWARD, 200, MM)
    drivetrain.drive_for(REVERSE, 200, MM)

# VR threads — Do not delete
vr_thread(main)

转动#

turn 表示机器人无限向左或向右转向。机器人将持续转向,直到收到其他指令,例如行驶或停止。

Usage:
drivetrain.turn(direction)

参数

描述

direction

机器人转向的方向: LEFT 或 RIGHT。

def main():
    # Turn right and left, then stop
    drivetrain.turn(RIGHT)
    wait(2, SECONDS)
    drivetrain.turn(LEFT)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

转弯#

turn_for 参数使机器人向左或向右旋转指定角度。旋转角度是相对于机器人当前位置的。程序会等待机器人完成旋转后才执行下一行代码。

Usage:
drivetrain.turn_for(direction, angle, units, wait)

参数

描述

direction

机器人转向的方向: LEFT 或 RIGHT。

angle

The number of degrees the robot turns. This can be an integer or decimal (float).

units

可选。旋转单位: DEGREES (默认值)。

wait

可选 wait=True (默认值)表示程序会等待机器人完成转向后再运行下一行代码。2 wait=False 表示程序会立即运行下一行代码。

def main():
    # Turn the robot right and left
    drivetrain.turn_for(RIGHT, 90, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_for(LEFT, 90, DEGREES)

# VR threads — Do not delete
vr_thread(main)

转向航向#

航向角是指机器人朝向的方向,以度为单位。`turn_to_heading 将机器人转向 -359 度到 359 度之间的特定航向角。机器人将沿最短路径转向以达到目标航向角。

机器人的初始航向角为0度。

程序会等到机器人完成转向后才运行下一行代码。

Usage:
drivetrain.turn_to_heading(angle, units, wait)

参数

描述

angle

机器人应面向的方向,以度为单位。可以是 integer 的整数,也可以是 -359 到 359 之间的十进制数(float)。

units

可选。旋转单位: DEGREES (默认值)。

wait

可选 wait=True (默认值)表示程序会等待机器人完成转向后再运行下一行代码。2 wait=False 表示程序会立即运行下一行代码。

def main():
    # Turn to face the cardinal directions
    drivetrain.turn_to_heading(90, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(180, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(270, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

转向旋转#

turn_to_rotation 将机器人旋转到指定角度。

旋转角度是指机器人转动的程度,以度为单位。在项目开始时,旋转角度值设置为 0 度。也可以使用 set_rotation 方法设置旋转角度。

旋转角度是绝对值。这意味着转弯方向取决于机器人当前的旋转角度。向右转弯会增加旋转角度,向左转弯会减少旋转角度。

例如,如果机器人从0度开始,你将其旋转720度,它会向右转两次。如果你再将其旋转360度,它会向左转一次,因为360小于720。

程序会等到机器人完成转向后才运行下一行代码。

Usage:
drivetrain.turn_to_rotation(angle, units, wait)

参数

描述

angle

机器人将旋转到的旋转值,以度为单位。这可以是整数 integerfloat)。

units

可选。旋转单位: DEGREES (默认值)。

wait

可选 wait=True (默认值)表示程序会等待机器人完成转向后再运行下一行代码。2 wait=False 表示程序会立即运行下一行代码。

def main():
    # Turn left, then spin in a circle
    # clockwise and face right
    drivetrain.turn_to_rotation(-90, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_rotation(450, DEGREES)

# VR threads — Do not delete
vr_thread(main)

停止#

stop 停止机器人的移动。

Usage:
drivetrain.stop()

参数

描述

此方法没有参数。

def main():
    # Drive forward then stop
    drivetrain.drive(FORWARD)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

变异体#

设置标题#

航向角是指机器人面向的方向,以度为单位。0 set_heading 将机器人的当前航向角更改为新的航向角值。

例如,如果机器人转向右侧,将航向设置为 0 度,则该右侧位置将成为新的 0 度航向。然后,机器人可以根据新的航向转向其他位置。

Usage:
drivetrain.set_heading(heading, units)

参数

描述

heading

The heading value, in degrees, to set for the robot. This can be an integer or decimal (float).

units

可选。航向单位: DEGREES (默认值)。

def main():
    # Face the new 0 degrees
    drivetrain.set_heading(90, DEGREES)
    drivetrain.turn_to_heading(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

设置旋转#

旋转角度是指机器人转动的程度,以度为单位。项目开始时,旋转角度值设置为 0 度。`set_rotation 会将机器人的当前旋转角度更改为新值。

例如,如果机器人向右转了两圈,它的旋转角度将为 720 度。将旋转角度设置为 0 度会将旋转角度从 720 度重置为 0 度。然后,机器人可以根据这个新的旋转角度进行旋转。

Usage:
drivetrain.set_rotation(rotation, units)

参数

描述

rotation

要设置的机器人旋转值,以度为单位。这可以是整数 integerfloat)。

units

可选。旋转单位: DEGREES (默认值)。

def main():
    # Spin counterclockwise two times
    drivetrain.set_rotation(720, DEGREES)
    drivetrain.turn_to_rotation(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

设置超时#

set_timeout 设置机器人尝试完成一个动作的超时时间。如果机器人无法在规定时间内完成,它将停止尝试并执行下一行代码。这可以防止机器人卡在某个动作上。

Usage:
drivetrain.set_timeout(value, units)

参数

描述

value

The amount of time the robot can try to finish a movement. This can be a positive integer or decimal (float).

units

时间单位: SECONDS 或 MSEC (毫秒)。

def main():
    # Turn right after driving forward
    drivetrain.set_timeout(1, SECONDS)
    drivetrain.drive_for(FORWARD, 25, INCHES)
    drivetrain.turn_for(RIGHT, 90)

# VR threads — Do not delete
vr_thread(main)

设置驱动速度#

set_drive_velocity 告诉机器人行驶速度。百分比越高,机器人行驶速度越快;百分比越低,机器人行驶速度越慢。

每个项目开始时,机器人默认以 50% 的速度行驶。

注意:速度越高,机器人行驶速度越快,但精度可能越低;速度越低,机器人行驶速度越慢,但精度可能越高。

Usage:
drivetrain.set_drive_velocity(velocity, units)

参数

描述

velocity

行驶速度,范围从 0% 到 100%。可以是整数 integerfloat)。

units

可选。速度单位: PERCENT (默认值)。

def main():
    # Drive forward at different velocities
    # Default velocity
    drivetrain.drive_for(FORWARD, 150, MM)
    wait(1, SECONDS)
    # Drive slower
    drivetrain.set_drive_velocity(20, PERCENT)
    drivetrain.drive_for(FORWARD, 150, MM)
    wait(1, SECONDS)
    # Drive faster
    drivetrain.set_drive_velocity(100, PERCENT)
    drivetrain.drive_for(FORWARD, 150, MM)

# VR threads — Do not delete
vr_thread(main)

设置转弯速度#

set_turn_velocity 告诉机器人转弯的速度。百分比越高,机器人转弯越快;百分比越低,机器人转弯越慢。

每个项目开始时,机器人默认以 50% 的速度旋转。

注意:速度越高,机器人转弯越快,但精度可能越低;速度越低,机器人转弯越慢,但精度可能越高。

Usage:
drivetrain.set_turn_velocity(velocity, units)

参数

描述

velocity

转弯速度,范围从 0% 到 100%。可以是整数 integerfloat)。

units

可选。速度单位: PERCENT (默认值)。

def main():
    # Turn at different velocities
    # Default velocity
    drivetrain.turn_for(RIGHT, 120, DEGREES)
    wait(1, SECONDS)
    # Turn slower
    drivetrain.set_turn_velocity(20, PERCENT)
    drivetrain.turn_for(RIGHT, 120, DEGREES)
    wait(1, SECONDS)
    # Turn faster
    drivetrain.set_turn_velocity(100, PERCENT)
    drivetrain.turn_for(RIGHT, 120, DEGREES)

# VR threads — Do not delete
vr_thread(main)

获取器#

标题#

A heading is the direction the robot is facing, measured in degrees. heading returns the robot’s current heading from 0 to 359.99 degrees.

机器人的初始航向角为0度。

Usage:
drivetrain.heading(units)

参数

描述

units

可选。航向单位: DEGREES (默认值)。

def main():
    # Display the heading after turning
    drivetrain.turn_for(RIGHT, 450, DEGREES)
    brain.screen.print("Heading: ")
    brain.screen.print(drivetrain.heading(DEGREES))

# VR threads — Do not delete
vr_thread(main)

旋转#

Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. rotation returns the robot’s current rotation.

向右转会增加旋转角度,向左转会减少旋转角度。例如,向右转两圈将得到 720 度的旋转角度。

Usage:
drivetrain.rotation(units)

参数

描述

units

可选。旋转单位: DEGREES (默认值)。

def main():
    # Display the rotation after turning
    drivetrain.turn_for(RIGHT, 450, DEGREES)
    brain.screen.print("Rotation: ")
    brain.screen.print(drivetrain.rotation(DEGREES))

# VR threads — Do not delete
vr_thread(main)

已完成#

is_done 返回机器人是否已完成移动,返回值为布尔值。这可用于根据机器人的移动状态控制其他行为的执行时间。

  • True — 机器人已停止移动。

  • False ​​— 机器人仍在移动。

此方法与以下具有 wait 参数的传动系统方法配合使用:drive_for, turn_for, turn_to_heading, 和 turn_to_rotation。

Usage:
drivetrain.is_done()

参数

描述

此方法没有参数。

正在移动#

is_moving 返回机器人是否正在移动,返回值为布尔值。这可用于根据机器人的移动状态控制其他行为的执行时间。

  • True — 机器人正在移动。

  • False ​​— 机器人没有移动。

Usage:
drivetrain.is_moving()

参数

描述

此方法没有参数。

速度#

velocity 返回机器人行驶的速度,以 -100% 到 100% 的百分比表示。

Usage:
drivetrain.velocity(units)

参数

描述

units

可选。速度单位: PERCENT (默认值)。

例子

def main():
    # Display the velocity after driving
    drivetrain.drive_for(FORWARD, 150, MM)
    brain.screen.print("Velocity: ")
    brain.screen.print(drivetrain.velocity(PERCENT))

运动#

迪斯科利用进料电机组带动进料轮旋转,以便收集和计分圆盘。这些进料轮在接触到场辊时,也能带动场辊旋转。

方向说明解释了每个方向如何移动发现者上的进气电机组。

行动#

旋转#

spin 表示电机组正转或反转永不停歇。电机组将持续旋转,直到收到其他指令,例如改变旋转方向或停止。

Usage:
intake_motor_group.spin(direction)

参数

描述

direction

The direction the motor group spins:

  • FORWARD — Spins in the intake direction.
  • REVERSE — Spins in the outtake direction.

def main():
    # Spin the intake forward then stop
    intake_motor_group.spin(FORWARD)
    wait(0.5, SECONDS)
    intake_motor_group.stop()

# VR threads — Do not delete
vr_thread(main)

spin_for#

spin_for 会使电机组旋转指定距离。旋转距离是相对于电机组的当前位置而言的。程序会等待电机组旋转完毕后再执行下一行代码。

Usage:
intake_motor_group.spin_for(direction, distance, units, wait)

参数

描述

direction

The direction the motor group spins:

  • FORWARD — Spins in the intake direction.
  • REVERSE — Spins in the outtake direction.

distance

电机组旋转的距离。0 度 DEGREES 使用整数。2 圈 TURNS 可以使用整数或小数。

units

可选。距离单位: DEGREES (默认)或 TURNS。

wait

Optional.

  • wait=True (default) — Makes the project wait until the motor group is done spinning before the next line of code runs.
  • wait=False — Makes the next line of code run right away.

def main():
    # Spin the intake forward then stop
    intake_motor_group.spin_for(FORWARD, 360, DEGREES)

# VR threads — Do not delete
vr_thread(main)

自旋至位置#

spin_to_position 将电机组旋转到特定位置。

电机组的位置是指其旋转的距离,以 DEGREES 或 TURNS来衡量。一圈等于 360 度。在项目开始时,电机组的位置设置为 0 度。也可以使用 set_position 方法设置电机组的位置。

位置值是绝对值。这意味着旋转方向取决于电机组的当前位置。

例如,如果电机组从 0 度开始旋转到 720 度,它将正转两圈。如果之后它旋转到 360 度,它将反转一圈,因为 360 小于 720。

Usage:
intake_motor_group.spin_to_position(angle, units, wait)

参数

描述

angle

电机组将旋转到的位置值。0 度 DEGREES 使用整数。2 圈 TURNS 可以使用整数或小数。

units

可选。位置单位: DEGREES (默认)或 TURNS。

wait

Optional.

  • wait=True (default) — Makes the project wait until the motor group is done spinning before the next line of code runs.
  • wait=False — Makes the next line of code run right away.

def main():
    # Spin the intake forward then stop
    intake_motor_group.spin_to_position(55, DEGREES)

# VR threads — Do not delete
vr_thread(main)

停止#

stop 停止电机组旋转。

Usage:
intake_motor_group.stop()

参数

描述

此方法没有参数。

def main():
    # Spin the intake forward then stop
    intake_motor_group.spin(FORWARD)
    wait(0.5, SECONDS)
    intake_motor_group.stop()

# VR threads — Do not delete
vr_thread(main)

变异体#

设置位置#

电机组的位置是指它旋转的距离,以 DEGREES 或 TURNS测量。 set_position 用于将电机组的当前位置更改为新值。

例如,如果一个电机组旋转了 180 度,将其位置设置为 0 度会将该位置从 180 度重置为 0 度。然后,该电机组可以根据这个新值旋转到相应的位置。

Usage:
intake_motor_group.set_position(position, units)

参数

描述

position

电机组的位置值设置。0 度 DEGREES 使用整数。2 圈 TURNS 可以使用整数或小数。

units

可选。位置单位: DEGREES (默认)或 TURNS。

def main():
    # Spin the intake forward then stop
    intake_motor_group.set_position(90, DEGREES)
    intake_motor_group.spin_to_position(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

设置速度#

set_velocity 告诉电机组的旋转速度。百分比越高,电机组旋转速度越快;百分比越低,电机组旋转速度越慢。

每个项目开始时,每个电机组默认以 50% 的速度旋转。

注意:更高的速度会使电机组旋转得更快,但精度可能会降低。更低的速度会使电机组旋转得更慢,但精度可能会更高。

Usage:
intake_motor_group.set_velocity(velocity, units)

参数

描述

velocity

旋转速度,范围从 0% 到 100%。可以是整数 integerfloat)。

units

速度单位: PERCENT。

def main():
    # Spin the intake forward then stop
    intake_motor_group.set_velocity(75, PERCENT)
    intake_motor_group.spin_to_position(180, DEGREES)

# VR threads — Do not delete
vr_thread(main)

设置超时#

set_timeout 设置电机组尝试完成动作的超时时间。如果电机组无法在规定时间内完成动作,它将停止尝试并执行下一行代码。这可以防止电机组卡在某个动作上。

Usage:
intake_motor_group.set_timeout(value, units)

参数

描述

value

The amount of time the motor group can try to finish a movement. This can be a positive integer or decimal (float).

units

时间单位: SECONDS 或 MSEC (毫秒)。

def main():
    # Spin the intake forward then stop
    intake_motor_group.set_timeout(2, SECONDS)
    intake_motor_group.spin_to_position(270, DEGREES)

# VR threads — Do not delete
vr_thread(main)

获取器#

已完成#

is_done 返回运动组是否已完成运动,返回值为布尔值。这可用于根据运动组的运动状态来控制其他行为的执行时间。

  • True — 电机组运动完毕。

  • False ​​— 运动组仍在运动。

此方法与以下具有 wait 参数的 Motion 方法配合使用:spin_for 和 spin_to_position。

Usage:
intake_motor_group.is_done()

参数

描述

此方法没有参数。

正在旋转#

is_spinning 返回电机组是否正在旋转,返回值为布尔值。这可用于根据电机组的运动状态控制其他行为的执行时间。

  • True — 电机组正在旋转。

  • False ​​— 电机组不旋转。

此方法与以下具有 wait 参数的 Motion 方法配合使用:spin_for 和 spin_to_position。

Usage:
intake_motor_group.is_spinning()

参数

描述

此方法没有参数。

位置#

A motor group’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. position returns the motor group’s current position.

项目开始时,电机组位置设置为 0 度。如果电机组向前旋转一整圈,则位置为 360 度或 1 圈。如果电机组向反方向旋转,则位置为负值。

Usage:
intake_motor_group.position(units)

参数

描述

units

将电机组位置恢复到: DEGREES 或 TURNS。

速度#

速度velocity 旋转速度。

正值表示电机组正向旋转,负值表示电机组反向旋转。

Usage:
intake_motor_group.velocity(units)

参数

描述

units

要返回的速度单位: PERCENT。

安慰#

项目运行时,控制台会显示文本、数字和变量值。控制台方法还可以将光标移动到新行、清除控制台以及向“监视器”选项卡添加变量或传感器值。

打印#

脑屏幕打印#

brain.screen.print 使用当前光标位置在控制台中显示文本、数字或变量值。

当您希望下一个打印值从新行开始时,请使用 brain.screen.next_row。

Usage:
brain.screen.print(value)

参数

描述

value

要在控制台中显示的文本、数字或变量值。

def main():
    # Display a message in the Console
    brain.screen.print("Hello, robot!")

# VR threads — Do not delete
vr_thread(main)

VEXcode 控制台,显示控制台和文本“Hello, robot!”。

brain.screen.下一行#

brain.screen.next_row 将光标移动到控制台下一行的第 1 列。下一个打印的值将显示在该行。

Usage:
brain.screen.next_row()

参数

描述

此方法没有参数。

def main():
    # Print on two rows
    brain.screen.print("Row 1")
    brain.screen.next_row()
    brain.screen.print("Row 2")

# VR threads — Do not delete
vr_thread(main)

VEXcode 控制台,显示控制台,第一行显示文本“第 1 行”,第二行显示文本“第 2 行”。

brain.screen.clear_screen#

brain.screen.clear_screen 清除控制台中的所有行并将光标移回第 1 行。

Usage:
brain.screen.clear_screen()

参数

描述

此方法没有参数。

def main():
    # Display text, then clear it after two seconds
    brain.screen.print("This will disappear...")
    wait(2, SECONDS)
    brain.screen.clear_screen()

# VR threads — Do not delete
vr_thread(main)

监视器#

监控变量#

monitor_variable 将一个或多个预定义变量添加到 VEXcode 的“监视器”选项卡中。这样,您就可以在项目运行时监视变量值的变化。

要成功监控 monitor_variable 变量必须是全局变量。请以字符串形式提供每个变量名。

Usage:
monitor_variable(“variable”)
monitor_variable(“variable1”, “variable2”)

参数

描述

variable

要监控的预定义全局变量的名称,以字符串形式给出。要监控多个变量,请用逗号分隔每个变量名。

def main():
    # Monitor the amount of loops
    global loops
    monitor_variable("loops")

    # Drive in a square 3 times
    for loops in range(12):
        drivetrain.turn_for(RIGHT, 90, DEGREES)
        drivetrain.drive_for(FORWARD, 150, MM)

# VR threads — Do not delete
vr_thread(main)

监控传感器#

monitor_sensor 将一个或多个传感器值添加到 VEXcode 的“监视器”选项卡中。这样,您就可以在项目运行时观察传感器值的变化。

请以字符串形式提供每个传感器的值。

Usage:
monitor_sensor(“sensor”)
monitor_sensor(“sensor1”, “sensor2”)

参数

描述

sensor

The sensor value to monitor, given as a string. To monitor more than one sensor value, separate each sensor value with a comma. Supported sensor identifiers include:

  • Brain
    • brain.timer.time
  • Drivetrain
    • drivetrain.is_done
    • drivetrain.is_moving
    • drivetrain.heading
    • drivetrain.rotation
    • drivetrain.velocity_rpm
    • drivetrain.velocity_percent
  • Intake Motor Group
    • intake_motor_group.is_done
    • intake_motor_group.is_spinning
    • intake_motor_group.position_degrees
    • intake_motor_group.position_turns
    • intake_motor_group.velocity_rpm
    • intake_motor_group.velocity_percent
  • Fork Motor Group
    • fork_motor_group.is_done
    • fork_motor_group.is_spinning
    • fork_motor_group.position_degrees
    • fork_motor_group.position_turns
    • fork_motor_group.velocity_rpm
    • fork_motor_group.velocity_percent
  • Bottom Distance Sensor
    • bottom_distance.is_object_detected
    • bottom_distance.object_distance_mm
    • bottom_distance.object_distance_inches
  • Left Distance Sensor
    • left_distance.is_object_detected
    • left_distance.object_distance_mm
    • left_distance.object_distance_inches
  • Center Distance Sensor
    • center_distance.is_object_detected
    • center_distance.object_distance_mm
    • center_distance.object_distance_inches
  • Right Distance Sensor
    • right_distance.is_object_detected
    • right_distance.object_distance_mm
    • right_distance.object_distance_inches
  • Line Trackers
    • bottom_line_tracker.reflectivity
    • middle_line_tracker.reflectivity
    • top_line_tracker.reflectivity
  • Roller Optical Sensor
    • roller_optical.is_near_object
    • roller_optical.color
    • roller_optical.brightness
    • roller_optical.hue
  • Optical Sensor
    • optical.is_near_object
    • optical.color
    • optical.brightness
    • optical.hue
  • GPS Sensor
    • gps.position_mm
    • gps.position_inches
    • gps.heading
  • Rotation Sensor
    • rotation.angle
    • rotation.position

def main():
    # Monitor the robot's heading
    monitor_sensor("drivetrain.heading")
    drivetrain.turn_for(RIGHT, 450, DEGREES)

# VR threads — Do not delete
vr_thread(main)

传感#

光学的#

靠近对象#

is_near_object 返回一个布尔值,指示光学传感器是否检测到范围内的物体。

  • True – 光学传感器检测到物体。

  • False ​​– 光学传感器未检测到物体。

Usage:
roller_optical.is_near_object()

参数

描述

此方法没有参数。

颜色#

color 返回一个基于检测到的色调值的 ` Color 类的实例。这些实例可以与预定义的 Color 对象进行比较,以创建条件语句。

可选颜色有:

  • NONE

  • RED - 色调值介于 340° 至 20° 之间

  • GREEN - 色调值介于 80° 至 140° 之间

  • BLUE - 色调值介于 200° 至 240° 之间

  • YELLOW - 色调值介于 40° 至 60° 之间

  • ORANGE - 色调值介于 20° 至 40° 之间

  • PURPLE - 色调值介于 240° 至 280° 之间

  • CYAN - 色调值介于 140° 至 200° 之间

注意: 光学传感器正在查找与指定颜色匹配的色调范围。有关检测特定色调范围的信息,请参阅 hue。

Usage:
roller_optical.color()

参数

描述

此方法没有参数。

亮度#

brightness 返回物体反射的光量,以百分比表示的十进制数 (float)。

百分比越高,意味着反射回光学传感器的光线越多;百分比越低,意味着反射回的光线越少。

Usage:
roller_optical.brightness()

参数

描述

此方法没有参数。

色调#

hue 返回检测到的颜色的色调值,以 0 到 359 之间的十进制数 (float) 表示。

色相是用色轮上的数字来描述颜色的一种方法。

一个圆形色轮,显示完整的色调光谱,边缘标有度数,从顶部的 0° 到 360°,以 30° 为增量递增。

Usage:
roller_optical.hue()

参数

描述

此方法没有参数。

检测到目标#

object_detected 注册一个函数,当光学传感器检测到新物体时,该函数将被调用。

Usage:
roller_optical.object_detected(callback, arg)

参数

描述

callback

先前定义的 函数,当光学传感器检测到新物体时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅使用带参数的函数。

丢失对象#

object_lost 注册一个函数,当光学传感器丢失检测到的对象时,该函数将被调用。

Usage:
roller_optical.object_lost(callback, arg)

参数

描述

callback

先前定义的 函数,当光学传感器丢失检测到的对象时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅使用带参数的函数。

全球定位系统#

x_position#

x_position 返回场上 GPS(游戏定位系统™)传感器的当前 x 坐标。

Usage:
gps.x_position(units)

参数

描述

单位

偏移值的单位: INCHES 或 MM

y 位置#

y_position 返回场上 GPS(游戏定位系统™)传感器的当前 y 坐标。

Usage:
gps.y_position(units)

参数

描述

单位

偏移值的单位: INCHES 或 MM

标题#

heading 返回机器人当前面向的航向,该航向基于 GPS(游戏定位系统™)传感器的读数,范围为 0 到 359 度。

Usage:
gps.heading()

参数

描述

此方法没有参数。

线路跟踪器#

反射率#

reflectivity 返回一个整数,表示从表面反射的光量(以百分比表示)。

  • 0%反射率意味着物体非常暗。

  • 100%反射率意味着物体非常明亮。

用法:
此方法可以使用以下三个可用的 line_tracker 对象之一:

线路跟踪器

命令

top_line_tracker

top_line_tracker.reflectivity(units) — 顶级追踪器

middle_line_tracker

middle_line_tracker.reflectivity(units) — 中线追踪器

bottom_line_tracker

bottom_line_tracker.reflectivity(units) — 底线追踪器

范围

描述

单位

可选。反射率的单位:

  • PERCENT (默认)