Κονσόλα#

Εισαγωγή#

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

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

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

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

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

  • clear — Clears all rows in the Console.

Getter — Ανάγνωση εισόδου χρήστη.

  • input — Waits for user input and returns the response as text.

Mutator — Μορφοποίηση εκτυπωμένου κειμένου.

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

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

  • monitor_variable — Adds one or more predefined variables 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:
console.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
    console.print("Hello, robot!")

# Start threads — Do not delete
start_thread(main)

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

def main():
    # Display 1/3 with two decimals
    console.print(1 / 3, precision=2)

# Start threads — Do not delete
start_thread(main)

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

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:
console.new_line()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

def main():
    # Print on two lines
    console.print("Row 1")
    console.new_line()
    console.print("Row 2")

# Start threads — Do not delete
start_thread(main)

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Row 1" που εμφανίζεται στην πρώτη γραμμή και "Row 2" στη δεύτερη γραμμή.

clear#

clear clears all rows from the Console.

Usage:
console.clear()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

def main():
    # Display text, then clear it after two seconds
    console.print("This will disappear...")
    wait(2, SECONDS)
    console.clear()

# Start threads — Do not delete
start_thread(main)

Λήπτης#

input#

input waits for the user to enter a response, then returns that response as text.

The project pauses at input() until a response is entered in the Console.

The value returned by input() is always text. To use the response as a number, convert it first with int() or float().

Usage:
input()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Ask for a name, then print a greeting
answer = input("What's your name?")
console.print("Hello, " + answer)

# Ask for a number, then use it in math
answer = input("Enter a number:")
number = float(answer)
console.print(number + 1)

Μεταλλακτής#

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

Usage:
console.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
    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)

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και μπλε κείμενο που λέει "Προεπιλεγμένο χρώμα κειμένου" που εμφανίζεται στην πρώτη γραμμή και κόκκινο "Κόκκινο χρώμα κειμένου" στη δεύτερη γραμμή.

Ελεγκτής εκπομπών#

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. Options include:

  • Timer
    • timer.time
  • Drivetrain
    • drivetrain.get_heading
    • drivetrain.get_rotation
    • drivetrain.get_velocity
    • drivetrain.get_yaw
    • drivetrain.get_roll
    • drivetrain.get_pitch
    • drivetrain.get_crashed
    • drivetrain.is_stopped
  • Motor
    • motor.get_position
    • motor.get_velocity
    • motor.get_current
    • motor.is_stopped
    • motor.is_moving
  • Inertial
    • inertial.get_rotation
    • inertial.get_heading
    • inertial.get_yaw
    • inertial.get_roll
    • inertial.get_pitch
    • inertial.get_accelerationX
    • inertial.get_accelerationY
    • inertial.get_accelerationZ
  • Bumper
    • bumper.is_pressed
  • Eye
    • eye.get_color
    • eye.get_hue
    • eye.get_brightness
    • eye.is_object_detected
    • eye.is_color_detected

# 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 and heading 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 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

Το όνομα μιας προκαθορισμένης καθολικής μεταβλητής προς παρακολούθηση, που δίνεται ως συμβολοσειρά. Για να παρακολουθείτε περισσότερες από μία μεταβλητές, διαχωρίστε κάθε όνομα μεταβλητής με κόμμα.

# 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)