From 7e6d00cf3d8a39777c90ad911c051d28dd05c5c5 Mon Sep 17 00:00:00 2001 From: Sharad <69742813+TheSharad@users.noreply.github.com> Date: Sun, 16 Aug 2020 20:44:29 +0530 Subject: [PATCH 1/5] Updated goto.py --- examples/goto.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/goto.py b/examples/goto.py index 8a034dfc..12cba328 100755 --- a/examples/goto.py +++ b/examples/goto.py @@ -20,6 +20,11 @@ async def run(): print("Global position estimate ok") break + print("Fetching Absolute Height of Terrain....") + async for terrain_info in drone.telemetry.position(): + absolute_altitude = terrain_info.absolute_altitude_m + break + print("-- Arming") await drone.action.arm() @@ -27,8 +32,9 @@ async def run(): await drone.action.takeoff() await asyncio.sleep(1) - - await drone.action.goto_location(47.399386, 8.535245, 500, float('nan')) + flying_alt = absolute_altitude + 20.0 #To fly drone 20m above the ground plane + #goto_location() takes Absolute MSL altitude + await drone.action.goto_location(47.399386, 8.535245, flying_alt, 0) if __name__ == "__main__": loop = asyncio.get_event_loop() From 8f916f0cd22e03c284419bacf6510a3efc8999d5 Mon Sep 17 00:00:00 2001 From: Sharad <69742813+TheSharad@users.noreply.github.com> Date: Sun, 16 Aug 2020 20:46:51 +0530 Subject: [PATCH 2/5] Added an example for FollowMe Plugin --- examples/follow_me_example.py | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 examples/follow_me_example.py diff --git a/examples/follow_me_example.py b/examples/follow_me_example.py new file mode 100644 index 00000000..636179a0 --- /dev/null +++ b/examples/follow_me_example.py @@ -0,0 +1,73 @@ +#! /usr/bin/env python3 + +#This example shows how to use the follow me plugin + +import asyncio +from mavsdk import System +from mavsdk.follow_me import (Config, FollowMeError, TargetLocation) + +default_height = 8.0 #in Meters +follow_distance = 2.0 #in Meters, this is the distance that the drone will remain away from Target while following it +#Direction relative to the Target +#Options are NONE, FRONT, FRONT_LEFT, FRONT_RIGHT, BEHIND +direction = Config.FollowDirection.BEHIND +responsiveness = 0.02 + +#This list contains fake location coordinates (These coordinates are obtained from mission.py example) +fake_location = [[47.398039859999997,8.5455725400000002],[47.398036222362471,8.5450146439425509],[47.397825620791885,8.5450092830163271]] + +async def fly_drone(): + drone = System() + await drone.connect(system_address="udp://:14540") + + #This waits till a mavlink based drone is connected + async for state in drone.core.connection_state(): + if state.is_connected: + print(f"-- Connected to drone with UUID: {state.uuid}") + break + + #Checking if Global Position Estimate is ok + async for global_lock in drone.telemetry.health(): + if global_lock.is_global_position_ok: + print("-- Global position state is good enough for flying.") + break + + #Arming the drone + print ("-- Arming") + await drone.action.arm() + await asyncio.sleep(1) + + #Follow me Mode requires some configuration to be done before starting the mode + conf = Config(default_height, follow_distance, direction, responsiveness) + await drone.follow_me.set_config(conf) + await asyncio.sleep(1) + + print ("-- Taking Off") + await drone.action.takeoff() + await asyncio.sleep(8) + print ("-- Starting Follow Me Mode") + await drone.follow_me.start() + await asyncio.sleep(8) + + #This for loop provides fake coordinates from the fake_location list for the follow me mode to work + #In a simulator it won't make much sense though + for latitude,longitude in fake_location: + target = TargetLocation(latitude, longitude, 0, 0, 0, 0) + print ("-- Following Target") + await drone.follow_me.set_target_location(target) + await asyncio.sleep(2) + + #Stopping the follow me mode + print ("-- Stopping Follow Me Mode") + await drone.follow_me.stop() + await asyncio.sleep(5) + + print ("-- Landing") + await drone.action.land() + await asyncio.sleep(35) + print ("-- Disarming") + await drone.action.disarm() + +if __name__ == "__main__": + loop = asyncio.get_event_loop() + loop.run_until_complete(fly_drone()) From b8154bc6c485484e42c920dc121edd2063cc7b88 Mon Sep 17 00:00:00 2001 From: Sharad Sharma <69742813+TheSharad@users.noreply.github.com> Date: Mon, 17 Aug 2020 14:23:32 +0530 Subject: [PATCH 3/5] updated goto.py for better understanding Changed print statement --> print("Fetching Absolute Height of Terrain....") to print("Fetching altitude amsl at home location....") so as to better reflect the reasons for fetching position() update. --- examples/goto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/goto.py b/examples/goto.py index 12cba328..42b59786 100755 --- a/examples/goto.py +++ b/examples/goto.py @@ -20,7 +20,7 @@ async def run(): print("Global position estimate ok") break - print("Fetching Absolute Height of Terrain....") + print("Fetching altitude amsl at home location....") async for terrain_info in drone.telemetry.position(): absolute_altitude = terrain_info.absolute_altitude_m break From aa82880f6b202643b93391621c3ef8debd4a9641 Mon Sep 17 00:00:00 2001 From: Sharad Sharma <69742813+TheSharad@users.noreply.github.com> Date: Mon, 17 Aug 2020 21:37:07 +0530 Subject: [PATCH 4/5] Removed unnecessary code Removed unnecessary sleep and disarm statements to make the code cleaner and better. No need to disarm manually as that happens automatically once the system detects landing. --- examples/follow_me_example.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/examples/follow_me_example.py b/examples/follow_me_example.py index 636179a0..1053c32c 100644 --- a/examples/follow_me_example.py +++ b/examples/follow_me_example.py @@ -35,12 +35,10 @@ async def fly_drone(): #Arming the drone print ("-- Arming") await drone.action.arm() - await asyncio.sleep(1) #Follow me Mode requires some configuration to be done before starting the mode conf = Config(default_height, follow_distance, direction, responsiveness) await drone.follow_me.set_config(conf) - await asyncio.sleep(1) print ("-- Taking Off") await drone.action.takeoff() @@ -64,9 +62,6 @@ async def fly_drone(): print ("-- Landing") await drone.action.land() - await asyncio.sleep(35) - print ("-- Disarming") - await drone.action.disarm() if __name__ == "__main__": loop = asyncio.get_event_loop() From 067c0cd3905fc36ec1c83cce47dc8bd8eb72d65c Mon Sep 17 00:00:00 2001 From: Sharad Sharma <69742813+TheSharad@users.noreply.github.com> Date: Mon, 17 Aug 2020 21:47:00 +0530 Subject: [PATCH 5/5] changed position() to home() Changed the usage of position() with home() to make sure that drone always gets the correct home altitude as if the drone is in air position() will provide the current altitude which if used without caution can result in issues. --- examples/goto.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/goto.py b/examples/goto.py index 42b59786..f4f76c58 100755 --- a/examples/goto.py +++ b/examples/goto.py @@ -20,8 +20,8 @@ async def run(): print("Global position estimate ok") break - print("Fetching altitude amsl at home location....") - async for terrain_info in drone.telemetry.position(): + print("Fetching amsl altitude at home location....") + async for terrain_info in drone.telemetry.home(): absolute_altitude = terrain_info.absolute_altitude_m break