安慰#

介绍#

VEXcode CTE 控制台显示在 VEXcode 的监视器窗口中。它允许您实时显示文本、接收输入、监视变量和传感器,以及格式化打印数据。

Note: The Console is only available when a Brain has been constructed with brain = Brain(), as all Console output is driven through methods on the Brain instance.

This page uses brain as the example Brain name. Replace it with your own configured name as needed.

以下是所有方法的列表:

打印 — 与控制台交互。

  • print — Print text to the console.

  • new_line — Move the console cursor position at the start of the next row down.

  • clear — Clear all text from the console.

  • set_print_color — Set the color text will display in for the console.

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

打印#

print#

print prints values in the console using the current cursor position.

Usage:
brain.print(value, end)

参数

描述

value

要打印到控制台的字符串(用引号括起来)或数字。

end

Optional. By default, Python will add a new line after each print command. To print multiple values to the same line, use the end parameter.

# Print a greeting
brain.print("Hello there!")

new_line#

new_line moves the cursor to the start of the row below the current position in the console.

Usage:
brain.new_line()

参数

描述

此方法没有参数。

# Print on two lines
brain.print("Line 1")
brain.new_line()
brain.print("Line 2")

set_print_color#

set_print_color sets the color used when printing text to the console.

Usage:
brain.set_print_color(color)

参数

描述

color

The color to print text with:

  • BLACK
  • BLUE
  • GREEN
  • RED

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

clear#

clear clears all text from the console.

Usage:
brain.clear()

参数

描述

此方法没有参数。

# Clear the console after printing
brain.print("This will disappear...")
wait(2, SECONDS)
brain.clear()

监视器#

monitor_variable#

monitor_variable adds a predefined variable to be monitored in the Monitor tab of VEXcode.

Usage:
monitor_variable(“variable”)

参数

描述

variable

要监视的预定义变量的名称,以字符串形式给出。

# Monitor the amount of loops
global loops
monitor_variable("loops")

# Move in a square 3 times
for loops in range(12):
    arm.move_inc(100, 0, 0)
    arm.move_inc(0, 100, 0)
    arm.move_inc(-100, 0, 0)
    arm.move_inc(0, 100, 0)

actions = 0
# Monitor the amount of loops and actions
global loops, actions
monitor_variable("loops", "actions")

# Move in a square 3 times
for loops in range(12):
    arm.move_inc(100, 0, 0)
    arm.move_inc(0, 100, 0)
    arm.move_inc(-100, 0, 0)
    arm.move_inc(0, 100, 0)
    actions = actions + 4

monitor_sensor#

monitor_sensor adds a sensor value to be monitored in the Monitor tab of VEXcode.

Usage:
monitor_sensor(“sensor”)

参数

描述

sensor

Which sensor to monitor, given as a string:

  • arm.is_done
  • arm.get_x
  • arm.get_y
  • arm.get_z
  • arm.get_pitch
  • arm.get_roll
  • arm.get_yaw
  • arm.can_arm_reach_to
  • arm.can_arm_reach_inc
  • arm.can_end_effector_reach_to
  • arm.get_end_effector_reach_inc

# Monitor the x-axis in the Monitor tab
monitor_sensor("arm.get_x")
arm.move_to(40, 140, 210)

# Monitor the x-, y-, and z-axes in the Monitor tab
monitor_sensor("arm.get_x", "arm.get_y", "arm.get_z")
arm.move_inc(100, 0, 0)
arm.move_inc(0, 100, 0)
arm.move_inc(-100, 0, 0)
arm.move_inc(0, 100, 0)