Multi-vehicle SITL and jMAVSim

I could not find any discussion on this specific problem, so I thought I would post this for others, just in case.

I was having a problem getting the to work correctly. Running it to start two PX4 SITL instances would result in the following:

killing running instances
starting instance 0 in /home/umex/Documents/tools/PX4-Autopilot/Tools/build/px4_sitl_default/instance_0
starting instance 1 in /home/umex/Documents/tools/PX4-Autopilot/Tools/build/px4_sitl_default/instance_1

But when looking at the process lists, it would not start any PX4 instances. You can launch instances of jMAVSim, which will start correctly, but again, there were no PX4 instances running.

After some analysis, the issue appears to be the script itself. In the current script, the following lines build the paths for starting the PX4 executable:

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"


The issue is with src_path and build_path. The first (on my Ubuntu 20.04 system) creates a path with a .. in it. The result is a build_path that also has a .. embedded in the middle. In addition to this issue, build_path still ends up pointing to a path that is one level below where it needs to be. This may be due to the movement of the build folder up one level. In any case, I modified the above with the following changes:

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
src_path=$(dirname "$SCRIPT_DIR")

build_path=$(dirname "$src_path")/build/px4_sitl_default

And the script now correctly launches the px4 instances and sets them waiting for connection by the simulator.

From what I can tell, the original version expected the build/px4_sitl_default folder to be in PX4_Autopilot/Tools when it is in fact at the PX4_Autopilot root folder.

1 Like

You sir, are THE guy. I have searched everywhere for why this issue kept happening with the jmav simulator with no success. It now works perfectly. Thanks a lot.

1 Like