安慰#
介绍#
VEXcode VR 具有监视器选项卡,允许跟踪变量和传感器,以及向控制台打印文本。
以下是所有方法的列表:
打印 - 与控制台交互。
print– Print text to the Console.new_line– Move the Console cursor position at the start of the next row down.set_print_color– Set the color text will display in for the Console.clear– Clear all text from the Console.
监控 – 在 VEXcode 的“监控”选项卡中,监控项目期间传感器或变量的值。
monitor_variable– Add a predefined variable to the Monitor tab.monitor_sensor– Add a sensor to the Monitor tab.
打印#
print#
print prints values in the console using the current cursor position.
Usage:
brain.print(value, precision)
参数 |
描述 |
|---|---|
|
要打印的值,可以是字符串或数字。 |
|
可选。将打印多少位小数。默认值为 0。 |
def main():
# Display a message in the console
brain.print("Hello, robot!")
# VR threads — Do not delete
vr_thread(main)
def main():
# Print a number with 5 decimals
brain.print(math.pi, precision = 5)
# VR threads — Do not delete
vr_thread(main)
new_line#
new_line moves the cursor to the start of the row below the current position in the Console.
Usage:
brain.new_line()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
# Print on two lines
brain.print("Line 1")
brain.new_line()
brain.print("Line 2")
# VR threads — Do not delete
vr_thread(main)
set_print_color#
set_print_color sets the color used when printing text to the Console.
Usage:
brain.set_print_color(color)
参数 |
描述 |
|---|---|
|
The color to print text with:
|
def main():
# Print in different colors
brain.print("Default text color")
wait(1, SECONDS)
brain.set_print_color(RED)
brain.print("Red text")
# VR threads — Do not delete
vr_thread(main)
clear#
clear clears all text from the Console.
Usage:
brain.clear()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
# Clear the console after printing
brain.print("This will disappear...")
wait(2, SECONDS)
brain.clear()
# VR threads — Do not delete
vr_thread(main)
监视器#
monitor_variable#
monitor_variable adds a predefined variable or variables to be monitored in the Monitor tab of VEXcode. Variables must be global for monitor_variable to successfully monitor variables.
Usage:
monitor_variable(“variable1”, “variable2”, …)
参数 |
描述 |
|---|---|
|
要监视的预定义变量的名称,以字符串形式给出。 |
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 adds a sensor value or values to be monitored in the Monitor tab of VEXcode. If a sensor can return data in different units, the Monitor tab will display the returned data in each available unit.
Usage:
monitor_sensor(“sensor1_id”, “sensor2_id”, …)
参数 |
描述 |
|---|---|
|
要监测的传感器,以字符串形式指定。这可以是任何返回值的传感器方法(例如“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)