Skip to content

Commit 50a811e

Browse files
Merge pull request mavlink#456 from potaito/pr-unify-initial-checks
Same connection and GPS checks in all examples
2 parents 108ef86 + d44ec16 commit 50a811e

21 files changed

+82
-34
lines changed

examples/camera.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async def run():
1313
print("Waiting for drone to connect...")
1414
async for state in drone.core.connection_state():
1515
if state.is_connected:
16-
print(f"Drone discovered!")
16+
print(f"-- Connected to drone!")
1717
break
1818

1919
print_mode_task = asyncio.ensure_future(print_mode(drone))

examples/failure_injection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ async def run():
1212
print("Waiting for drone to connect...")
1313
async for state in drone.core.connection_state():
1414
if state.is_connected:
15-
print(f"Drone discovered with UUID: {state.uuid}")
15+
print(f"-- Connected to drone!")
1616
break
1717

1818
print("Waiting for drone to have a global position estimate...")
1919
async for health in drone.telemetry.health():
2020
if health.is_global_position_ok and health.is_home_position_ok:
21-
print("Global position estimate ok")
21+
print("-- Global position estimate OK")
2222
break
2323

2424
print("-- Enabling failure injection")

examples/firmware_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async def run():
1111
print("Waiting for drone to connect...")
1212
async for state in drone.core.connection_state():
1313
if state.is_connected:
14-
print(f"Drone discovered!")
14+
print(f"-- Connected to drone!")
1515
break
1616

1717
info = await drone.info.get_version()

examples/follow_me_example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ async def fly_drone():
2020
drone = System()
2121
await drone.connect(system_address="udp://:14540")
2222

23-
#This waits till a mavlink based drone is connected
23+
print("Waiting for drone to connect...")
2424
async for state in drone.core.connection_state():
2525
if state.is_connected:
2626
print(f"-- Connected to drone!")
2727
break
2828

29-
#Checking if Global Position Estimate is ok
30-
async for global_lock in drone.telemetry.health():
31-
if global_lock.is_global_position_ok and global_lock.is_home_position_ok:
32-
print("-- Global position state is good enough for flying.")
29+
print("Waiting for drone to have a global position estimate...")
30+
async for health in drone.telemetry.health():
31+
if health.is_global_position_ok and health.is_home_position_ok:
32+
print("-- Global position estimate OK")
3333
break
3434

3535
#Arming the drone

examples/geofence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ async def run():
1919
await drone.connect(system_address="udp://:14540")
2020

2121
# Wait for the drone to connect
22-
print("Waiting for drone...")
22+
print("Waiting for drone to connect...")
2323
async for state in drone.core.connection_state():
2424
if state.is_connected:
25-
print(f"Drone discovered!")
25+
print(f"-- Connected to drone!")
2626
break
2727

2828
# Fetch the home location coordinates, in order to set a boundary around the home location

examples/goto.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ async def run():
1111
print("Waiting for drone to connect...")
1212
async for state in drone.core.connection_state():
1313
if state.is_connected:
14-
print("Drone discovered!")
14+
print(f"-- Connected to drone!")
1515
break
1616

1717
print("Waiting for drone to have a global position estimate...")
1818
async for health in drone.telemetry.health():
19-
if health.is_global_position_ok:
20-
print("Global position estimate ok")
19+
if health.is_global_position_ok and health.is_home_position_ok:
20+
print("-- Global position state is good enough for flying.")
2121
break
2222

2323
print("Fetching amsl altitude at home location....")

examples/logfile_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async def run():
1212
print("Waiting for drone to connect...")
1313
async for state in drone.core.connection_state():
1414
if state.is_connected:
15-
print(f"Drone discovered")
15+
print(f"-- Connected to drone!")
1616
break
1717

1818
entries = await get_entries(drone)

examples/manual_control.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ async def manual_controls():
3535
await drone.connect(system_address="udp://:14540")
3636

3737
# This waits till a mavlink based drone is connected
38+
print("Waiting for drone to connect...")
3839
async for state in drone.core.connection_state():
3940
if state.is_connected:
4041
print(f"-- Connected to drone!")
4142
break
4243

4344
# Checking if Global Position Estimate is ok
44-
async for global_lock in drone.telemetry.health():
45-
if global_lock.is_global_position_ok:
46-
print("-- Global position state is ok")
45+
async for health in drone.telemetry.health():
46+
if health.is_global_position_ok and health.is_home_position_ok:
47+
print("-- Global position state is good enough for flying.")
4748
break
4849

4950
# set the manual control input after arming

examples/mission.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async def run():
1313
print("Waiting for drone to connect...")
1414
async for state in drone.core.connection_state():
1515
if state.is_connected:
16-
print("Drone discovered!")
16+
print(f"-- Connected to drone!")
1717
break
1818

