PX4 Multi-vehicle Configuration#
The PX4 software-in-the-loop (SITL) stack comes with a sitl_multiple_run.sh
shell script that runs multiple instances of the PX4 binary. This allows the SITL stack to listen to connections from multiple AutonomySim
vehicles on multiple TCP ports starting from 4560. However, the provided script does not let us view the PX4 console. If you want to run the instances manually while being able to view each instance's console (Recommended) see this section.
Running Multiple PX4 SITL Instances#
Note
You have to build PX4 with make px4_sitl_default none_iris
as shown here before trying to run multiple PX4 instances.
-
From your bash (or
This starts multiple instances that listen to TCP ports 4560 to 4560+i where 'i' is the number of vehicles/instances specified.Cygwin
) terminal go to the PX4 Firmware directory and run thesitl_multiple_run.sh
script while specifying the number of vehicles you need. -
You should get a confirmation message that says that old instances have been stopped and new instances have been started.
-
Now edit AutonomySim settings file to make sure you have matching TCP port settings for the set number of vehicles and to make sure that both vehicles do not spawn on the same point. For example, these settings would spawn two PX4Multirotors where one of them would try to connect to PX4 SITL at port
4560
and the other at port4561
. It also makes sure the vehicles spawn at0,1,0
and0,-1,0
to avoid collision:You can add more than two vehicles but you will need to make sure you adjust the TCP port for each (ie: vehicle 3's port would be{ "SettingsVersion": 1.2, "SimMode": "Multirotor", "Vehicles": { "Drone1": { "VehicleType": "PX4Multirotor", "UseSerial": false, "UseTcp": true, "TcpPort": 4560, "ControlPortLocal": 14540, "ControlPortRemote": 14580, "X": 0, "Y": 1, "Z": 0 }, "Drone2": { "VehicleType": "PX4Multirotor", "UseSerial": false, "UseTcp": true, "TcpPort": 4561, "ControlPortLocal": 14541, "ControlPortRemote": 14581, "X": 0, "Y": -1, "Z": 0 } } }
4562
and so on..) and adjust the spawn point. -
Now run your Unreal
AutonomySim
environment and it should connect to SITL PX4 via TCP. If you are running the instances with the PX4 console visible, you should see a bunch of messages from each SITL PX4 window. Specifically, the following messages tell you that AutonomySim is connected properly and GPS fusion is stable:
If you do not see these messages then check your port settings.
You should also be able to use QGroundControl
in SITL mode. Make sure there is no Pixhawk hardware plugged in, otherwise QGroundControl will choose to use that instead. Note that as we don't have a physical board, an RC cannot be connected directly to it. So the alternatives are either use XBox 360 Controller
or connect your RC using USB (for example, in case of FrSky Taranis X9D Plus) or using trainer USB cable to your PC. This makes your RC look like a joystick. You will need to do extra set up in QGroundControl to use virtual joystick for RC control. You do not need to do this unless you plan to fly a drone manually in AutonomySim
. Autonomous flight using the Python API does not require RC, see No Remote Control
.
Starting SITL instances with PX4 console#
If you want to start your SITL instances while being able to view the PX4 console, you will need to run the shell scripts found here rather than sitl_multiple_run.sh
.
Here is how you would do so:
Note
This script also assumes PX4 is built with make px4_sitl_default none_iris
as shown here before trying to run multiple PX4 instances.
- From your bash (or
Cygwin
) terminal go to the PX4 directory and get the scripts (place them in a subdirectory called Scripts win the PX4 directory as shown)Note the shell scripts expect thecd PX4 mkdir -p Scripts cd Scripts wget https://github.com/nervosys/AutonomySim/raw/main/PX4Scripts/sitl_kill.sh wget https://github.com/nervosys/AutonomySim/raw/main/PX4Scripts/run_autonomysim_sitl.sh
Scripts
andFirmware
directories to be within the same parent directory. Also, you may need to make the scripts executable by runningchmod +x sitl_kill.sh
andchmod +x run_autonomysim_sitl.sh
. - Run the
sitl_kill.sh
script to kill all active PX4 SITL instances -
Run the
run_autonomysim_sitl.sh
script while specifying which instance you would like to run in the current terminal window (the first instance would be numbered 0)You should see the PX4 instance starting and waiting for AutonomySim's connection as it would with a single instance.
4. Open a new terminal and go to the Scripts directory and start the next instance 5. Repeat Step 4 for as many instances as you would like to start 6. Run your Unreal AutonomySim environment and it should connect to SITL PX4 via TCP (assuming your settings.json file has the right ports).______ __ __ ___ | ___ \ \ \ / / / | | |_/ / \ V / / /| | | __/ / \ / /_| | | | / /^\ \ \___ | \_| \/ \/ |_/ px4 starting. INFO [px4] Calling startup script: /bin/sh /cygdrive/c/PX4/home/PX4/Firmware/etc/init.d-posix/rcS 0 INFO [dataman] Unknown restart, data manager file './dataman' size is 11798680 bytes INFO [simulator] Waiting for simulator to connect on TCP port 4560