Ελεγκτής#
Εισαγωγή#
Το χειριστήριο VEX AIR Drone διαθέτει διάταξη 12 κουμπιών και δύο joystick. Αυτές οι είσοδοι επιτρέπουν στο drone να ανιχνεύει τα πατήματα κουμπιών και τις κινήσεις του joystick, επιτρέποντας διαδραστικό και γρήγορο έλεγχο.
Παρακάτω είναι μια λίστα με όλες τις διαθέσιμες μεθόδους:
Λήψη – Ανάγνωση κουμπιού, joystick και κατάστασης σύνδεσης.
pressing– Returns if a specific button is currently being pressed.position– Returns the position of the joystick along a specified axis.is_drone_connected– Returns whether the controller is connected to the drone.get_battery_level– Returns the controller’s battery level.
Επανακλήσεις – Απόκριση σε αλλαγές εισόδου κουμπιών ή joystick.
Αποκτητές#
pressing#
pressing returns a Boolean indicating whether a specific button on the controller is currently being pressed. This method must be called on a specific button object, such as button5 (see full list of button objects below).
True- The specified button is being pressed.False- The specified button is not being pressed.
Χρήση:
Ένα από τα οκτώ διαθέσιμα κουμπιά, με αριθμούς από 5 έως 12, μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, όπως φαίνεται παρακάτω:
Κουμπί |
Εντολή |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Take a picture when button 5 is pressed.
drone.take_off(climb_to=500)
while True:
# Fly using the controller sticks
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
# Capture an image from the forward camera when button 5 is pressed.
if controller.button5.pressing():
drone.camera.capture_image(FORWARD_CAMERA)
wait(5, MSEC)
position#
position returns the position of the joystick’s specified axis, as a percentage from –100% to 100%.
Χρήση:
Ένας από τους τέσσερις διαθέσιμους άξονες μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, οι οποίοι αριθμούνται από το 1 έως το 4.
Αξονας |
Εντολή |
|---|---|
|
|
|
|
|
|
|
|

Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Climb when the left joystick is moved up.
drone.take_off(climb_to=500)
while True:
if controller.axis1.position() > 0:
drone.climb(direction=UP, velocity=50)
else:
drone.hover()
wait(5, MSEC)
is_drone_connected#
is_drone_connected returns a Boolean indicating whether the drone is connected.
True- The drone is connected.False- The drone is not connected.
Χρήση:
controller.is_drone_connected()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Print controller connection status on screen.
while True:
if controller.is_drone_connected():
controller.screen.clear_screen()
controller.screen.set_cursor(1, 1)
controller.screen.print("Controller connected")
wait(0.5, SECONDS)
get_battery_level#
get_battery_level returns the Controller’s battery level, as a percentage from 0% to 100%.
Χρήση:
controller.get_battery_level()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Show controller's battery level.
if controller.get_battery_level() > 50:
controller.screen.print("Battery level ok")
else:
controller.screen.print("Battery level low")
Επανακλήσεις#
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.
Χρήση:
Με αυτήν τη μέθοδο μπορεί να χρησιμοποιηθεί ένα από τα οκτώ διαθέσιμα κουμπιά, τα οποία αριθμούνται από το 5 έως το 12.
Κουμπί |
Εντολή |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

Παράμετροι |
Περιγραφή |
|---|---|
|
Μια προηγουμένως καθορισμένη συνάρτηση που θα εκτελείται κάθε φορά που πατιέται το καθορισμένο κουμπί. |
|
Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Χρήση συμβάντων με παραμέτρους για περισσότερες πληροφορίες. |
# Take a picture when button 5 is pressed.
def take_picture():
drone.camera.capture_image(FORWARD_CAMERA)
# Run take_picture each time button 5 is pressed.
controller.button5.pressed(take_picture)
# Fly using the controller sticks.
drone.take_off(climb_to=500)
while True:
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)
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.
Χρήση:
Με αυτήν τη μέθοδο μπορεί να χρησιμοποιηθεί ένα από τα οκτώ διαθέσιμα κουμπιά, τα οποία αριθμούνται από το 5 έως το 12.
Κουμπί |
Εντολή |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

Παράμετροι |
Περιγραφή |
|---|---|
|
Μια προηγουμένως καθορισμένη συνάρτηση που θα εκτελείται κάθε φορά που απελευθερώνεται το καθορισμένο κουμπί. |
|
Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Χρήση Συναρτήσεων με Παραμέτρους για περισσότερες πληροφορίες. |
# Take a picture when button 5 is released.
def take_picture():
drone.camera.capture_image(FORWARD_CAMERA)
# Run take_picture each time button 5 is released.
controller.button5.released(take_picture)
# Fly using the controller sticks.
drone.take_off(climb_to=500)
while True:
drone.move_with_vectors(
forward=controller.axis4.position(),
rightward=controller.axis3.position(),
upward=controller.axis1.position(),
rotation=controller.axis2.position()
)
wait(5, MSEC)
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.
Χρήση:
Ένας από τους τέσσερις διαθέσιμους άξονες μπορεί να χρησιμοποιηθεί με αυτήν τη μέθοδο, οι οποίοι αριθμούνται από το 1 έως το 4.
Αξονας |
Εντολή |
|---|---|
|
|
|
|
|
|
|
|

Παράμετροι |
Περιγραφή |
|---|---|
|
Μια προηγουμένως καθορισμένη συνάρτηση που θα εκτελείται κάθε φορά που αλλάζει η θέση του joystick κατά μήκος του καθορισμένου άξονα. |
|
Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Χρήση Συναρτήσεων με Παραμέτρους για περισσότερες πληροφορίες. |
# Move forward when the left joystick moves.
def on_axis1_changed():
drone.move_for(direction=0, distance=200, velocity=50, units=MM)
drone.take_off(climb_to=500)
controller.axis1.changed(on_axis1_changed)