Skip to content

Commit

Permalink
Merge pull request #456 from potaito/pr-unify-initial-checks
Browse files Browse the repository at this point in the history
Same connection and GPS checks in all examples
  • Loading branch information
JonasVautherin authored Mar 21, 2022
2 parents 108ef86 + d44ec16 commit 50a811e
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions examples/failure_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion examples/firmware_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions examples/follow_me_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/geofence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/goto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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....")
Expand Down
2 changes: 1 addition & 1 deletion examples/logfile_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions examples/manual_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion examples/mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion examples/mission_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 7 additions & 1 deletion examples/offboard_attitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions examples/offboard_position_ned.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 7 additions & 1 deletion examples/offboard_position_velocity_ned.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 7 additions & 1 deletion examples/offboard_velocity_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 7 additions & 1 deletion examples/offboard_velocity_ned.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion examples/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions examples/takeoff_and_land.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions examples/takeoff_and_land_keyboard_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion examples/telemetry_flight_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
7 changes: 6 additions & 1 deletion examples/telemetry_takeoff_and_land.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down

0 comments on commit 50a811e

Please sign in to comment.