1919
print_mission_progress_task = asyncio.ensure_future(
@@ -71,6 +71,12 @@ async def run():
7171
print("-- Uploading mission")
7272
await drone.mission.upload_mission(mission_plan)
7373

74+
print("Waiting for drone to have a global position estimate...")
75+
async for health in drone.telemetry.health():
76+
if health.is_global_position_ok and health.is_home_position_ok:
77+
print("-- Global position estimate OK")
78+
break
79+
7480
print("-- Arming")
7581
await drone.action.arm()
7682

examples/mission_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async def run():
1313
print("Waiting for drone to connect...")
1414
async for state in drone.core.connection_state():
1515
if state.is_connected:
16-
print("Drone discovered!")
16+
print(f"-- Connected to drone!")
1717
break
1818

1919
mission_import_data = await drone.mission_raw.import_qgroundcontrol_mission("example-mission.plan")

examples/offboard_attitude.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ async def run():
2020
print("Waiting for drone to connect...")
2121
async for state in drone.core.connection_state():
2222
if state.is_connected:
23-
print(f"Drone discovered!")
23+
print(f"-- Connected to drone!")
24+
break
25+
26+
print("Waiting for drone to have a global position estimate...")
27+
async for health in drone.telemetry.health():
28+
if health.is_global_position_ok and health.is_home_position_ok:
29+
print("-- Global position estimate OK")
2430
break
2531

2632
print("-- Arming")

examples/offboard_position_ned.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ async def run():
2020
drone = System()
2121
await drone.connect(system_address="udp://:14540")
2222

23+
print("Waiting for drone to connect...")
24+
async for state in drone.core.connection_state():
25+
if state.is_connected:
26+
print(f"-- Connected to drone!")
27+
break
28+
29+
print("Waiting for drone to have a global position estimate...")
30+
async for health in drone.telemetry.health():
31+
if health.is_global_position_ok and health.is_home_position_ok:
32+
print("-- Global position estimate OK")
33+
break
34+
2335
print("-- Arming")
2436
await drone.action.arm()
2537

examples/offboard_position_velocity_ned.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ async def run():
1212
print("Waiting for drone to connect...")
1313
async for state in drone.core.connection_state():
1414
if state.is_connected:
15-
print(f"Drone discovered with UUID: {state.uuid}")
15+
print(f"-- Connected to drone!")
16+
break
17+
18+
print("Waiting for drone to have a global position estimate...")
19+
async for health in drone.telemetry.health():
20+
if health.is_global_position_ok and health.is_home_position_ok:
21+
print("-- Global position estimate OK")
1622
break
1723

1824
print("-- Arming")

examples/offboard_velocity_body.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ async def run():
1616
print("Waiting for drone to connect...")
1717
async for state in drone.core.connection_state():
1818
if state.is_connected:
19-
print(f"Drone discovered!")
19+
print(f"-- Connected to drone!")
20+
break
21+
22+
print("Waiting for drone to have a global position estimate...")
23+
async for health in drone.telemetry.health():
24+
if health.is_global_position_ok and health.is_home_position_ok:
25+
print("-- Global position estimate OK")
2026
break
2127

2228
print("-- Arming")

examples/offboard_velocity_ned.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ async def run():
1616
print("Waiting for drone to connect...")
1717
async for state in drone.core.connection_state():
1818
if state.is_connected:
19-
print(f"Drone discovered!")
19+
print(f"-- Connected to drone!")
20+
break
21+
22+
print("Waiting for drone to have a global position estimate...")
23+
async for health in drone.telemetry.health():
24+
if health.is_global_position_ok and health.is_home_position_ok:
25+
print("-- Global position estimate OK")
2026
break
2127

2228
print("-- Arming")

examples/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async def run():
1515
print("Waiting for drone to connect...")
1616
async for state in drone.core.connection_state():
1717
if state.is_connected:
18-
print(f"Drone discovered!")
18+
print(f"-- Connected to drone!")
1919
break
2020

2121
asyncio.get_event_loop().add_reader(sys.stdin, got_stdin_data, drone)

examples/takeoff_and_land.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ async def run():
1212
print("Waiting for drone to connect...")
1313
async for state in drone.core.connection_state():
1414
if state.is_connected:
15-
print(f"Drone discovered!")
15+
print(f"-- Connected to drone!")
1616
break
1717

1818
print("Waiting for drone to have a global position estimate...")
1919
async for health in drone.telemetry.health():
20-
if health.is_global_position_ok:
21-
print("Global position estimate ok")
20+
if health.is_global_position_ok and health.is_home_position_ok:
21+
print("-- Global position estimate OK")
2222
break
2323

2424
print("-- Arming")

examples/takeoff_and_land_keyboard_control.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ async def setup():
2424
print("Waiting for drone to connect...")
2525
async for state in drone.core.connection_state():
2626
if state.is_connected:
27-
print(f"Drone discovered!")
27+
print(f"-- Connected to drone!")
2828
break
2929

3030
print("Waiting for drone to have a global position estimate...")
3131
async for health in drone.telemetry.health():
32-
if health.is_global_position_ok:
33-
print("Global position estimate ok")
32+
if health.is_global_position_ok and health.is_home_position_ok:
33+
print("-- Global position estimate OK")
3434
break
3535

3636

examples/telemetry_flight_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async def print_flight_mode():
1111
print("Waiting for drone to connect...")
1212
async for state in drone.core.connection_state():
1313
if state.is_connected:
14-
print(f"Drone discovered!")
14+
print(f"-- Connected to drone!")
1515
break
1616

1717
async for flight_mode in drone.telemetry.flight_mode():

examples/telemetry_takeoff_and_land.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def run():
3131
print("Waiting for drone to connect...")
3232
async for state in drone.core.connection_state():
3333
if state.is_connected:
34-
print(f"Drone discovered!")
34+
print(f"-- Connected to drone!")
3535
break
3636

3737
# Start parallel tasks
@@ -41,6 +41,11 @@ async def run():
4141
running_tasks = [print_altitude_task, print_flight_mode_task]
4242
termination_task = asyncio.ensure_future(observe_is_in_air(drone, running_tasks))
4343

44+
async for health in drone.telemetry.health():
45+
if health.is_global_position_ok and health.is_home_position_ok:
46+
print("-- Global position state is good enough for flying.")
47+
break
48+
4449
# Execute the maneuvers
4550
print("-- Arming")
4651
await drone.action.arm()

examples/tune.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async def run():
1313
print("Waiting for drone to connect...")
1414
async for state in drone.core.connection_state():
1515
if state.is_connected:
16-
print(f"Drone discovered!")
16+
print(f"-- Connected to drone!")
1717
break
1818

1919
song_elements = []

0 commit comments

Comments
 (0)