安慰#

介绍#

VEXcode VR 包含一个监视器选项卡,可以在项目运行时显示控制台输出、监视变量和监视传感器值。

控制台方法可以显示文本、数字和变量值。它们还可以将控制台光标移动到新的一行、清除控制台以及设置更改颜色后打印文本的颜色。

以下是所有方法的列表:

打印 — 输出文本或清除控制台。

  • print — 在控制台中显示文本、数字或变量值。

  • new_line — 将控制台光标移动到下一行的开头。

  • set_print_color — 设置控制台中打印文本的颜色。

  • clear — 清除控制台中的所有行。

监控 — 在 VEXcode 的“监控”选项卡中,监控项目期间传感器或变量的值。

  • monitor_variable — 向“监视器”选项卡添加一个或多个预定义变量。

  • monitor_sensor — 向监视器选项卡添加一个或多个传感器值。

打印#

print#

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

如果您希望打印消息中包含项目中的值(例如分数、计时器或传感器读数),请使用自定义字符串格式。有关更多信息,请参阅字符串格式页面。

当您希望下一个打印值从新的一行开始时,请使用 new_line。

Usage:
brain.print(value, precision)

参数

描述

value

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

precision

可选。打印数字时显示的小数位数。默认值为 0,因此数字不显示小数位。

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

# VR threads — Do not delete
vr_thread(main)

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

def main():
    # Print a number with 5 decimal places
    brain.print(math.pi, precision=5)

# VR threads — Do not delete
vr_thread(main)

new_line#

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

当您希望下一个打印值从新的一行开始时,请使用此方法。

Usage:
brain.new_line()

参数

描述

此方法没有参数。

def main():
    # Print on two lines
    brain.print("Row 1")
    brain.new_line()
    brain.print("Row 2")

# VR threads — Do not delete
vr_thread(main)

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

set_print_color#

set_print_color 设置使用此方法后控制台中打印的文本颜色。在项目开始时,控制台文本颜色设置为 BLACK。

Usage:
brain.set_print_color(color)

参数

描述

color

控制台打印文本的颜色:

  • BLACK
  • BLUE
  • GREEN
  • RED

def main():
    # Print text in different colors
    brain.print("Default text color")
    brain.new_line()
    brain.set_print_color(RED)
    brain.print("Red text color")

# VR threads — Do not delete
vr_thread(main)

VEXcode 控制台,显示控制台和黑色文字“默认文本颜色”(第一行),红色文字“红色文本颜色”(第二行)。

clear#

clear 清除控制台中的所有行。

Usage:
brain.clear()

参数

描述

此方法没有参数。

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

# VR threads — Do not delete
vr_thread(main)

监视器#

monitor_variable#

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

Variables must be global for monitor_variable to monitor them successfully. Provide each variable name as a string.

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)

actions = 0

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

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

# VR threads — Do not delete
vr_thread(main)

monitor_sensor#

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

如果传感器可以以不同的单位返回数据,“监控”选项卡将显示以每种可用单位返回的数据。请以字符串形式提供每个传感器值。

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

参数

描述

sensor

要监测的传感器值,以字符串形式给出。要监测多个传感器值,请用逗号分隔每个传感器值。这可以是任何返回值的传感器方法,例如 “drivetrain.rotation”。

def main():
    # Monitor the distance in MM and inches
    monitor_sensor("front_distance.get_distance")
    drivetrain.drive_for(FORWARD, 400, MM)

# VR threads — Do not delete
vr_thread(main)

def main():
    # Monitor the rotation in the Monitor tab
    monitor_sensor("drivetrain.rotation", "drivetrain.heading")
    drivetrain.turn_for(RIGHT, 450, DEGREES)

# VR threads — Do not delete
vr_thread(main)