Skip to content

Commit

Permalink
update examples to use new Drone class
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasVautherin committed Sep 17, 2019
1 parent 7743709 commit 42408d6
Show file tree
Hide file tree
Showing 14 changed files with 410 additions and 322 deletions.
16 changes: 8 additions & 8 deletions examples/calibration.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/usr/bin/env python3

import asyncio

from mavsdk import start_mavlink
from mavsdk import connect as mavsdk_connect

start_mavlink(connection_url="udp://:14540")
drone = mavsdk_connect(host="127.0.0.1")
from mavsdk import Drone


async def run():

drone = Drone()
await drone.connect(drone_address="udp://:14540")

print("-- Starting gyro calibration")
async for progress_data in drone.calibration.calibrate_gyro():
print(progress_data)
Expand All @@ -19,5 +17,7 @@ async def run():
async for progress_data in drone.calibration.calibrate_magnetometer():
print(progress_data)

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
22 changes: 11 additions & 11 deletions examples/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import asyncio

from mavsdk import start_mavlink
from mavsdk import connect as mavsdk_connect
from mavsdk import (CameraError, CameraMode)

start_mavlink()
drone = mavsdk_connect(host="127.0.0.1")
from mavsdk import Drone


async def run():
drone = Drone()
await drone.connect(drone_address="udp://:14540")

asyncio.ensure_future(print_camera_mode(drone))
asyncio.ensure_future(print_camera_status(drone))

print("Setting mode to 'PHOTO'")
try:
await drone.camera.set_mode(CameraMode.PHOTO)
Expand All @@ -28,17 +30,15 @@ async def run():
# Shut down the running coroutines (here 'print_camera_mode()' and 'print_camera_status()')
await asyncio.get_event_loop().shutdown_asyncgens()

async def print_camera_mode():
async def print_camera_mode(drone):
async for camera_mode in drone.camera.mode():
print(f"Camera mode: {camera_mode}")

async def print_camera_status():
async def print_camera_status(drone):
async for camera_status in drone.camera.camera_status():
print(camera_status)


if __name__ == "__main__":
asyncio.ensure_future(print_camera_mode())
asyncio.ensure_future(print_camera_status())

asyncio.get_event_loop().run_until_complete(run())
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
14 changes: 6 additions & 8 deletions examples/firmware_version.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#!/usr/bin/env python3

import asyncio

from mavsdk import start_mavlink
from mavsdk import connect as mavsdk_connect

start_mavlink(connection_url="udp://:14540")
drone = mavsdk_connect(host="127.0.0.1")
from mavsdk import Drone


async def run():
drone = Drone()
await drone.connect(drone_address="udp://:14540")

info = await drone.info.get_version()
print(info)


loop = asyncio.get_event_loop()
loop.run_until_complete(run())
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
27 changes: 13 additions & 14 deletions examples/mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import asyncio

from mavsdk import start_mavlink
from mavsdk import connect as mavsdk_connect
from mavsdk import Drone
from mavsdk import (MissionItem)

start_mavlink(connection_url="udp://:14540")
drone = mavsdk_connect(host="127.0.0.1")


async def run():
drone = Drone()
await drone.connect(drone_address="udp://:14540")

asyncio.ensure_future(print_mission_progress(drone))
termination_task = asyncio.ensure_future(observe_is_in_air(drone))

mission_items = []
mission_items.append(MissionItem(47.398039859999997,
8.5455725400000002,
Expand Down Expand Up @@ -54,13 +56,15 @@ async def run():
print("-- Starting mission")
await drone.mission.start_mission()

await termination_task

async def print_mission_progress():

async def print_mission_progress(drone):
async for mission_progress in drone.mission.mission_progress():
print(f"Mission progress: {mission_progress.current_item_index}/{mission_progress.mission_count}")


async def observe_is_in_air():
async def observe_is_in_air(drone):
""" Monitors whether the drone is flying or not and
returns after landing """

Expand All @@ -75,11 +79,6 @@ async def observe_is_in_air():
return


def setup_tasks():
asyncio.ensure_future(run())
asyncio.ensure_future(print_mission_progress())


if __name__ == "__main__":
setup_tasks()
asyncio.get_event_loop().run_until_complete(observe_is_in_air())
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
217 changes: 0 additions & 217 deletions examples/offboard.py

This file was deleted.

Loading

0 comments on commit 42408d6

Please sign in to comment.