PX4 Multiple Vehicle Simulation


I’ve been trying to run PX4 with multiply vehicles as described here https://dev.px4.io/en/simulation/multi-vehicle-simulation.html but it seems outdated. After launch I see Gazebo with 3 drones, but mavros doesn’t connect to them. So I can see topics, but states say it’s not connected.

Can you help me with this? I suppose the problem is with ports but I haven’t succeed to find out how it should be


I am currently running the multivehicle similation and it is working for me.

Are you running the current master of the firmware?

Could you post any logs or launchfile you are using?

I did everything as in the link above
OS: Ubuntu 18.04
ROS Melodic
Gazebo 9.8

Log file https://gist.github.com/Vourhey/760df1ec4d2874a209e069c788e3b126

Are you using the current master of Px4/Firmware?

Yes. I just rechecked before the answer and downloaded the clean copy

You seem to have a custom path for the firmware.

Are you sure you added the path properly? It seems that none of the plugins can be found in your log:

cd <Firmware_clone>
make px4_sitl_default gazebo
source ~/catkin_ws/devel/setup.bash    // (optional)
source Tools/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)/Tools/sitl_gazebo
1 Like

Oh, you’re right!
Thank you Jaeyoung-Lim, I spent a lot of time and needed someone!

Can you tell me one more thing. When a drone takes off it’s not going straight up, but is going to one side. How to fix it? Or how to change the drone to iris rplidar for example?

So, what are you commanding to the drone? I am not sure what you mean by not going straight up.

You can look at the launchfile and change the vehicle to change the sitl target here: https://github.com/PX4/Firmware/blob/master/launch/multi_uav_mavros_sitl.launch#L7

I call

$ rosservice call /uav2/mavros/set_mode "base_mode: 0  
custom_mode: 'OFFBOARD'"
$ rosservice call /uav2/mavros/cmd/takeoff "{min_pitch: 0.0, yaw: 0.0, latitude: 0.0, longitude: 0.0, altitude: 10.0}"              
$ rosservice call /uav2/mavros/cmd/arming "value: true"

I expect it to go up and stay there. But the drone moves like there’s a strong wind and stays far away from the home point

And yeah, I saw the vehicle parameter, but it’s used here

<arg name="cmd" default="$(find xacro)/xacro $(find px4)/Tools/sitl_gazebo/models/rotors_description/urdf/$(arg vehicle)_base.xacro rotors_description_dir:=$(find px4)/Tools/sitl_gazebo/models/rotors_description mavlink_udp_port:=$(arg mavlink_udp_port) mavlink_tcp_port:=$(arg mavlink_tcp_port) --inorder"/>

and there’re only those files in the rotors_description folder
component_snippets.xacro iris_base.xacro iris.xacro multirotor_base.xacro

In that case it is not entering offboard mode as you are not sending any setpoints. Your services will simply arm and takeoff the drone. If you want to use offboard mode, you need to send a continuous stream of setpoints.

Not sure it helps, but you can look at my personal project here where local position setpoints are sent to multiple vehicles: https://github.com/Jaeyoung-Lim/mavros_swarm

For the vehcile name, you can use any of the sitl targets by changing the name. Try for example “tailsitter”

1 Like