Created
December 22, 2021 11:05
-
-
Save AmitGupta7580/022ab3ba266559ccec04e6b47bc53ae4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import asyncio | |
from mavsdk import System | |
async def run(): | |
print("Code Initialized---") | |
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 | |
previous_altitude = None | |
async for position in drone.telemetry.position(): | |
altitude = round(position.relative_altitude_m) | |
latitude = round(position.latitude_deg) | |
longitude = round(position.longitude_deg) | |
if altitude != previous_altitude: | |
previous_altitude = altitude | |
break; | |
print(latitude,longitude,altitude) | |
new_altitude = altitude + 1.0 | |
print("-- Arming") | |
await drone.action.arm() | |
print("-- Taking off") | |
await drone.action.goto_location(latitude,longitude,new_altitude,0) | |
await asyncio.sleep(20) | |
print("-- Landing") | |
await drone.action.land() | |
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