Κονσόλα#

Εισαγωγή#

Το VEXcode VR περιλαμβάνει μια καρτέλα Monitor (Παρακολούθηση) που μπορεί να εμφανίσει την έξοδο της κονσόλας, να παρακολουθεί μεταβλητές και να παρακολουθεί τιμές αισθητήρων ενώ εκτελείται ένα έργο.

Οι μέθοδοι κονσόλας μπορούν να εμφανίσουν κείμενο, αριθμούς και τιμές μεταβλητών. Μπορούν επίσης να μετακινήσουν τον κέρσορα της κονσόλας σε μια νέα γραμμή, να καθαρίσουν την κονσόλα και να ορίσουν το χρώμα του κειμένου που θα εκτυπώνεται μετά την αλλαγή του χρώματος.

Παρακάτω είναι μια λίστα με όλες τις μεθόδους:

Εκτύπωση — Έξοδος κειμένου ή εκκαθάριση της Κονσόλας.

  • print — Displays text, numbers, or variable values in the Console.

  • new_line — Moves the Console cursor to the start of the next row.

  • set_print_color — Sets the color used for text printed in the Console.

  • clear — Clears all rows in the Console.

Παρακολούθηση — Παρακολουθήστε την τιμή ενός αισθητήρα ή μιας μεταβλητής κατά τη διάρκεια ενός έργου στην καρτέλα Παρακολούθηση του VEXcode.

  • monitor_variable — Adds one or more predefined variables to the Monitor tab.

  • monitor_sensor — Adds one or more sensor values to the Monitor tab.

Αποτύπωμα#

print#

print displays text, numbers, or variable values in the Console using the current cursor position.

Χρησιμοποιήστε προσαρμοσμένη μορφοποίηση συμβολοσειράς όταν θέλετε ένα εκτυπωμένο μήνυμα να περιλαμβάνει τιμές από το έργο σας, όπως μια βαθμολογία, ένα χρονόμετρο ή μια ένδειξη αισθητήρα. Ανατρέξτε στη σελίδα Μορφοποίηση συμβολοσειράς για περισσότερες πληροφορίες.

Use new_line when you want the next printed value to start on a new row.

Usage:
brain.print(value, precision)

Παράμετροι

Περιγραφή

value

Το κείμενο, ο αριθμός ή η τιμή μεταβλητής που θα εμφανίζεται στην Κονσόλα.

precision

Optional. The number of decimal places to display when printing a number. The default is 0, so numbers print with no decimal places.

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

# VR threads — Do not delete
vr_thread(main)

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Γεια σου, ρομπότ!".

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 moves the cursor to column 1 on the next row in the Console. The next value printed will appear on that row.

Χρησιμοποιήστε αυτήν τη μέθοδο όταν θέλετε η επόμενη εκτυπωμένη τιμή να ξεκινά σε μια νέα γραμμή.

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, που εμφανίζει την Κονσόλα και το κείμενο "Row 1" που εμφανίζεται στην πρώτη γραμμή και "Row 2" στη δεύτερη γραμμή.

set_print_color#

set_print_color sets the color used for text printed in the Console after this method is used. At the start of a project, the Console text color is set to BLACK.

Usage:
brain.set_print_color(color)

Παράμετροι

Περιγραφή

color

The color to use for text printed in the Console:

  • 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 clears all rows from the Console.

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 adds one or more predefined variables to the Monitor tab in VEXcode. This lets you watch a variable’s value change while a project is running.

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 adds one or more sensor values to the Monitor tab in VEXcode. This lets you watch sensor values change while a project is running.

Εάν ένας αισθητήρας μπορεί να επιστρέψει δεδομένα σε διαφορετικές μονάδες, η καρτέλα Παρακολούθηση θα εμφανίσει τα δεδομένα που επιστρέφονται σε κάθε διαθέσιμη μονάδα. Παρέχετε κάθε τιμή αισθητήρα ως συμβολοσειρά.

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

Παράμετροι

Περιγραφή

sensor

The sensor value to monitor, given as a string. To monitor more than one sensor value, separate each sensor value with a comma. This can be any sensor method that returns a value, such as “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)