Ελεγκτής#

Εισαγωγή#

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

Configured Controller actions are controller behaviors set in the Devices menu. Use remote_control_code_enabled to temporarily enable or disable those configured actions during a project.

This page uses controller_1 as the example Controller name. Replace it with your own configured name as needed.

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

Ενέργειες — Εκτελέστε Rumble στο χειριστήριο ή ενεργοποιήστε/απενεργοποιήστε τις διαμορφωμένες ενέργειες του χειριστηρίου.

Οθόνη — Εμφάνιση κειμένου και αριθμών στην οθόνη του χειριστηρίου.

  • print — Displays text, numbers, or variable values on the Controller screen.

  • set_cursor — Moves the cursor to a specified row and column on the Controller screen.

  • column — Returns the current cursor column on the Controller screen.

  • row — Returns the current cursor row on the Controller screen.

  • clear_screen — Clears the Controller screen.

  • clear_row — Clears one row on the Controller screen.

  • next_row — Moves the cursor to the next row on the Controller screen.

Λήψη κουμπιών — Ανάγνωση καταστάσεων κουμπιών και θέσεων joystick.

  • .pressing — Returns whether a specified button is being pressed.

  • .position — Returns the position of a specified joystick axis.

Επανακλήσεις — Εκτέλεση συναρτήσεων όταν αλλάζει η είσοδος του ελεγκτή.

  • .pressed — Runs a function when a specified button is pressed.

  • .released — Runs a function when a specified button is released.

  • .changed — Runs a function when the joystick’s position changes along a specified axis.

Κατασκευαστής — Δημιουργήστε χειροκίνητα ένα αντικείμενο Ελεγκτή.

Ενέργειες#

rumble#

rumble plays a rumble pattern on the Controller. In the pattern string, periods are short rumbles, hyphens are long rumbles, and spaces are pauses.

Usage:
controller_1.rumble(pattern)

Παράμετρος

Περιγραφή

pattern

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

# Rumble the Controller with a short-short-long-long pattern
controller_1.rumble("..--")

remote_control_code_enabled#

remote_control_code_enabled is a variable that enables or disables Controller actions configured in the Devices menu. Controller configured actions are enabled by default.

Usage:
remote_control_code_enabled = state

Αξία

Περιγραφή

True

Ενεργοποιεί ενέργειες που έχουν ρυθμιστεί από τον ελεγκτή.

False

Απενεργοποιεί τις ενέργειες που έχουν ρυθμιστεί από τον ελεγκτή.

# Drive forward or backward using the left joystick
remote_control_code_enabled = False

while True:
    if controller_1.axis3.position() > 0:
        drivetrain.drive(FORWARD)
    elif controller_1.axis3.position() < 0:
        drivetrain.drive(REVERSE)
    # Press A to use Controller configured actions again
    elif controller_1.buttonA.pressing():
        break
    else:
        drivetrain.stop()

    wait(20, MSEC)

remote_control_code_enabled = True

Οθόνη#

Η οθόνη του ελεγκτή V5 έχει 3 γραμμές και 19 στήλες για την εμφάνιση κειμένου και αριθμών.

Ένα στιγμιότυπο οθόνης της οθόνης του ελεγκτή V5, που δείχνει τις γραμμές και τις στήλες στην εκτυπώσιμη περιοχή. Γραμμή 1 Η στήλη 1 ξεκινά από την επάνω αριστερή γωνία και η γραμμή 3 και η στήλη 19 βρίσκονται στην κάτω δεξιά γωνία.

print#

controller_1.screen.print displays text, numbers, or variable values on the Controller screen using the current cursor position.

Usage:
controller_1.screen.print(value, sep, precision)

Παράμετρος

Περιγραφή

value

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

sep

Optional. A string to place between values. This must be written as a keyword argument, such as sep=”- “. The default is ” “.

precision

Optional. The number of decimal places to display when printing simple numbers. This must be written as a keyword argument, such as precision=2. The default is 2.

# Print a number on the Controller screen
controller_1.screen.print(1)

# Print multiple numbers separated by hyphens
controller_1.screen.print(1, 2, 3, 4, sep="-")

# Print a number using one decimal place
controller_1.screen.print(1 / 3, precision=1)

set_cursor#

set_cursor moves the cursor to a specified row and column on the Controller screen. The next printed value will appear at that position.

Usage:
controller_1.screen.set_cursor(row, col)

Παράμετρος

Περιγραφή

row

The row of the cursor, from 1 to 3.

col

The column of the cursor, from 1 to 19.

# Print text at row 2, column 1
controller_1.screen.set_cursor(2, 1)
controller_1.screen.print("Ready")

column#

column returns the current column where text will be printed on the Controller screen.

Usage:
controller_1.screen.column()

Παράμετροι

Περιγραφή

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

# Print the current column number
controller_1.screen.set_cursor(2, 3)
controller_1.screen.print(controller_1.screen.column())

row#

row returns the current row where text will be printed on the Controller screen.

Usage:
controller_1.screen.row()

Παράμετροι

Περιγραφή

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

# Print the current row number
controller_1.screen.set_cursor(2, 3)
controller_1.screen.print(controller_1.screen.row())

clear_screen#

clear_screen clears the Controller screen and moves the cursor back to the starting position.

Usage:
controller_1.screen.clear_screen()

Παράμετροι

Περιγραφή

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

# Print text, then clear the Controller screen
controller_1.screen.print("VEX V5")
wait(2, SECONDS)
controller_1.screen.clear_screen()

clear_row#

clear_row clears one row on the Controller screen.

Usage:
controller_1.screen.clear_row(row)

Παράμετρος

Περιγραφή

row

Optional. The row to clear, from 1 to 3. If no row is provided, the current cursor row is cleared.

# Clear row 2 on the Controller screen
controller_1.screen.clear_row(2)

next_row#

next_row moves the cursor to column 1 on the next row of the Controller screen. The next printed value will appear on that row.

Usage:
controller_1.screen.next_row()

Παράμετροι

Περιγραφή

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

# Print on two rows
controller_1.screen.print("VEX V5")
controller_1.screen.next_row()
controller_1.screen.print("Controller")

Αποκτητές#

.pressing#

.pressing returns whether a specific button on the Controller is currently being pressed. This method must be called on a specific button object, such as controller_1.buttonA.

  • True — The specified button is being pressed.

  • False — The specified button is not being pressed.

Χρήση:
Ένα από τα διαθέσιμα αντικείμενα κουμπιών μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο:

Η μπροστινή και η πίσω πλευρά του χειριστηρίου V5 με τα κουμπιά επισημασμένα με κίτρινο χρώμα. Στην επιφάνεια του χειριστηρίου υπάρχουν κουμπιά βέλους πάνω, κάτω, αριστερά και δεξιά στα αριστερά και κουμπιά X, A, B, Y δεξιόστροφα από τις 12 η ώρα στα δεξιά. Στην πίσω πλευρά του χειριστηρίου υπάρχουν L1, L2, R1 και R2 στην αριστερή και δεξιά πλευρά αντίστοιχα.

Κουμπί

Εντολή

buttonA

controller_1.buttonA.pressing() — The A button

buttonB

controller_1.buttonB.pressing() — The B button

buttonX

controller_1.buttonX.pressing() — The X button

buttonY

controller_1.buttonY.pressing() — The Y button

buttonDown

controller_1.buttonDown.pressing() — The Down button

buttonUp

controller_1.buttonUp.pressing() — The Up button

buttonLeft

controller_1.buttonLeft.pressing() — The Left button

buttonRight

controller_1.buttonRight.pressing() — The Right button

buttonL1

controller_1.buttonL1.pressing() — The L1 button

buttonL2

controller_1.buttonL2.pressing() — The L2 button

buttonR1

controller_1.buttonR1.pressing() — The R1 button

buttonR2

controller_1.buttonR2.pressing() — The R2 button

Παράμετροι

Περιγραφή

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

# Turn right while L1 is pressed
while True:
    if controller_1.buttonL1.pressing():
        drivetrain.turn(RIGHT)
    else:
        drivetrain.stop()

    wait(20, MSEC)

.position#

.position returns the position of a joystick axis as a number from -100 to 100.

This method must be called on a specific axis object, such as controller_1.axis1.

Χρήση:
Ένα από τα διαθέσιμα αντικείμενα άξονα μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο:

Ένα χειριστήριο VEX V5 με τους άξονες γύρω από τα joystick να έχουν επισημανθεί. Οι άξονες 1 και 2 βρίσκονται γύρω από το δεξί joystick και οι άξονες 3 και 4 γύρω από το αριστερό.

Αξονας

Εντολή

axis1

controller_1.axis1.position() — The right joystick’s horizontal axis

axis2

controller_1.axis2.position() — The right joystick’s vertical axis

axis3

controller_1.axis3.position() — The left joystick’s vertical axis

axis4

controller_1.axis4.position() — The left joystick’s horizontal axis

Παράμετροι

Περιγραφή

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

# Turn with the left joystick
remote_control_code_enabled = False

while True:
    if controller_1.axis4.position() > 10:
        drivetrain.turn(RIGHT)
    elif controller_1.axis4.position() < -10:
        drivetrain.turn(LEFT)
    else:
        drivetrain.stop()

    wait(20, MSEC)

Επανακλήσεις#

.pressed#

.pressed runs a function when the specified button is pressed. Once it is used, the function will run automatically each time that button is pressed.

Χρήση:
Ένα από τα διαθέσιμα αντικείμενα κουμπιών μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο:

Η μπροστινή και η πίσω πλευρά του χειριστηρίου V5 με τα κουμπιά επισημασμένα με κίτρινο χρώμα. Στην επιφάνεια του χειριστηρίου υπάρχουν κουμπιά βέλους πάνω, κάτω, αριστερά και δεξιά στα αριστερά και κουμπιά X, A, B, Y δεξιόστροφα από τις 12 η ώρα στα δεξιά. Στην πίσω πλευρά του χειριστηρίου υπάρχουν L1, L2, R1 και R2 στην αριστερή και δεξιά πλευρά αντίστοιχα.

Κουμπί

Εντολή

buttonA

controller_1.buttonA.pressed(callback, arg) — The A button

buttonB

controller_1.buttonB.pressed(callback, arg) — The B button

buttonX

controller_1.buttonX.pressed(callback, arg) — The X button

buttonY

controller_1.buttonY.pressed(callback, arg) — The Y button

buttonDown

controller_1.buttonDown.pressed(callback, arg) — The Down button

buttonUp

controller_1.buttonUp.pressed(callback, arg) — The Up button

buttonLeft

controller_1.buttonLeft.pressed(callback, arg) — The Left button

buttonRight

controller_1.buttonRight.pressed(callback, arg) — The Right button

buttonL1

controller_1.buttonL1.pressed(callback, arg) — The L1 button

buttonL2

controller_1.buttonL2.pressed(callback, arg) — The L2 button

buttonR1

controller_1.buttonR1.pressed(callback, arg) — The R1 button

buttonR2

controller_1.buttonR2.pressed(callback, arg) — The R2 button

Παράμετρος

Περιγραφή

callback

Μια προηγουμένως καθορισμένη συνάρτηση που θα εκτελείται κάθε φορά που πατιέται το καθορισμένο κουμπί.

arg

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

# Drive forward when A is pressed
def drive_forward():
    drivetrain.drive_for(FORWARD, 100, MM)

controller_1.buttonA.pressed(drive_forward)

.released#

.released runs a function when the specified button is released. Once it is used, the function will run automatically each time that button is released.

