Consola#
Introducción#
The VEXcode GO Console is displayed in the Monitor window within VEXcode. It allows you to display text, receive input, monitor variables and sensors, and format printed data in real time.
A continuación se muestra una lista de todos los métodos:
Actions — Interact with the console.
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.
Mutators — Change the text color in the console.
set_print_color— Set the color text will display in for the console.
Monitor — Monitor a sensor’s or variable’s value during a project in VEXcode’s Monitor tab.
monitor_sensor— Add a sensor to the Monitor tab.monitor_variable— Add a predefined variable to the Monitor tab.
Comportamiento#
print#
print imprime valores en la consola utilizando la posición actual del cursor.
Uso:
console.print(value, precision)
Parámetros |
Descripción |
|---|---|
|
El valor a imprimir como una cadena o un número. |
|
Opcional. Cuántos decimales se imprimirán. El valor predeterminado es 0. |
def main():
# Display a message in the console
console.print("Hello, robot!")
# Start threads — Do not delete
start_thread(main)
def main():
# Print a number with 5 decimals
console.print(math.pi, precision = 5)
# Start threads — Do not delete
start_thread(main)
new_line#
new_line moves the cursor to the start of the row below the current position in the console.
Uso:
console.new_line()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
def main():
# Print on two lines
console.print("Line 1")
console.new_line()
console.print("Line 2")
# Start threads — Do not delete
start_thread(main)
clear#
clear clears all text from the console.
Uso:
console.clear()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
def main():
# Clear the console after printing
console.print("This will disappear...")
wait(2, SECONDS)
console.clear()
# Start threads — Do not delete
start_thread(main)
Mutadores#
set_print_color#
set_print_color sets the color used when printing text to the console.
Uso:
set_print_color(color)
Parámetros |
Descripción |
|---|---|
|
The color to print text with:
|
def main():
# Print in different colors
console.print("Default text color")
console.new_line()
console.set_print_color(RED)
console.print("Red text color")
# Start threads — Do not delete
start_thread(main)
Monitor#
monitor_sensor#
monitor_sensor agrega un valor de sensor para ser monitoreado en la pestaña Monitor de VEXcode.
Uso:
monitor_sensor(“sensor”)
Parámetros |
Descripción |
|---|---|
|
Qué sensor monitorear, dado como una cadena:
|
# Build Used: Super Code Base 2.0
def main():
# Monitor the rotation in the Monitor tab
monitor_sensor("drivetrain.get_rotation")
drivetrain.turn_for(RIGHT, 450)
# Start threads — Do not delete
start_thread(main)
# Build Used: Super Code Base 2.0
def main():
# Monitor the rotation in the Monitor tab
monitor_sensor("drivetrain.get_rotation", "drivetrain.get_heading")
drivetrain.turn_for(RIGHT, 450)
# Start threads — Do not delete
start_thread(main)
monitor_variable#
monitor_variable agrega una variable predefinida para ser monitoreada en la pestaña Monitor de VEXcode.
Uso:
monitor_variable(“variable”)
Parámetros |
Descripción |
|---|---|
|
El nombre de la variable predefinida a monitorear, dado como una cadena. |
# Build Used: Super Code Base 2.0
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)
# Start threads — Do not delete
start_thread(main)
actions = 0
# Build Used: Super Code Base 2.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
# Start threads — Do not delete
start_thread(main)