# ROS2 Launch file to launch PX4

**URL:** <https://discuss.px4.io/t/ros2-launch-file-to-launch-px4/32392>\
**Category:** PX4 Autopilot\
**Created:** [May 24, 2023, 3:32pm UTC](https://discuss.px4.io/t/ros2-launch-file-to-launch-px4/32392 "2023-05-24T15:32:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![princealy](https://discuss.px4.io/user_avatar/discuss.px4.io/princealy/32/12558_2.png) [@princealy](https://discuss.px4.io/u/princealy)\
**Post date:** [May 24, 2023, 3:32pm UTC](https://discuss.px4.io/t/ros2-launch-file-to-launch-px4/32392/1 "2023-05-24T15:32:05Z")

</div>

Currently, there are great examples and documentation of offboard control and multi-vehicle control:

> **[PX4 Guide (main)](https://docs.px4.io/main/en/ros/ros2_offboard_control.html)**
>
> PX4 User and Developer Guide

> **[PX4 Guide (main)](https://docs.px4.io/main/en/ros/ros2_multi_vehicle.html)**
>
> PX4 User and Developer Guide

The issue is that there is no clear way to also launch PX4 in the launch scripts. Therefore, to launch 4 vehicles, the user needs to open 4 terminals to run PX4 using make. This becomes more challenging with more vehicles or with additional gazebo configuration.

---

<div class="post-metadata">

**Author:** ![Benja](https://discuss.px4.io/user_avatar/discuss.px4.io/benja/32/11872_2.png) [@Benja](https://discuss.px4.io/u/Benja)\
**Post date:** [May 24, 2023, 3:53pm UTC](https://discuss.px4.io/t/ros2-launch-file-to-launch-px4/32392/2 "2023-05-24T15:53:08Z")

</div>

Hi @princealy , thanks for starting this.

Please, take a look at [GitHub - osrf/vehicle\_gateway: A pluginlib-based C++ library that interfaces with several vehicle SDK's](https://github.com/osrf/vehicle_gateway)  
As far as I know it is the most complete way to have ROS 2 - Gazebo Garden - PX4 all together.  
I never used it though

---

<div class="post-metadata">

**Author:** ![princealy](https://discuss.px4.io/user_avatar/discuss.px4.io/princealy/32/12558_2.png) [@princealy](https://discuss.px4.io/u/princealy)\
**Post date:** [May 24, 2023, 4:01pm UTC](https://discuss.px4.io/t/ros2-launch-file-to-launch-px4/32392/3 "2023-05-24T16:01:26Z")

</div>

I think there is also this: [GitHub - ARK-Electronics/ws\_ROS2\_PX4\_Simulation: Example of controlling PX4 Velocity Setpoints with ROS2 Teleop controls. No need for QGC](https://github.com/ARK-Electronics/ws_ROS2_PX4_Simulation)  
created recently.

We might want to consider supporting both ROS2 Foxy (Which means supprot Gazebo Classic) and ROS2 humble (Gazebo Garden).

What do you think?

---

<div class="post-metadata">

**Author:** ![Theotime\_Balaguer](https://discuss.px4.io/letter_avatar_proxy/v4/letter/t/cab0a1/32.png) [@Theotime\_Balaguer](https://discuss.px4.io/u/Theotime_Balaguer)\
**Post date:** [May 25, 2023, 7:09am UTC](https://discuss.px4.io/t/ros2-launch-file-to-launch-px4/32392/4 "2023-05-25T07:09:29Z")

</div>

Hi, I was not aware of the existence of Vehicle Gateway, really don’t know how I missed this from osrf !

This looks promising ! I will give it a try today, report my feelings.

@hamishwillee, I don’t think there is a doc on Vehicle Gateway ? Should we create one ?

---

<div class="post-metadata">

**Author:** ![Theotime\_Balaguer](https://discuss.px4.io/letter_avatar_proxy/v4/letter/t/cab0a1/32.png) [@Theotime\_Balaguer](https://discuss.px4.io/u/Theotime_Balaguer)\
**Post date:** [May 25, 2023, 11:17am UTC](https://discuss.px4.io/t/ros2-launch-file-to-launch-px4/32392/5 "2023-05-25T11:17:53Z")

</div>

So, I tried vehicle\_gateway and it seems to me that it is exactly the kind of module that can facilitate entering the field of aerial robotics, as was discussed yesterday during the [ROS Aerial working group](https://discourse.ros.org/t/may-2023-meetings-aerial-robotics/31231/5).

It already has a PX4 package that allows to launch one or multiple instances of the PX4 autopilot, the uOrb ↔ DDS bridge and the Gazebo simulation.

However it uses `micro_ros_agent`, which is a wrapper of the MicroXRCEAgent. In my case, it fails when I launch `px4_sim/launch/px4_sim.launch.py`.

I tested vehicle\_gateway with ROS2 Humble, Gazebo Garden and micro\_ros\_agent v3.0.4, and I suffer crashes of the `micro_ros_agent` with the following error :

```auto
[micro_ros_agent-3] terminate called after throwing an instance of 'std::bad_array_new_length'

```

The error also happen when I launch only the micro\_ros\_agent in one terminal and a PX4 instance in another one, so it doesn’t seems to be related to the vehicle\_gateway repo.

Is this an issue only on my side, or is it for everyone ?

I tried to remove the micro\_ros\_agent node from the launch file and launched a MicroXRCEAgent separately, in another terminal. Everything works great in this case.

Anyway, we should make a choice on whether PX4 support vehicle gateway and it is the go-to method to launch PX4 and Gazebo using ROS2, or we add a new launch file directly in the PX4 project (that could be inspired by [these ROS launch files](https://github.com/osrf/vehicle_gateway/tree/main/px4_sim/launch)).  
My opinion is that it would be beneficial for newcomers that want to use ROS to have an easy way to integrate the PX4 Autopilot in their simulations, so I would push to use vehicle\_gateway.

---

<div class="post-metadata">

**Author:** ![mbarcis](https://discuss.px4.io/user_avatar/discuss.px4.io/mbarcis/32/11989_2.png) [@mbarcis](https://discuss.px4.io/u/mbarcis)\
**Post date:** [May 30, 2023, 9:11am UTC](https://discuss.px4.io/t/ros2-launch-file-to-launch-px4/32392/6 "2023-05-30T09:11:00Z")

</div>

From what I’ve seen, Vehicle Gateway is in very active development, and from time to time the version from the main branch won’t work properly. Nevertheless, we’ve got our multi-robot setup working based on this version: [Pin PX4 to most recent commit (#100) · osrf/vehicle\_gateway@16e65ce · GitHub](https://github.com/osrf/vehicle_gateway/commit/16e65ce) . It’s slightly old now given how fast the commits are coming to this repo, but for me, it works well.

---

<div class="post-metadata">

**Author:** ![princealy](https://discuss.px4.io/user_avatar/discuss.px4.io/princealy/32/12558_2.png) [@princealy](https://discuss.px4.io/u/princealy)\
**Post date:** [June 12, 2023, 2:06am UTC](https://discuss.px4.io/t/ros2-launch-file-to-launch-px4/32392/7 "2023-06-12T02:06:06Z")

</div>

I have had a lot of issues getting Vehicle Gateway to work. Since ROS2 humble is not officially supported yet , I am wondering if there is a way to launch PX4 that works with ROS2 foxy. MY team and I found we can use the `sitl_multiple_run.sh` to run multiple drones and use the XRCE bridge to connect it to ROS 2. This can be launched like this from a launch file

```auto
  ExecuteProcess(
            cmd=[
                HOME + '/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_multiple_run.sh',
                '-n', str(no_of_drones), '-w', 'baylands'
            ],

```

However, there seems to be a bug where ROS 2 will connect to vehicle 1 through n but not vehicle 0. Not sure if there is another simple way to launch the vehicles without using another framework under such constant development.