Χρήση:
Ένα από τα διαθέσιμα αντικείμενα κουμπιών μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο:

Η μπροστινή και η πίσω πλευρά του χειριστηρίου V5 με τα κουμπιά επισημασμένα με κίτρινο χρώμα. Στην επιφάνεια του χειριστηρίου υπάρχουν κουμπιά βέλους πάνω, κάτω, αριστερά και δεξιά στα αριστερά και κουμπιά X, A, B, Y δεξιόστροφα από τις 12 η ώρα στα δεξιά. Στην πίσω πλευρά του χειριστηρίου υπάρχουν L1, L2, R1 και R2 στην αριστερή και δεξιά πλευρά αντίστοιχα.

Κουμπί

Εντολή

buttonA

controller_1.buttonA.released(callback, arg) — The A button

buttonB

controller_1.buttonB.released(callback, arg) — The B button

buttonX

controller_1.buttonX.released(callback, arg) — The X button

buttonY

controller_1.buttonY.released(callback, arg) — The Y button

buttonDown

controller_1.buttonDown.released(callback, arg) — The Down button

buttonUp

controller_1.buttonUp.released(callback, arg) — The Up button

buttonLeft

controller_1.buttonLeft.released(callback, arg) — The Left button

buttonRight

controller_1.buttonRight.released(callback, arg) — The Right button

buttonL1

controller_1.buttonL1.released(callback, arg) — The L1 button

buttonL2

controller_1.buttonL2.released(callback, arg) — The L2 button

buttonR1

controller_1.buttonR1.released(callback, arg) — The R1 button

buttonR2

controller_1.buttonR2.released(callback, arg) — The R2 button

Παράμετρος

Περιγραφή

callback

Μια προηγουμένως καθορισμένη συνάρτηση που θα εκτελείται κάθε φορά που απελευθερώνεται το καθορισμένο κουμπί.

arg

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

# Drive backward when A is released
def back_up():
    drivetrain.drive_for(REVERSE, 100, MM)

controller_1.buttonA.released(back_up)

.changed#

.changed runs a function when the joystick’s position changes along the specified axis. Once it is used, the function will run automatically each time the joystick’s position changes along that axis.

Χρήση:
Ένα από τα διαθέσιμα αντικείμενα άξονα μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο:

Ένα χειριστήριο VEX V5 με τους άξονες γύρω από τα joystick να έχουν επισημανθεί. Οι άξονες 1 και 2 βρίσκονται γύρω από το δεξί joystick και οι άξονες 3 και 4 γύρω από το αριστερό.

Αξονας

Εντολή

axis1

controller_1.axis1.changed(callback, arg) — The right joystick’s horizontal axis

axis2

controller_1.axis2.changed(callback, arg) — The right joystick’s vertical axis

axis3

controller_1.axis3.changed(callback, arg) — The left joystick’s vertical axis

axis4

controller_1.axis4.changed(callback, arg) — The left joystick’s horizontal axis

Παράμετρος

Περιγραφή

callback

Μια προηγουμένως καθορισμένη συνάρτηση που θα εκτελείται κάθε φορά που αλλάζει η θέση του joystick κατά μήκος του καθορισμένου άξονα.

arg

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

# Play a sound when the left joystick moves
def tada_sound():
    brain.play_sound(SoundType.TADA)

controller_1.axis4.changed(tada_sound)

Κατασκευαστές#

Controller#

Controller creates a Controller object. Manually creating a Controller object is only needed when configuring a controller outside of VEXcode.

Usage:
Controller(controller_type)

Παράμετρος

Περιγραφή

controller_type

Optional. The Controller type to create: PRIMARY for the primary Controller connected to the Brain or PARTNER for the second Controller connected to the Brain.

# Create the primary Controller
controller_1 = Controller(PRIMARY)

# Create a partner Controller
controller_2 = Controller(PARTNER)