Hello,
I have been trying to pass the MAVSDK drone "System’ object between two different python processes as an argument, such that I have a stand-alone function that connects to mavsdk and creates the drone “System” object in one separate script, and then passes that drone object to another script. It is most likely an issue with my understanding but can anyone tell me why I cannot pass the drone “System” object between separate scripts? Has it something to do with the drone object not being pickleable? I have made two crude scripts below to try to illustrate the problem I have - basically just trying to pass the drone object from one to the other to facilitate printing telemetry.
Thank you very much in advance,
Kind regards,
Jono
Example_Script_1.py:
import asyncio
import multiprocessing
import Example_Script_2
from multiprocessing import Process
from multiprocessing.sharedctypes import Value
async def run():
#Start the drone in another process (Example_Script_2 in this case).
#Process(await Example_Script_2.run(dronequeue))
Process(daemon=True, target=await Example_Script_2.run(dronequeue))
drone = dronequeue.get()
# Start the tasks
asyncio.ensure_future(print_position(drone))
await asyncio.sleep(10)
async def print_position(drone):
async for position in drone.telemetry.position():
print(position)
if __name__ == "__main__":
# Run the asyncio loop
dronequeue = multiprocessing.Queue() #Used to transfer the object between processes.
asyncio.run(run())
Example_Script_2.py:
from mavsdk import System
from multiprocessing.sharedctypes import Value
async def run(dronequeue):
# Init the drone
drone = System()
await drone.connect(system_address="udp://:14540")
print("connected to drone!!!")
dronequeue.put(drone)
return