Skip to content

Instantly share code, notes, and snippets.

@AmitGupta7580
Created December 22, 2021 11:12
Show Gist options
  • Save AmitGupta7580/cc7091579ea683606a17bbc7874c7e2e to your computer and use it in GitHub Desktop.
Save AmitGupta7580/cc7091579ea683606a17bbc7874c7e2e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import asyncio
from mavsdk import System
async def run():
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("Drone discovered!")
break
print("Waiting for drone to have a global position estimate...")
async for health in drone.telemetry.health():
if health.is_global_position_ok:
print("Global position estimate ok")
break
print("Fetching amsl altitude at home location....")
async for terrain_info in drone.telemetry.home():
absolute_altitude = terrain_info.absolute_altitude_m
break
print("-- Arming")
await drone.action.arm()
print("-- Taking off")
await drone.action.takeoff()
await asyncio.sleep(1)
# To fly drone 20m above the ground plane
flying_alt = absolute_altitude + 20.0
# goto_location() takes Absolute MSL altitude
await drone.action.goto_location(47.397606, 8.543060, flying_alt, 0)
while True:
print("Staying connected, press Ctrl-C to exit")
await asyncio.sleep(1)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment