Vision#

Introduction#

Le capteur de vision du drone VEX AIR détecte et suit les identifiants AprilTag. Cela permet au drone d’analyser son environnement, de suivre des objets et de réagir en fonction des données visuelles détectées. Vous trouverez ci-dessous la liste des méthodes et propriétés disponibles :

Capteurs – Détectent si le drone tient un objet.

  • get_data – Renvoie un tuple d’objets détectés pour une signature spécifique.

Propriétés – Données de l’objet renvoyées par get_data.

  • exists – Indique si l’objet existe dans la détection actuelle.

  • width – Largeur de l’objet détecté.

  • height – Hauteur de l’objet détecté.

  • centerX – Position X du centre de l’objet.

  • centerY – Position Y du centre de l’objet.

  • bearing – Angle de l’objet par rapport au capteur de vision avant ou les degrés nécessaires pour que le drone fasse face à l’objet.

  • rotation – Orientation de l’objet.

  • originX – Position X du coin supérieur gauche de l’objet.

  • originY – Position Y du coin supérieur gauche de l’objet.

  • id – Identifiant de l’étiquette de l’objet.

  • type – Renvoie le type de l’objet.

Getters#

get_data#

get_data filtre les données de la trame du capteur de vision en une seule signature — une description enregistrée de quelque chose que le capteur peut reconnaître, comme un ID AprilTag — et renvoie un tuple.

The tuple stores objects ordered from largest to smallest by width, starting at index 0. Each object’s properties can be accessed using its index. An empty tuple is returned if no matching objects are detected.

Usage:
drone.vision.get_data(camera, signature, count)

Paramètres

Description

camera

La caméra à partir de laquelle récupérer les données : soit la DOWNWARD_CAMERA , soit la FORWARD_CAMERA.

signature

Filtre l’ensemble de données pour n’inclure que les données de la signature spécifiée. Les signatures disponibles sont :

  • ALL_TAGS - Tous les identifiants AprilTag
  • TAG0 à TAG37 - Un seul identifiant AprilTag de 0 à 37

count

Facultatif. Définit le nombre maximal d’objets pouvant être renvoyés, de 1 à 24 (par défaut : 8).

# Climb upward when an AprilTag ID is detected
drone.take_off(climb_to=500)
while True:
    vision_data = drone.vision.get_data(FORWARD_CAMERA, ALL_TAGS)
    if vision_data[0].exists:
        drone.climb_for(direction=UP, distance=200)

Propriétés#

Il existe plusieurs propriétés qui sont incluses avec chaque objet stocké dans un tuple après l’utilisation de get_data.

All property values except .id and .type describe the detected object’s position, size, orientation, or bearing at the moment get_data was used. These values are measured in pixels or degrees. Each Vision Sensor has a different resolution:

  • Face avant : 640 x 480 pixels

  • Orientation vers le bas : 640 x 400 pixels

.exists#

.exists renvoie une valeur booléenne indiquant si l’index existe dans le tuple. Elle renvoie une erreur si aucun objet n’est détecté.

  • True – L’index existe.

  • False – L’index n’existe pas.

# Climb upward when an AprilTag ID is detected
drone.take_off(climb_to=500)
while True:
    vision_data = drone.vision.get_data(FORWARD_CAMERA, ALL_TAGS)
    if vision_data[0].exists:
        drone.climb_for(direction=UP, distance=200)

.width#

.width renvoie la largeur de l’objet détecté en pixels sous forme d’un entier compris entre 1 et 640.

# Show if the AprilTag ID appears large or small
while True:
    vision_data = drone.vision.get_data(FORWARD_CAMERA, ALL_TAGS)
    clear_console()
    if vision_data[0].exists:
        if vision_data[0].width > 100:
            print("Large")
        else:
            print("Small")
    wait(0.2, SECONDS)

.height#

.height renvoie la hauteur de l’objet détecté en pixels sous forme d’un entier compris entre 1 et 480.

# Show if the AprilTag ID appears large or small
while True:
    vision_data = drone.vision.get_data(FORWARD_CAMERA, ALL_TAGS)
    clear_console()
    if vision_data[0].exists:
        if vision_data[0].height > 100:
            print("Large")
        else:
            print("Small")
    wait(0.2, SECONDS)

.centerX#

.centerX renvoie la coordonnée x du centre de l’objet détecté en pixels sous forme d’un entier compris entre 1 et 640.

# Show if an AprilTag ID is to the left or the right of the camera
while True:
    clear_console()
    vision_data = drone.vision.get_data(FORWARD_CAMERA, ALL_TAGS)
    if vision_data[0].exists:
        if vision_data[0].centerX < 320:
            print("To the left!")
        else:
            print("To the right!")
    wait(0.2, SECONDS)

.centerY#

.centerY renvoie la coordonnée y du centre de l’objet détecté en pixels sous forme d’un entier compris entre 1 et 480.

# Take off and align drone with AprilTag ID on wall
# Change drone.take_off parameter to see different results
drone.take_off(climb_to=800)
vision_data = drone.vision.get_data(FORWARD_CAMERA, ALL_TAGS)
if vision_data[0].exists:
    if vision_data[0].centerY < 240:
        print("Below the target!")
    else:
        print("Above the target!")
else:
    print("No target found!")

.bearing#

La fonction .bearing renvoie un angle indiquant la position d’un objet par rapport au drone. Son comportement dépend du capteur de vision utilisé.

Une valeur de 0° indique que le centre de l’objet et le capteur sont alignés. Les valeurs positives signifient que l’objet est à droite, tandis que les valeurs négatives signifient qu’il est à gauche.

Capteur

Retours

Vers le bas

Degrés selon lesquels l’avant du drone doit tourner pour s’aligner avec le centre de l’objet, de –180º à 180º.

Avant

Degrés selon lesquels l’objet est décalé à gauche ou à droite du centre du capteur de vision, de –180º à 180º.

# Align the front of the drone to an AprilTag ID
drone.set_turn_velocity(15)
drone.take_off(climb_to=500)
while True:
    vision_data = drone.vision.get_data(DOWNWARD_CAMERA, ALL_TAGS)
    if vision_data[0].exists:
        if -20 < vision_data[0].bearing < 20:
            # Hover once sensor is centered on AprilTag ID
            drone.hover()
            controller.sound.play(SUCCESS)
            while controller.sound.is_active():
                wait(50, MSEC)
        elif vision_data[0].bearing < -21:
            drone.turn(LEFT)
        else:
            drone.turn(RIGHT)
    wait(5, MSEC)

.rotation#

.rotation renvoie l’orientation de l’identifiant AprilTag détecté sous forme d’un entier en degrés de 1 à 359.

# Turn left or right based on the rotation of an AprilTag ID
drone.take_off(climb_to=1000)
while True:
    vision_data = drone.vision.get_data(FORWARD_CAMERA, ALL_TAGS)
    if vision_data[0].exists:
        if 240 < vision_data[0].rotation < 300:
            drone.turn_for(LEFT, 90)
        elif 60 < vision_data[0].rotation < 120:
            drone.turn_for(RIGHT, 90)
        else:
            drone.hover()
    wait(0.2, SECONDS)

.originX#

.originX renvoie la coordonnée x du coin supérieur gauche de la boîte englobante de l’objet détecté en pixels sous forme d’un entier de 1 à 640.

# Draw lines to the AprilTag ID origin from all corners
while True:
    controller.screen.clear_screen()
    vision_data = drone.vision.get_data(FORWARD_CAMERA, ALL_TAGS)
    if vision_data[0].exists:
        controller.screen.draw_line(0, 0, vision_data[0].originX, vision_data[0].originY)
        controller.screen.draw_line(0, 480, vision_data[0].originX, vision_data[0].originY)
        controller.screen.draw_line(640, 0, vision_data[0].originX, vision_data[0].originY)
        controller.screen.draw_line(640, 480, vision_data[0].originX, vision_data[0].originY)
    wait(0.2, SECONDS)

.originY#

.originY renvoie la coordonnée y du coin supérieur gauche de la boîte englobante de l’objet détecté en pixels sous forme d’un entier de 1 à 480.

# Draw lines to the AprilTag ID origin from all corners
while True:
    controller.screen.clear_screen()
    vision_data = drone.vision.get_data(FORWARD_CAMERA, ALL_TAGS)
    if vision_data[0].exists:
        controller.screen.draw_line(0, 0, vision_data[0].originX, vision_data[0].originY)
        controller.screen.draw_line(0, 480, vision_data[0].originX, vision_data[0].originY)
        controller.screen.draw_line(640, 0, vision_data[0].originX, vision_data[0].originY)
        controller.screen.draw_line(640, 480, vision_data[0].originX, vision_data[0].originY)
    wait(0.2, SECONDS)

.id#

.id renvoie le numéro d’identification de l’identifiant AprilTag détecté sous forme d’un entier compris entre 0 et 37.

# Display the detected AprilTag ID
while True:
    vision_data = drone.vision.get_data(FORWARD_CAMERA, ALL_TAGS)
    clear_console()
    if vision_data[0].exists:
        print(vision_data[0].id)
    wait(0.2, SECONDS)

.type#

.type returns what type of object is detected. It will return the following:

Type d’objet

Valeur numérique

Objets inclus

drone.vision.TAG_OBJECT

8

Identifiants AprilTag

drone.vision.COLOR_OBJECT

1

Signatures couleur - Bientôt disponible !

drone.vision.CODE_OBJECT

2

Codes couleur - Bientôt disponible !

# Display what AprilTag ID is detected
while True:
    controller.screen.clear_screen()
    controller.screen.set_cursor(1, 1)
    vision_data = drone.vision.get_data(FORWARD_CAMERA, ALL_TAGS)
    if vision_data[0].exists:
        if vision_data[0].type == drone.vision.TAG_OBJECT:
            controller.screen.print("AprilTag ID: ")
            controller.screen.print(vision_data[0].id)

    wait(0.1, SECONDS)