想像#
介紹#
VEX AIR 無人機的視覺感測器可偵測並追蹤 AprilTag ID。這使得無人機能夠分析周圍環境、追蹤物體並根據檢測到的視覺數據做出反應。以下是所有可用方法和屬性的清單:
Getters-偵測無人機是否持有物體。
get_data– 傳回特定簽章偵測到的物件元組。
屬性 – 從 get_data 傳回的物件資料。
吸氣劑#
get_data#
get_data 將來自視覺感測器幀的資料過濾為單一簽章(感測器可以識別的事物的保存描述,例如 AprilTag ID),並傳回一個元組。
此元組儲存的物件按寬度從大到小排序,從索引 0 開始。每個物件的 屬性 可以透過其索引存取。如果未偵測到匹配的對象,則傳回一個空元組。
用法:
drone.vision.get_data(camera, signature, 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)
特性#
使用 get_data 後,儲存在 tuple 中的每個物件都包含多個屬性。
除 .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 傳回偵測到的物件中心的 x 座標(以像素為單位),數值為 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 傳回偵測到的物件中心的 y 座標(以像素為單位),數值為 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 傳回偵測到的物件邊界框左上角的 x 座標(以像素為單位),數值為 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 傳回偵測到的物件邊界框左上角的 y 座標(以像素為單位),數值為 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 傳回偵測到的物件類型。它將返回以下內容:
物件類型 |
數值 |
包含的對象 |
|---|---|---|
|
8 |
四月標籤 ID |
|
1 |
顏色簽名 - *即將推出! * |
|
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)