How to run multivehicle sitl in gazebo with offboard control

I am running an example of a single uav in px4 sitl in gazebo with offboard control using ros2.
Successfully installed microros_dds and I am able to echo the topics list under ros and see the messages published to during the sitl process.

I would like to add another uav to the already running sitl and would like to control both using ros2.
how do I go about doing this?

What I have tried so far.

  1. Started micro-ros-agent using
    ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888

  2. Started multi sim in gazebo using
    ./Tools/simulations/gazebo-classic/sitl_mutliple_run.sh -n 2
    This launches a gazebo sim with 2 iris uavs as in the attached image

  3. Start QGroundController. I am able to see both uavs there. I can successfully take off either of them and HOLD position.

  4. source ros2 and px4_msgs and then list the topics using ros2 topic list which lists the topics as follows

/clock
/parameter_events
/performance_metrics
/px4_1/fmu/in/obstacle_distance
/px4_1/fmu/in/offboard_control_mode
/px4_1/fmu/in/onboard_computer_status
/px4_1/fmu/in/sensor_optical_flow
/px4_1/fmu/in/telemetry_status
/px4_1/fmu/in/trajectory_setpoint
/px4_1/fmu/in/vehicle_attitude_setpoint
/px4_1/fmu/in/vehicle_command
/px4_1/fmu/in/vehicle_mocap_odometry
/px4_1/fmu/in/vehicle_rates_setpoint
/px4_1/fmu/in/vehicle_trajectory_bezier
/px4_1/fmu/in/vehicle_trajectory_waypoint
/px4_1/fmu/in/vehicle_visual_odometry
/px4_1/fmu/out/failsafe_flags
/px4_1/fmu/out/sensor_combined
/px4_1/fmu/out/timesync_status
/px4_1/fmu/out/vehicle_attitude
/px4_1/fmu/out/vehicle_control_mode
/px4_1/fmu/out/vehicle_global_position
/px4_1/fmu/out/vehicle_gps_position
/px4_1/fmu/out/vehicle_local_position
/px4_1/fmu/out/vehicle_odometry
/px4_1/fmu/out/vehicle_status
/rosout

I was able to successfully control when it was just 1 uav as in the example px4_offboard

But I am having trouble in separately controlling uav1 and uav2 via ros2.
I have attached some images below.

  1. Micro_ros_agent and ros2 topics

  2. Gazebo with 2 uavs and QGCS

@Benja @JulianOes
How do I proceed? Please suggest.
Thanks.

I have ever tried multiple drones in Gazebo, what I did is to use namespace to encapsulate each drone, including the model, controller, etc, works fine.

Thanks. so each uav model needs a separate namespace. If you see in one of the screengrabs i have attached, there is only one namespace “px4_1” from the topics list, but there are two uavs.
how do i find how they are mapped?

I further note that the topics keep changing between /fmu/.. and /px4_1/fmu...
Please see attached gif of rqt showing this behavior
multipleTopics

if I try to publish to either /fmu or the /px4_1/fmu , it results in an awkward flight pattern for one of the uavs. The published trajectory is meant to be the blue circle depicted in rqt.

Maybe the two drones shared the same plugins caused this issue, if the single drone has no this issue, it is high chance there are two publisher sending same command to one subscriber, u can check the by rostopic info <topic_name> to see the senders, may can confirm this guess

Hi @returncode13 @Leo1
This solves your issue Multiple uavs sitl with offboard control using ros2 · Issue #21069 · PX4/PX4-Autopilot · GitHub
The automatic startup of the microdds_bridge is not compatible with sitl_mutliple_run.sh but the workaround is straightforward.