ROS 2 with SITL

Once ROS2 is correctly installed, source your workspace and launch Ardupilot SITL with ROS 2!

source ~/ros2_ws/install/setup.bash
ros2 launch ardupilot_sitl transport:=udp4 refs:=$(ros2 pkg prefix ardupilot_sitl)/share/ardupilot_sitl/config/dds_xrce_profile.xml synthetic_clock:=True wipe:=False model:=quad speedup:=1 slave:=0 instance:=0 defaults:=$(ros2 pkg prefix ardupilot_sitl)/share/ardupilot_sitl/config/default_params/copter.parm,$(ros2 pkg prefix ardupilot_sitl)/share/ardupilot_sitl/config/default_params/dds_udp.parm sim_address:= master:=tcp: sitl:=

If the ROS 2 topics aren’t being published, set the ardupilot parameter DDS_ENABLE to 1 manually and reboot the launch

export PATH=$PATH:~/ros2_ws/src/ardupilot/Tools/autotest -w -v ArduPlane --console -DG --enable-dds

param set DDS_ENABLE 1

For more information refer to ardupilot/Tools/ros2/ There you can find examples of launches using serial connection instead of udp, as well as a step-by-step breakdown of what the launch files are doing.