Ελεγκτής#
Εισαγωγή#
Ο ελεγκτής VEX EXP διαθέτει κουμπιά και δύο joystick. Οι μέθοδοι του ελεγκτή μπορούν να χρησιμοποιηθούν για τον έλεγχο των πατημάτων κουμπιών, την ανάγνωση της κίνησης του joystick, την ενεργοποίηση ή απενεργοποίηση των διαμορφωμένων ενεργειών του ελεγκτή ή την εκτέλεση λειτουργιών όταν συμβαίνουν συμβάντα του ελεγκτή.
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 as the example controller name. Replace it with your own configured name as needed.
Παρακάτω είναι μια λίστα με όλες τις διαθέσιμες μεθόδους:
Ενέργεια — Ενεργοποίηση ή απενεργοποίηση των διαμορφωμένων ενεργειών του χειριστηρίου.
remote_control_code_enabled— Enables or disables controller actions configured in the Devices menu.
Λήψη κουμπιών — Ανάγνωση καταστάσεων κουμπιών και θέσεων 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.
Κατασκευαστής — Δημιουργήστε χειροκίνητα ένα αντικείμενο Ελεγκτή.
Controller— Creates a Controller object.
Δράση#
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
Αξία |
Περιγραφή |
|---|---|
|
Ενεργοποιεί ενέργειες που έχουν ρυθμιστεί από τον ελεγκτή. |
|
Απενεργοποιεί τις ενέργειες που έχουν ρυθμιστεί από τον ελεγκτή. |
# Drive forward or backward using the left joystick
remote_control_code_enabled = False
while True:
if controller.axis3.position() > 0:
drivetrain.drive(FORWARD)
elif controller.axis3.position() < 0:
drivetrain.drive(REVERSE)
# Press A to use controller configured actions again
elif controller.buttonA.pressing():
break
else:
drivetrain.stop()
wait(20, MSEC)
remote_control_code_enabled = True
Αποκτητές#
.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.buttonA.
True— The specified button is being pressed.False— The specified button is not being pressed.
Χρήση:
Ένα από τα διαθέσιμα αντικείμενα κουμπιών μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο:
Κουμπί |
Εντολή |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Turn right while L1 is pressed
while True:
if controller.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.axis1.
Χρήση:
Ένα από τα διαθέσιμα αντικείμενα άξονα μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο:
Αξονας |
Εντολή |
|---|---|
|
|
|
|
|
|
|
|
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Turn with the left joystick
remote_control_code_enabled = False
while True:
if controller.axis4.position() > 10:
drivetrain.turn(RIGHT)
elif controller.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.
Χρήση:
Ένα από τα διαθέσιμα αντικείμενα κουμπιών μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο:
Κουμπί |
Εντολή |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Παράμετρος |
Περιγραφή |
|---|---|
|
Μια προηγουμένως καθορισμένη συνάρτηση που θα εκτελείται κάθε φορά που πατιέται το καθορισμένο κουμπί. |
|
Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Χρήση συμβάντων με παραμέτρους για περισσότερες πληροφορίες. |
# Drive forward when R1 is pressed
def drive_forward():
drivetrain.drive_for(FORWARD, 200, MM)
controller.buttonR1.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.
Χρήση:
Ένα από τα διαθέσιμα αντικείμενα κουμπιών μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο:
Κουμπί |
Εντολή |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Παράμετρος |
Περιγραφή |
|---|---|
|
Μια προηγουμένως καθορισμένη συνάρτηση που θα εκτελείται κάθε φορά που απελευθερώνεται το καθορισμένο κουμπί. |
|
Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Χρήση συμβάντων με παραμέτρους για περισσότερες πληροφορίες. |
# Stop driving when R1 is released
def stop_driving():
drivetrain.stop()
controller.buttonR1.released(stop_driving)
.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.
Χρήση:
Ένα από τα διαθέσιμα αντικείμενα άξονα μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο:
Αξονας |
Εντολή |
|---|---|
|
|
|
|
|
|
|
|
Παράμετρος |
Περιγραφή |
|---|---|
|
Μια προηγουμένως καθορισμένη συνάρτηση που θα εκτελείται κάθε φορά που αλλάζει η θέση του joystick κατά μήκος του καθορισμένου άξονα. |
|
Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Χρήση συμβάντων με παραμέτρους για περισσότερες πληροφορίες. |
# Play a sound when the left joystick moves
def beep():
brain.play_sound(SoundType.TADA)
controller.axis3.changed(beep)
Κατασκευαστές#
Controller#
Controller creates a Controller object. Manually creating a Controller object is only needed when configuring a controller outside of VEXcode.
Usage:
Controller()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτός ο κατασκευαστής δεν έχει παραμέτρους. |
# Create a Controller object
my_controller = Controller()