QGC Mission Upload using MAVSDK python for multiple aircraft

Hello!

I have two scripts based upon the python “mission_import.py” script found here. This “mission_import.py” script works fine (my working version of this is attached for direct comparison).

I am trying to expand this do that I can distribute QGC mission files to more than just one drone. I have connected multiple drones each with their own MAVSDK server reporting such things as telemetry etc with no problems using the same connection code as is in the failing script below (“QGC_Mission_Upload_MULTI_DRONE.py”). However, when I want to upload the QGC mission file I receive an error message to the effect of:
“mavsdk.mission_raw.MissionRawError: FAILED_TO_OPEN_QGC_PLAN: ‘Failed To Open Qgc Plan’; origin: import_qgroundcontrol_mission(); params: (‘autogen_mission_ACID1.plan’,)” (full error text attached). Note also that the drone connects and receives the GPS signal fine so it would seem the actual connection is established properly?.

I have tried many different variations of this each with the same error message. I believe the error message relates to the way I am connecting to the drone(s), because the actual mission upload lines of code are identical between the single drone script that works, and the multi drone script that does not work.

Is anyone able to help me / shed some light on where I am going wrong here? I copy the text of the failing script below (I could not work out how to attach it sorry).

Thanks very much for your help in advance!

Kind regards,

Jono

##################################################################################

QGC_Mission_Upload_MULTI_DRONE

import asyncio
from mavsdk import System
import subprocess
import os

async def run(ACID):
#Determine the directory for use in the mav SDK starts
fn = os.getcwd()
add = “/venv/lib/python3.8/site-packages/mavsdk/bin”
full_filename = (fn + add)
#
#Start MAVSDK servers
svr_port = 50040 + ACID - 1
sys_address = 14540 + ACID - 1
alphanumeric_string = ’ ./mavsdk_server udp://:%s -p %s’ % (sys_address,svr_port)
subprocess.call([‘gnome-terminal’, ‘–’, ‘sh’, ‘-c’, alphanumeric_string], cwd=full_filename)
#
#Connect drones to MAVSDK servers
drone = System(mavsdk_server_address=“localhost”, port=svr_port)
await drone.connect(system_address=sys_address)
print(“Waiting for drone”,ACID,“to connect…”)
async for state in drone.core.connection_state():
if state.is_connected:
print(f"-- Connected to drone",ACID,“!”)
break
print(“Waiting for drone”,ACID,“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(“-- Drone”,ACID,“global position estimate OK”)
break
#
# Upload the mission file to the drone
mission_import_data = await drone.mission_raw.import_qgroundcontrol_mission(“autogen_mission_ACID1.plan”)
print(f"{len(mission_import_data.mission_items)} mission items imported")
await drone.mission_raw.upload_mission(mission_import_data.mission_items)
print(“Mission uploaded”)
#
if name == “main”:
ACID = 1
loop = asyncio.get_event_loop()
loop.run_until_complete(run(ACID))

##################################################################################

##################################################################################
The error message:

Waiting for drone 1 to connect…
– Connected to drone 1 !
Waiting for drone 1 to have a global position estimate…
Traceback (most recent call last):
File “/home/jono/Documents/PycharmProjects/Targeting 22-11-18/QGC_Mission_Upload_MULTI_DRONE.py”, line 42, in
loop.run_until_complete(run(ACID))
File “/usr/lib/python3.8/asyncio/base_events.py”, line 616, in run_until_complete
return future.result()
File “/home/jono/Documents/PycharmProjects/Targeting 22-11-18/QGC_Mission_Upload_MULTI_DRONE.py”, line 34, in run
mission_import_data = await drone.mission_raw.import_qgroundcontrol_mission(“autogen_mission_ACID1.plan”)
File “/home/jono/Documents/PycharmProjects/Targeting 22-11-18/venv/lib/python3.8/site-packages/mavsdk/mission_raw.py”, line 973, in import_qgroundcontrol_mission
raise MissionRawError(result, “import_qgroundcontrol_mission()”, qgc_plan_path)
mavsdk.mission_raw.MissionRawError: FAILED_TO_OPEN_QGC_PLAN: ‘Failed To Open Qgc Plan’; origin: import_qgroundcontrol_mission(); params: (‘autogen_mission_ACID1.plan’,)
Exception ignored in: <function System.del at 0x7f812c01bf70>
Traceback (most recent call last):
File “/home/jono/Documents/PycharmProjects/Targeting 22-11-18/venv/lib/python3.8/site-packages/mavsdk/system.py”, line 86, in del
File “/home/jono/Documents/PycharmProjects/Targeting 22-11-18/venv/lib/python3.8/site-packages/mavsdk/system.py”, line 122, in _stop_mavsdk_server
ImportError: sys.meta_path is None, Python is likely shutting down
– Drone 1 global position estimate OK

Process finished with exit code 1
################################################################################

Crisis averted… I have found out that for some reason when running the example “mission_import.py” script only the python script name is required for the “qgc_plan_path”, whereas in my bespoke multi aircraft script it requires the full path of the qgc .plan file. May be related to the use of individual MAVSDK servers for each aircraft - not too sure…

SOLVED!

1 Like