วิสัยทัศน์#

การแนะนำ#

เซ็นเซอร์ตรวจจับภาพของโดรน VEX AIR ตรวจจับและติดตามรหัส AprilTag ซึ่งช่วยให้โดรนวิเคราะห์สภาพแวดล้อม ติดตามวัตถุ และตอบสนองตามข้อมูลภาพที่ตรวจพบ ด้านล่างนี้คือรายการวิธีการและคุณสมบัติทั้งหมดที่มีให้ใช้งาน:

ตัวตรวจจับ – ตรวจสอบว่าโดรนกำลังถือวัตถุอยู่หรือไม่

  • get_data – ส่งคืนทูเปิลของวัตถุที่ตรวจพบสำหรับลายเซ็นเฉพาะ

คุณสมบัติ – ข้อมูลวัตถุที่ส่งคืนจาก get_data

  • exists – วัตถุนั้นมีอยู่ในการตรวจจับปัจจุบันหรือไม่

  • width – ความกว้างของวัตถุที่ตรวจพบ

  • height – ความสูงของวัตถุที่ตรวจพบ

  • centerX – ตำแหน่ง X ของจุดศูนย์กลางของวัตถุ

  • centerY – ตำแหน่ง Y ของจุดศูนย์กลางของวัตถุ

  • bearing – มุมของวัตถุที่สัมพันธ์กับเซ็นเซอร์ตรวจจับภาพด้านหน้า หรือองศาที่จำเป็นสำหรับโดรนที่จะหันหน้าเข้าหาวัตถุ

  • rotation – การวางแนวของวัตถุ

  • originX – ตำแหน่ง X ของมุมบนซ้ายของวัตถุ

  • originY – ตำแหน่ง Y ของมุมบนซ้ายของวัตถุ

  • id – รหัสแท็กของวัตถุ

  • type – ส่งคืนประเภทของวัตถุ

ผู้รับ#

get_data#

get_data กรองข้อมูลจากเฟรม Vision Sensor ให้เหลือเพียงลายเซ็นเดียว ซึ่งเป็นคำอธิบายที่บันทึกไว้ของสิ่งที่เซ็นเซอร์สามารถจดจำได้ เช่น รหัส AprilTag และส่งคืนทูเปิล

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)

พารามิเตอร์

คำอธิบาย

camera

กล้องที่จะดึงข้อมูล: กล้อง DOWNWARD_CAMERA หรือกล้อง FORWARD_CAMERA

signature

กรองชุดข้อมูลเพื่อให้มีเฉพาะข้อมูลที่มีลายเซ็นที่กำหนดเท่านั้น ลายเซ็นที่ใช้ได้มีดังนี้:

  • ALL_TAGS - รหัส AprilTag ทั้งหมด
  • TAG0 ถึง TAG37 - รหัส AprilTag เดียวตั้งแต่ 0 ถึง 37

count

ตัวเลือกเสริม กำหนดจำนวนสูงสุดของวัตถุที่สามารถส่งคืนได้ตั้งแต่ 1 ถึง 24 (ค่าเริ่มต้น: 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)

คุณสมบัติ#

มีคุณสมบัติหลายอย่างที่รวมอยู่ในแต่ละวัตถุที่จัดเก็บใน tuple หลังจากใช้ get_data

ค่าคุณสมบัติทั้งหมด ยกเว้น .id และ .type อธิบายตำแหน่ง ขนาด การวางแนว หรือทิศทางของวัตถุที่ตรวจพบในขณะที่ get_data ถูกใช้งาน ค่าเหล่านี้วัดเป็นพิกเซลหรือองศา เซ็นเซอร์วิชั่นแต่ละตัวมีความละเอียดต่างกัน:

  • ด้านหน้า: 640 x 480 พิกเซล

  • มองลงด้านล่าง: 640 x 400 พิกเซล

.exists#

เมธอด .exists จะส่งคืนค่าบูลีนที่ระบุว่าดัชนีนั้นมีอยู่ในทูเปิลหรือไม่ หากไม่พบวัตถุใด ๆ จะส่งคืนค่าข้อผิดพลาด

  • True – ดัชนีมีอยู่จริง

  • False – ดัชนีนี้ไม่มีอยู่จริง

# 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 ส่งคืนความกว้างของวัตถุที่ตรวจพบในหน่วยพิกเซล โดยเป็นจำนวนเต็มตั้งแต่ 1 ถึง 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 ส่งคืนความสูงของวัตถุที่ตรวจพบในหน่วยพิกเซล โดยเป็นจำนวนเต็มตั้งแต่ 1 ถึง 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 จำนวนเต็มตั้งแต่ 1 ถึง 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 จำนวนเต็มตั้งแต่ 1 ถึง 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#

.bearing ส่งคืนค่ามุมที่ระบุตำแหน่งของวัตถุเทียบกับโดรน พฤติกรรมจะขึ้นอยู่กับเซ็นเซอร์ตรวจจับภาพที่ใช้

ค่า 0° แสดงว่าจุดศูนย์กลางของวัตถุและเซ็นเซอร์อยู่ในแนวเดียวกัน ค่าบวกหมายความว่าวัตถุอยู่ทางด้านขวา ในขณะที่ค่าลบหมายความว่าวัตถุอยู่ทางด้านซ้าย

เซ็นเซอร์

การคืนสินค้า

ลงล่าง

องศาที่ส่วนหน้าของโดรนต้องหมุนเพื่อให้ตรงกับจุดศูนย์กลางของวัตถุ ตั้งแต่ -180º ถึง 180º

ซึ่งไปข้างหน้า

องศาที่วัตถุเบี่ยงไปทางซ้ายหรือขวาจากจุดศูนย์กลางของเซ็นเซอร์ตรวจจับภาพ ตั้งแต่ –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 จะส่งคืนค่าการวางแนวของ AprilTag ID ที่ตรวจพบเป็นจำนวนเต็มในหน่วยองศาตั้งแต่ 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 วัตถุที่ตรวจพบในหน่วยพิกเซล โดยเป็นจำนวนเต็มตั้งแต่ 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 วัตถุที่ตรวจพบในหน่วยพิกเซล โดยเป็นจำนวนเต็มตั้งแต่ 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 ส่งคืนหมายเลขประจำตัวของ AprilTag ID ที่ตรวจพบเป็นจำนวนเต็มตั้งแต่ 0 ถึง 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 จะส่งคืนข้อมูลดังต่อไปนี้:

ประเภทวัตถุ

ค่าตัวเลข

วัตถุที่รวมอยู่

drone.vision.TAG_OBJECT

8

รหัสแท็กเดือนเมษายน

drone.vision.COLOR_OBJECT

1

ลายเซ็นสี - เร็วๆ นี้!

drone.vision.CODE_OBJECT

2

รหัสสี - เร็วๆ นี้!

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