外觀#

筆#

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筆顏色的透明度,範圍從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筆顏色的透明度,範圍從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")