OFFBOARD 속도 제어 (BODY 기준)
저작권: 쿼드(QUAD) 드론연구소 https://smartstore.naver.com/maponarooo
이번 세션에서는 Offboard 모드에서 Local_Position_NED를 이용한 위치제어 방법에 대해 다룹니다.
offboard_velocity_body.py 코드 분석
EKF Origin 초기화
print("-- Setting initial setpoint")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(0.0, 0.0, 0.0, 0.0))
반드시set_velocity_body 메쏘드를 이용하여 초기화 하여야 합니다.
이륙 및 기수 방향 변경
print("-- Turn clock-wise and climb")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(0.0, 0.0, -1.0, 60.0))
await asyncio.sleep(5)
1m 고도로 이륙하며 기수 방향을 시계방향으로 60도 회전 합니다.
원주 비행
Velocity Body를 이용하면 원주 비행이 쉽습니다.
print("-- Fly a circle")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(5.0, 0.0, 0.0, 30.0))
await asyncio.sleep(15)
5m 속도로 전진하며 기수를 30도 시계방향으로 회전 시킵니다.
옆면 원주 비행
print("-- Fly a circle sideways")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(0.0, -5.0, 0.0, 30.0))
await asyncio.sleep(15)
FRD 좌표계 기준으로 왼쪽으로 회전 시킵니다.
전체 코드
offboard_velocity_body.py
#!/usr/bin/env python3
import asyncio
from mavsdk import System
from mavsdk.offboard import (OffboardError, VelocityBodyYawspeed)
async def run():
""" Does Offboard control using velocity body coordinates. """
drone = System()
await drone.connect(system_address="udp://:14540")
print("Waiting for drone to connect...")
async for state in drone.core.connection_state():
if state.is_connected:
print(f"-- Connected to drone!")
break
print("Waiting for drone to have a global position estimate...")
async for health in drone.telemetry.health():
if health.is_global_position_ok and health.is_home_position_ok:
print("-- Global position estimate OK")
break
print("-- Arming")
await drone.action.arm()
print("-- Setting initial setpoint")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(0.0, 0.0, 0.0, 0.0))
print("-- Starting offboard")
try:
await drone.offboard.start()
except OffboardError as error:
print(f"Starting offboard mode failed with error code: \
{error._result.result}")
print("-- Disarming")
await drone.action.disarm()
return
print("-- Turn clock-wise and climb")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(0.0, 0.0, -1.0, 60.0))
await asyncio.sleep(5)
print("-- Turn back anti-clockwise")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(0.0, 0.0, 0.0, -60.0))
await asyncio.sleep(5)
print("-- Wait for a bit")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(0.0, 0.0, 0.0, 0.0))
await asyncio.sleep(2)
print("-- Fly a circle")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(5.0, 0.0, 0.0, 30.0))
await asyncio.sleep(15)
print("-- Wait for a bit")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(0.0, 0.0, 0.0, 0.0))
await asyncio.sleep(5)
print("-- Fly a circle sideways")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(0.0, -5.0, 0.0, 30.0))
await asyncio.sleep(15)
print("-- Wait for a bit")
await drone.offboard.set_velocity_body(
VelocityBodyYawspeed(0.0, 0.0, 0.0, 0.0))
await asyncio.sleep(8)
print("-- Stopping offboard")
try:
await drone.offboard.stop()
except OffboardError as error:
print(f"Stopping offboard mode failed with error code: \
{error._result.result}")
if __name__ == "__main__":
# Run the asyncio loop
asyncio.run(run())
실행
Local Position NED 보다 움직임이 부드러워 진 것을 볼 수 있습니다.
Last updated