SITL Multivehicle Gazebo Sim w/ ROS2 Offboard Control

Hello,

I have been attempting to prepare my workspace for gazebo multi-vehicle simulation w/ ROS2 offboard control. The steps of launching multiple PX4 nodes talking to gazebo are causing trouble. Here is where I am now:

gazebo_sitl_multiple_run.sh -m iris -n 2 -w empty -t px4_sitl_rtps
( 2x iris model, empty default world, sitl_rtps target… everything appears to launch appropriately; console output and log files are fine )

micrortps_agent -t UDP -s 2019 -r 2020 -n iris0
micrortps_agent -t UDP -s 2021 -r 2022 -n iris1
( 2 micrortps agent instances; namespaced to match custom ROS2 offboard control nodes using matching namespaces )

On ROS2 side, topics /<vehicle_id>/VehicleOdometry_PubSubTopic for each vehicle_id in [iris0, iris1] are published appropriately. Affecting the corresponding gazebo iris models produces expected changes to odometry on that vehicle’s topic. Additionally, messages published to /iris0/TrajectorySetpoint_PubSubTopic, /iris0/OffboardControlMode_PubSubTopic and /iris0/VehicleCommand_PubSubTopic are received by PX4 and the simulated model responds accordingly (arms, takes off, transforms, etc). However, messages published to these topics within the iris1 namespace result in no response from that PX4 node.

Basically, PX4 → ROS2 is functional for all vehicles, but ROS2 → PX4 is functional for only the first vehicle, despite micrortps ports matching on agent and client ends.

During my attempted fixes, I examined build/px4_sitl_rtps/instance_/out.log files and found that for all instances other than 0, the micrortps_client failed to bind UDP transport. I traced the gazebo_sitl_multiple_run.sh script to the rcS script (build/px4_sitl_rtps/etc/init.d-posix/rcS) which starts the micrortps_client on line 232. I added the -r flag before the receive port argument, and lauching the PX4 nodes again showed that both micrortps_clients now bind to UDP transport successfully. Before this step, neither PX4 → ROS2 or ROS2 → PX4 worked for iris1 (note, it still worked fine for iris0). This step did fix PX4 → ROS2, but as mentioned earlier, ROS2 → PX4 still does not behave.

Any recommendations on how to proceed with this debugging are greatly appreciated. I will happily provide additional information if anyone feels that enough has not been proactively provided. Thanks all!

3 Likes

Hello jackabove,

Thank you for posting your attempt at the problem. I was having the same issue where only the first vehicle will engage in offboad mode. Following your solution of adding -r flag allowed both of my vehicles to engage into offboard and receive ROS2 topics to control both vehicles.

Would you mind sharing what version of PX4 you’re using?

My setup is using the latest v1.12.0 and your solution seems to work for my problem.

Sorry to get back so late… I made changes to avoid solving this problem (ran px4 instances on different systems in the same network)… I don’t know which version I had and have made many changes since the time of posting. Hopefully you were able to figure it out on your end!

hi,
i think the -r flag now is added by default into the rcS file. I am able to receive sensor combined values from both vehicles, however offboard only works for the first instance of the vehicle. same problem as you were facing, i.e ROS2 ->PX4 for second instance does not work. Did you manage to find a solution for it?

I have been forced to move this to the back burner for now… sorry. My approach would begin with examining the micrortps_agent source; poking around and adding some debugging stuff. I will update this thread if I find a solution.

Hi,
is there any progress here?