Consola#

Introducción#

VEXcode VR cuenta con una pestaña Monitor que permite el seguimiento de variables y sensores, así como la impresión de texto en la consola.

A continuación se muestra una lista de todos los métodos:

Imprimir – Interactuar con la consola.

  • 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.

Monitor: monitoree el valor de un sensor o una variable durante un proyecto en la pestaña Monitor de VEXcode.

Imprimir#

print#

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

Usage:
brain.print(value, precision)

Parámetros

Descripción

value

El valor a imprimir como una cadena o un número.

precision

Opcional. ¿Cuántos decimales se imprimirán? El valor predeterminado es 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()

Parámetros

Descripción

Este método no tiene parámetros.

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)

Parámetros

Descripción

color

The color to print text with:

  • BLACK
  • BLUE
  • GREEN
  • RED
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()

Parámetros

Descripción

Este método no tiene parámetros.

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#

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”, …)

Parámetros

Descripción

variable

El nombre de la variable predefinida a monitorear, dado como una cadena.

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”, …)

Parámetros

Descripción

sensor

Qué sensor monitorear, especificado como una cadena. Puede ser cualquier método de sensor que devuelva un valor (“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)