外观#

笔#

pen.move#

pen.move(action) 方法用于设置 VR Pen 的位置。

这是一种非等待方法,允许任何后续方法无延迟地执行。

参数

描述

action

VR笔的设置位置为 UP 或 DOWN。

返回:无。

  • UP - 这支笔无法在操场上画线。

  • DOWN - 这支笔会在操场上画一条彩色的线。

def main():
    # Position the VR Pen down.
    pen.move(DOWN)
    # Move forward for 400 mm to draw a line.
    drivetrain.drive_for(FORWARD, 400, MM)

pen.set_pen_color#

pen.set_pen_color(color) 方法用于设置 VR 笔的颜色。

这是一种非等待方法,允许任何后续方法无延迟地执行。

参数

描述

color

The color of the VR Pen: BLACK, RED, GREEN, or BLUE.

返回:无。

def main():
    # Move the VR Pen down.
    pen.move(DOWN)
    # Set the VR Pen color to blue.
    pen.set_pen_color(BLUE)
    # Drive forward for 400 mm to draw a line.
    drivetrain.drive_for(FORWARD, 400, MM)

pen.set_pen_width#

pen.set_pen_width(width) 方法用于设置 VR Pen 的宽度。

这是一种非等待方法,允许任何后续方法无延迟地执行。

参数

描述

width

VR笔的宽度: EXTRA_THIN THIN MEDIUM宽 WIDE或 EXTRA-WIDE。

返回:无。

默认的 VR 笔宽度为 THIN。

def main():
    # Move the VR Pen down.
    pen.move(DOWN)
    # Set the VR Pen's width to medium.
    pen.set_pen_width(MEDIUM)
    # Drive forward for 400 mm to draw a line.
    drivetrain.drive_for(FORWARD, 400, MM)

pen.set_pen_color_rgb#

pen.set_pen_color_rgb(red, green, blue, opacity) 方法用于设置 VR 笔颜色的 RGB 值。

这是一种非等待方法,允许任何后续方法无延迟地执行。

参数

描述

red

RGB 值中红色的强度,范围从 0 到 255。

green

RGB 值中绿色的强度,范围从 0 到 255。

blue

RGB 值中蓝色的强度,范围从 0 到 255。

opacity

VR Pen 颜色的透明度,范围从 0 到 100%。

返回:无。

def main():
    # Move the VR Pen down.
    pen.move(DOWN)
    # Set the color to orange at full opacity.
    pen.set_pen_color_rgb(225, 112, 52, 100)
    # Drive forward for 400 MM to draw a line.
    drivetrain.drive_for(FORWARD, 400, MM)

pen.fill#

pen.fill(red, green, blue, opacity) 方法会填充 VR 笔所在物体的形状,例如:

​VR 机器人位于一个带有小网格的表面上,机器人后面可以看到一条蓝色的网格线。

​VR 游乐场的一角,图中显示了蓝色填充的角落网格方格,旁边方格内是 VR 机器人。

​一个虚拟现实机器人站在纯蓝色的地板上。

网格线

网格方块

在没有网格的游乐场上,它填满了整个游乐场地板。

这是一种非等待方法,允许任何后续方法无延迟地执行。

参数

描述

red

RGB 值中红色的强度,范围从 0 到 255。

green

RGB 值中绿色的强度,范围从 0 到 255。

blue

RGB 值中蓝色的强度,范围从 0 到 255。

opacity

VR Pen 颜色的透明度,范围从 0 到 100%。

返回:无。

def main():
    # Fill the playground's floor with blue at full opacity.
    pen.fill(43, 162, 202, 100)

打印#

brain.print#

brain.print(value, precision = 0) 用于将单词、数字和报告的值打印到打印控制台。

这是一种非等待方法,允许任何后续方法无延迟地执行。

参数

描述

value

任何能报告数值的文字、数字或传感器。文字必须用引号括起来: ”。

precision

