From d44ec164b4ca95aedecedb98959296ab6648045e Mon Sep 17 00:00:00 2001 From: Alessandro Simovic Date: Mon, 21 Mar 2022 11:51:59 +0100 Subject: [PATCH] same con and GPS checks in all examples --- examples/camera.py | 2 +- examples/failure_injection.py | 4 ++-- examples/firmware_version.py | 2 +- examples/follow_me_example.py | 10 +++++----- examples/geofence.py | 4 ++-- examples/goto.py | 6 +++--- examples/logfile_download.py | 2 +- examples/manual_control.py | 7 ++++--- examples/mission.py | 8 +++++++- examples/mission_import.py | 2 +- examples/offboard_attitude.py | 8 +++++++- examples/offboard_position_ned.py | 12 ++++++++++++ examples/offboard_position_velocity_ned.py | 8 +++++++- examples/offboard_velocity_body.py | 8 +++++++- examples/offboard_velocity_ned.py | 8 +++++++- examples/shell.py | 2 +- examples/takeoff_and_land.py | 6 +++--- examples/takeoff_and_land_keyboard_control.py | 6 +++--- examples/telemetry_flight_mode.py | 2 +- examples/telemetry_takeoff_and_land.py | 7 ++++++- examples/tune.py | 2 +- 21 files changed, 82 insertions(+), 34 deletions(-) diff --git a/examples/camera.py b/examples/camera.py index 196075e5..e39f0981 100755 --- a/examples/camera.py +++ b/examples/camera.py @@ -13,7 +13,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") break print_mode_task = asyncio.ensure_future(print_mode(drone)) diff --git a/examples/failure_injection.py b/examples/failure_injection.py index 93653dee..d3437b56 100755 --- a/examples/failure_injection.py +++ b/examples/failure_injection.py @@ -12,13 +12,13 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered with UUID: {state.uuid}") + print(f"-- Connected to drone!") break print("Waiting for drone to have a global position estimate...") async for health in drone.telemetry.health(): if health.is_global_position_ok and health.is_home_position_ok: - print("Global position estimate ok") + print("-- Global position estimate OK") break print("-- Enabling failure injection") diff --git a/examples/firmware_version.py b/examples/firmware_version.py index cae8a9e3..63bc2d43 100755 --- a/examples/firmware_version.py +++ b/examples/firmware_version.py @@ -11,7 +11,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") break info = await drone.info.get_version() diff --git a/examples/follow_me_example.py b/examples/follow_me_example.py index 79e7b8cc..da80bd6e 100755 --- a/examples/follow_me_example.py +++ b/examples/follow_me_example.py @@ -20,16 +20,16 @@ async def fly_drone(): drone = System() await drone.connect(system_address="udp://:14540") - #This waits till a mavlink based drone is connected + print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: print(f"-- Connected to drone!") break - #Checking if Global Position Estimate is ok - async for global_lock in drone.telemetry.health(): - if global_lock.is_global_position_ok and global_lock.is_home_position_ok: - print("-- Global position state is good enough for flying.") + print("Waiting for drone to have a global position estimate...") + async for health in drone.telemetry.health(): + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position estimate OK") break #Arming the drone diff --git a/examples/geofence.py b/examples/geofence.py index f62be98c..e8a28209 100755 --- a/examples/geofence.py +++ b/examples/geofence.py @@ -19,10 +19,10 @@ async def run(): await drone.connect(system_address="udp://:14540") # Wait for the drone to connect - print("Waiting for drone...") + print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") break # Fetch the home location coordinates, in order to set a boundary around the home location diff --git a/examples/goto.py b/examples/goto.py index 24624194..198f255a 100755 --- a/examples/goto.py +++ b/examples/goto.py @@ -11,13 +11,13 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print("Drone discovered!") + print(f"-- Connected to drone!") 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") + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position state is good enough for flying.") break print("Fetching amsl altitude at home location....") diff --git a/examples/logfile_download.py b/examples/logfile_download.py index 39282bce..71af0ff7 100755 --- a/examples/logfile_download.py +++ b/examples/logfile_download.py @@ -12,7 +12,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered") + print(f"-- Connected to drone!") break entries = await get_entries(drone) diff --git a/examples/manual_control.py b/examples/manual_control.py index 115aea5f..a0ed64b7 100755 --- a/examples/manual_control.py +++ b/examples/manual_control.py @@ -35,15 +35,16 @@ async def manual_controls(): await drone.connect(system_address="udp://:14540") # This waits till a mavlink based drone is connected + print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: print(f"-- Connected to drone!") 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 ok") + async for health in drone.telemetry.health(): + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position state is good enough for flying.") break # set the manual control input after arming diff --git a/examples/mission.py b/examples/mission.py index 2c0570ef..93f0affd 100755 --- a/examples/mission.py +++ b/examples/mission.py @@ -13,7 +13,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print("Drone discovered!") + print(f"-- Connected to drone!") break print_mission_progress_task = asyncio.ensure_future( @@ -71,6 +71,12 @@ async def run(): print("-- Uploading mission") await drone.mission.upload_mission(mission_plan) + print("Waiting for drone to have a global position estimate...") + async for health in drone.telemetry.health(): + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position estimate OK") + break + print("-- Arming") await drone.action.arm() diff --git a/examples/mission_import.py b/examples/mission_import.py index 86220df4..2b6f2dd2 100755 --- a/examples/mission_import.py +++ b/examples/mission_import.py @@ -13,7 +13,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print("Drone discovered!") + print(f"-- Connected to drone!") break mission_import_data = await drone.mission_raw.import_qgroundcontrol_mission("example-mission.plan") diff --git a/examples/offboard_attitude.py b/examples/offboard_attitude.py index f36133e9..4ecbf13b 100755 --- a/examples/offboard_attitude.py +++ b/examples/offboard_attitude.py @@ -20,7 +20,13 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") + break + + print("Waiting for drone to have a global position estimate...") + async for health in drone.telemetry.health(): + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position estimate OK") break print("-- Arming") diff --git a/examples/offboard_position_ned.py b/examples/offboard_position_ned.py index fce612e0..5c6dedb7 100755 --- a/examples/offboard_position_ned.py +++ b/examples/offboard_position_ned.py @@ -20,6 +20,18 @@ 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(f"-- Connected to drone!") + break + + print("Waiting for drone to have a global position estimate...") + async for health in drone.telemetry.health(): + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position estimate OK") + break + print("-- Arming") await drone.action.arm() diff --git a/examples/offboard_position_velocity_ned.py b/examples/offboard_position_velocity_ned.py index db8feaee..d8513687 100755 --- a/examples/offboard_position_velocity_ned.py +++ b/examples/offboard_position_velocity_ned.py @@ -12,7 +12,13 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered with UUID: {state.uuid}") + print(f"-- Connected to drone!") + break + + print("Waiting for drone to have a global position estimate...") + async for health in drone.telemetry.health(): + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position estimate OK") break print("-- Arming") diff --git a/examples/offboard_velocity_body.py b/examples/offboard_velocity_body.py index 886f4d67..aa6562b0 100755 --- a/examples/offboard_velocity_body.py +++ b/examples/offboard_velocity_body.py @@ -16,7 +16,13 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") + break + + print("Waiting for drone to have a global position estimate...") + async for health in drone.telemetry.health(): + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position estimate OK") break print("-- Arming") diff --git a/examples/offboard_velocity_ned.py b/examples/offboard_velocity_ned.py index 43f03ccc..e8e70884 100755 --- a/examples/offboard_velocity_ned.py +++ b/examples/offboard_velocity_ned.py @@ -16,7 +16,13 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") + break + + print("Waiting for drone to have a global position estimate...") + async for health in drone.telemetry.health(): + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position estimate OK") break print("-- Arming") diff --git a/examples/shell.py b/examples/shell.py index 71a61a13..9a97ce9f 100755 --- a/examples/shell.py +++ b/examples/shell.py @@ -15,7 +15,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") break asyncio.get_event_loop().add_reader(sys.stdin, got_stdin_data, drone) diff --git a/examples/takeoff_and_land.py b/examples/takeoff_and_land.py index 7899fe93..31a1d524 100755 --- a/examples/takeoff_and_land.py +++ b/examples/takeoff_and_land.py @@ -12,13 +12,13 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") 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") + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position estimate OK") break print("-- Arming") diff --git a/examples/takeoff_and_land_keyboard_control.py b/examples/takeoff_and_land_keyboard_control.py index 27d2174c..5e9787f6 100644 --- a/examples/takeoff_and_land_keyboard_control.py +++ b/examples/takeoff_and_land_keyboard_control.py @@ -24,13 +24,13 @@ async def setup(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") 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") + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position estimate OK") break diff --git a/examples/telemetry_flight_mode.py b/examples/telemetry_flight_mode.py index 33eedc8f..3159c759 100755 --- a/examples/telemetry_flight_mode.py +++ b/examples/telemetry_flight_mode.py @@ -11,7 +11,7 @@ async def print_flight_mode(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") break async for flight_mode in drone.telemetry.flight_mode(): diff --git a/examples/telemetry_takeoff_and_land.py b/examples/telemetry_takeoff_and_land.py index e30016a1..0cb35247 100755 --- a/examples/telemetry_takeoff_and_land.py +++ b/examples/telemetry_takeoff_and_land.py @@ -31,7 +31,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") break # Start parallel tasks @@ -41,6 +41,11 @@ async def run(): running_tasks = [print_altitude_task, print_flight_mode_task] termination_task = asyncio.ensure_future(observe_is_in_air(drone, running_tasks)) + async for health in drone.telemetry.health(): + if health.is_global_position_ok and health.is_home_position_ok: + print("-- Global position state is good enough for flying.") + break + # Execute the maneuvers print("-- Arming") await drone.action.arm() diff --git a/examples/tune.py b/examples/tune.py index facb76ee..6989d03b 100755 --- a/examples/tune.py +++ b/examples/tune.py @@ -13,7 +13,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"Drone discovered!") + print(f"-- Connected to drone!") break song_elements = []