비전#
소개#
VEX AIR 드론의 비전 센서는 AprilTag ID를 감지하고 추적합니다. 이를 통해 드론은 주변 환경을 분석하고, 물체를 추적하며, 감지된 시각 데이터를 기반으로 반응할 수 있습니다. 아래는 사용 가능한 모든 메서드 및 속성 목록입니다.
게터 – 드론이 물체를 잡고 있는지 감지합니다.
get_data– 특정 시그니처에 대해 감지된 객체의 튜플을 반환합니다.
속성 – get_data에서 반환된 객체 데이터.
게터스#
get_data#
get_data 비전 센서 프레임에서 데이터를 필터링하여 단일 시그니처(센서가 인식할 수 있는 항목에 대한 저장된 설명, 예를 들어 AprilTag ID 등)만 추출하고 튜플을 반환합니다.
튜플은 인덱스 0부터 시작하여 너비가 큰 순서부터 작은 순서로 정렬된 객체를 저장합니다. 각 객체의 속성은 해당 인덱스를 사용하여 접근할 수 있습니다. 일치하는 객체가 감지되지 않으면 빈 튜플이 반환됩니다.
Usage:
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 |
AprilTag 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)