-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Context
I'm working with ROS2 and attempting to replicate a setup that works correctly in ROS1: launching multiple instances of SITL (ArduPilot Copter v4.5.7) and MAVROS2 on the same PC for multi-UAV simulation.
Problem
When I launch multiple instances (between 4 to 7) of SITL + MAVROS2 simultaneously on an Intel i7-12700H (20 threads), CPU usage spikes close to 100% in every core.
Each MAVROS2 process consumes around 250% CPU (2.5 cores), and the usage never decreases over time.
As a result, ROS2 service calls to MAVROS2 either receive no response or the callbacks are not triggered—likely because other callbacks are consuming too much CPU.
Interestingly, if I stagger the launch of each MAVROS2 + SITL instance by 30 seconds, the CPU usage per MAVROS2 process drops to ~40%, and all simulated drones operate correctly.
Note: However, if we want to simulate a large number of UAVs, waiting 30 seconds between each instance is not a viable solution. This workaround does not scale and significantly increases the total setup time.
Steps to Reproduce
At the same time (with a script or launch.py):
-
Launch mavros_node with the px4_config.yaml and px4_pluginlists.yaml from the mavros package.
Each instance with different tgt_system and fcu_url -
Launch SITL with:
/home/user/Libraries/ardupilot/ardupilot-Copter-v4.5.7/Tools/autotest/sim_vehicle.py -N -I <tgt_system> -l ,,1003,285 -v ArduCopter --frame quad
-
Repeat the process with a 30-second delay between each instance launch and compare behavior.
Expected Behavior
-
Simultaneous Launch:
- Each MAVROS2 instance consumes about 250% CPU
- CPU usage does not decrease over time
- ROS2 service calls may fail or hang due to callback starvation
-
Staggered Launch (30s delay):
- MAVROS2 instances initially spike in CPU usage
- CPU usage drops to 30–40% per instance after a few seconds
- All simulated UAVs operate as expected
Note:
Each SITL process uses approximately 10% CPU
(Significantly less than MAVROS2 or mavproxy.py)