Search code examples
dronekit-pythondronekit

Calling vehicle = connect() on 2 python code cause connection to drop


I have 2 python codes that run in subprocess, both calling vehicle = connect('/dev/ttyS0', heartbeat_timeout = 30, baud = 57600) simultaneously for different tasks (for radio controller's channels logging, automation, etc).

the codes work as intended but the connection between Raspberry Pi and PixHawk over serial sometime drop before reconnect automatically. This make me worried because it might affect the accuracy of data logging.

I tried passing the vehicle variable to other python and wrap vehicle into modules but both doesn't work. There's any way to share vehicle variable between 2 python code or I'm stuck with combining my codes to utilize threading for global variable?

Thanks in advance.


Solution

  • To connect to one vehicle from 2 program (In your case 2 python script) you can use Mavproxy (http://ardupilot.github.io/MAVProxy/html/index.html), You can connect your vehicle to Mavproxy then add 2 output in the Mavproxy then connect both of your python script to Mavproxy. But I recommend to utilize multithreading or multiprocessing than seperate it to 2 different script.


    Edit: You can start Mavproxy from terminal like this:

    mavproxy.py --master=/dev/ttyAMA0 --baudrate 57600 --out 127.0.0.1:14550 --out 127.0.0.1:14551

    where /dev/ttyAMA0 is your vehicle address, and then connect the python script to 127.0.0.1:14550 and 127.0.0.1:14551