|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import asyncio |
| 4 | +from mavsdk import System |
| 5 | +from mavsdk.gimbal import GimbalMode |
| 6 | + |
| 7 | +async def run(): |
| 8 | + # Init the drone |
| 9 | + drone = System() |
| 10 | + await drone.connect(system_address="udp://:14540") |
| 11 | + |
| 12 | + # Start printing gimbal position updates |
| 13 | + asyncio.ensure_future(print_gimbal_position(drone)) |
| 14 | + |
| 15 | + # Arm and takeoff the drone |
| 16 | + await drone.action.arm() |
| 17 | + await drone.action.takeoff() |
| 18 | + |
| 19 | + # Set the gimbal to YAW_LOCK (= 1) mode (see docs for the difference) |
| 20 | + # Other valid values: YAW_FOLLOW (= 0) |
| 21 | + # YAW_LOCK will fix the gimbal pointing to an absolute direction, |
| 22 | + # whereas YAW_FOLLOW will point relative to vehicle heading. |
| 23 | + print("Setting gimbal mode") |
| 24 | + await drone.gimbal.set_mode(GimbalMode.YAW_LOCK) |
| 25 | + await asyncio.sleep(5) |
| 26 | + |
| 27 | + # Move the gimbal to point at pitch -40 degrees, yaw 30 degrees |
| 28 | + print("Setting pitch & yaw") |
| 29 | + await drone.gimbal.set_pitch_and_yaw(-40, 30) |
| 30 | + await asyncio.sleep(10) |
| 31 | + |
| 32 | + |
| 33 | + # Set the gimbal to track a region of interest (lat, lon, altitude) |
| 34 | + # Units are degrees and meters MSL respectively |
| 35 | + print("Setting RoI") |
| 36 | + await drone.gimbal.set_roi_location(28.452386, -13.867138, 28.5) |
| 37 | + await asyncio.sleep(10) |
| 38 | + |
| 39 | + await drone.action.land() |
| 40 | + await asyncio.sleep(5) |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +async def print_gimbal_position(drone): |
| 45 | + # Report gimbal position updates asynchronously |
| 46 | + # Note that we are getting gimbal position updates in |
| 47 | + # euler angles; we can also get them as quaternions |
| 48 | + async for position in drone.telemetry.camera_attitude_euler(): |
| 49 | + print(position) |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + # Start the main function |
| 54 | + loop = asyncio.get_event_loop() |
| 55 | + loop.run_until_complete(run()) |
0 commit comments