Optional. The amount of decimals reported from a value from a sensor or variable, from precision = 0-precision = 9. The default print precision is 0.

返回:无。

def main():
    # Print the Drivetrain's current heading in degrees with 2 decimal points.
    brain.print("Drivetrain's heading:",
        drivetrain.heading(DEGREES), precision = 2)

brain.clear#

brain.clear() 方法用于清除打印控制台中的所有行,并将光标重置到第一行。

这是一种非等待方法,允许任何后续方法无延迟地执行。

返回:无。

def main():
    # Print "Project has started."
    brain.print("Project has started.")
    # Wait 3 seconds.
    wait(3, SECONDS)
    # Clear the print console.
    brain.clear()

brain.new_line#

brain.new_line() 方法用于在打印控制台中将光标设置到新行。

这是一种非等待方法,允许任何后续方法无延迟地执行。

返回:无。

def main():
    # Print "Project has started."
    brain.print("Project has started.")
    # Move the cursor to a new line.
    brain.new_line()

brain.set_print_color#

brain.set_print_color(color) 用于设置打印到打印控制台的文本颜色。

这是一种非等待方法,允许任何后续方法无延迟地执行。

参数

描述

color

The color of the text to be printed: BLACK, RED, GREEN, or BLUE. By default, the color is BLACK.

返回:无。

def main():
    # Set the print text color to red.
    brain.set_print_color(RED)
    # Print a message.
    brain.print("This is red!")

监控变量#

monitor_variable(“variable”, …) 方法用于向监视器控制台添加变量,以便可以查看和监视变量的值。

这是一种非等待方法,允许任何后续方法无延迟地执行。

参数

描述

variable

任何先前设置的全局变量。

返回:无。

# Create global variable.
disk_count = 1

def main():
    # Add disk_count to the Monitor Console.
    monitor_variable("disk_count")

监控传感器#

monitor_sensor(“sensor”, …) 方法用于向监视器控制台添加传感器,以便可以监视传感器值。

这是一种非等待方法,允许任何后续方法无延迟地执行。

参数

描述

sensor

任何受支持的传感器标识符。

返回:无。

支持的传感器标识符:

  • brain.timer.time

  • drivetrain.is_done

  • drivetrain.is_moving

  • drivetrain.heading

  • drivetrain.rotation

  • drivetrain.velocity_rpm

  • drivetrain.velocity_percent

  • arm_motor.is_done

  • arm_motor.is_spinning

  • arm_motor.position_degrees

  • arm_motor.position_turns

  • arm_motor.velocity_rpm

  • arm_motor.velocity_percent

  • arm_motor_group.is_done

  • arm_motor_group.is_spinning

  • arm_motor_group.position_degrees

  • arm_motor_group.position_turns

  • arm_motor_group.velocity_rpm

  • arm_motor_group.velocity_percent

  • intake_motor.is_done

  • intake_motor.is_spinning

  • intake_motor.position_degrees

  • intake_motor.position_turns

  • intake_motor.velocity_rpm

  • intake_motor.velocity_percent

  • 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

  • catapult_motor.is_done

  • catapult_motor.is_spinning

  • catapult_motor.position_degrees

  • catapult_motor.position_turns

  • catapult_motor.velocity_rpm

  • catapult_motor.velocity_percent

  • catapult_tension_motor.is_done

  • catapult_tension_motor.is_spinning

  • catapult_tension_motor.position_degrees

  • catapult_tension_motor.position_turns

  • catapult_tension_motor.velocity_rpm

  • catapult_tension_motor.velocity_percent

  • intake_bumper.pressing

  • bumper.pressing

  • front_distance.is_object_detected

  • front_distance.object_distance_mm

  • front_distance.object_distance_inches

  • front_optical.is_near_object

  • front_optical.color

  • front_optical.brightness

  • front_optical.hue

  • color.is_near_object

  • color.color

  • color.brightness

  • color.hue

def main():
    # Add the VR Robot's positional coordinates to the monitor console.
    monitor_sensor("location.position")