How to install and integrate Ardupilot with ROS2 and gazebo garden? - In just 15 steps

How to setup Ardupilot for ROS2

This tutorial gives step by step guid to install and integrate ardupilot with the new ROS2 and gazebo garden

1) ROS2 Installation :

 - ROS2 in Windows 11
 - ROS2 in Ubuntu 22.04
 - ROS2 in Ubuntu 20

2) Setup bashrc


$ gedit ~/.bashrc source /opt/ros/humble/setup.bash
$ source ~/.bashrc

3)Create Workspace for ros2 - ROS2 Workspace tutorial

$ sudo apt update 

$ sudo apt install python3-colcon-common-extensions 

$ colcon build

4)Modify bashrc

$ gedit ~/.bashrc export 

ROS_DOMAIN_ID=22 

export ROS_LOCALHOST_ONLY=1 

$ source ~/.bashrc

5)Install build dependencies

$ sudo apt install default-jre

$ cd

$ git clone --recurse-submodules https://github.com/ardupilot/Micro-XRCE-DDS-Gen.git
$ cd Micro-XRCE-DDS-Gen
$ ./gradlew assemble

6)Update bashrc

$ gedit ~/.bashrc
 export PATH=$PATH:~/Micro-XRCE-DDS-Gen/scripts
$ source ~/.bashrc
 
$ microxrceddsgen -version 

7)Setup Ardupilot build environment

$ cd

$ sudo apt-get update 

$ sudo apt-get install git 

$ sudo apt-get install gitk git-gui 

$ sudo apt-get install gcc-arm-none-eabi

$ git clone --recurse-submodules https://github.com/your-github-userid/ardupilot
$ cd ardupilot
$ git status
$ ./waf distclean
$ ./waf distclean
$ ./waf configure --board MatekF405-Wing
$ ./waf plane 

8)ROS2 - Ardupilot setup

$ cd ~/ros2_ws
$ sudo apt update
$ sudo apt install python3-vcstool 
$ vcs import --recursive --input  https://raw.githubusercontent.com/ArduPilot/ardupilot/master/Tools/ros2/ros2.repos src

$ cd ~/ros2_ws $ sudo apt update $ rosdep update $ source /opt/ros/humble/setup.bash $ rosdep install --from-paths src --ignore-src
 # Ignore the rosdep warnings at the end if any

 9) Build package

$ cd ~/ros2_ws
$ colcon build --packages-up-to ardupilot_dds_tests 
$ colcon build --packages-up-to ardupilot_dds_tests --event-handlers=console_cohesion+
$ cd ~/ros2_ws
$ source ./install/setup.bash
$ colcon test --packages-select ardupilot_dds_tests

 

10)SITL installation

$ cd ~/ardupilot
$ git pull
$ Tools/environment_install/install-prereqs-ubuntu.sh -y
$ ./waf clean
$ ./waf configure --board sitl
$ ./waf copter -v
 
$ cd ~/ardupilot/Tools/autotest

$ sudo pip3 install MAVProxy
$ mavproxy.py --version
 

11) Update bashrc

$ gedit ~/.bashrc
$ export PATH=$PATH:/path/to/mavproxy
$ source ~/.bashrc
 

12)First test

$ ./sim_vehicle.py -v ArduCopter -w

$ ./sim_vehicle.py -v ArduCopter --console --map

$ ./sim_vehicle.py -v ArduCopter -L KSFO --console --map 
STL tutorial:
https://ardupilot.org/dev/docs/using-sitl-for-ardupilot-testing.html#using-sitl-for-ardupilot-testing 

$ ./sim_vehicle.py -v ArduPlane -f quadplane --console --map --osd 

$ ./sim_vehicle.py -v ArduCopter -f quadcopter --console --map --osd 

 

13)Gazebo garden

$ gedit ~/.bashrc 

export GZ_VERSION=garden 

$ source ~/.bashrc 

$ cd ~/ros2_ws
$ vcs import --input https://raw.githubusercontent.com/ArduPilot/ardupilot_gz/main/ros2_gz.repos --recursive src

 

$ cd ~/ros2_ws
$ source /opt/ros/humble/setup.bash
$ sudo apt update
$ rosdep update
$ rosdep install --from-paths src --ignore-src -r

 14)Build ws

$ cd ~/ros2_ws
$ colcon build --packages-up-to ardupilot_gz_bringup 

 

15)Run simulation 

$ source install/setup.bash
$ ros2 launch ardupilot_gz_bringup iris_runway.launch.py

Examples available

  • Iris Runway (Copter)

ros2 launch ardupilot_gz_bringup iris_runway.launch.py
  • Iris Maze (Copter)

ros2 launch ardupilot_gz_bringup iris_maze.launch.py
  • WildThumper (Rover)

ros2 launch ardupilot_gz_bringup wildthumper.launch.py