Skip to content

Installation

ROS2 installation is out of scope for this guide, you should follow the official installation instructions.

Note

This guide is tested on the ROS2 Kilted release. But it is likely that your release will have quite similar set of commands.

Dependencies

Most of the ROS dependencies are supported and installed by rosdep, including external libraries such as ASIO, Eigen and GeographicLib.

Since GeographicLib requires certain datasets so to fulfill certain calculations, these need to be installed manually by the user.

Warning

The geoid dataset is mandatory to allow the conversion between heights in order to respect ROS API. Not having the dataset available will shutdown the UAS node.

Binary package (deb)

ROS repository has binary packages for Ubuntu amd64 and aarch64. Just use apt for installation:

sudo apt install ros-${ROS_DISTRO}-mavros

Then install GeographicLib datasets using helper script:

sudo ros2 run mavros install_geographiclib_datasets.sh

Or alternative one-liner script:

curl -LsSf https://raw.githubusercontent.com/mavlink/mavros/ros2/mavros/scripts/install_geographiclib_datasets.sh | sudo bash

Build from source

Use vcs utility for retrieving sources and colcon tool for build.

Install vcs tool and rosinstall_generator

sudo apt install -y python3-vcstool python3-rosinstall-generator python3-osrf-pycommon

Create the workspace (unneeded if you already have it)

source /opt/ros/kilted/setup.bash
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws
rosinstall_generator --format repos mavlink | tee /tmp/mavlink.repos
rosinstall_generator --format repos --upstream mavros | tee /tmp/mavros.repos

Note

--upstream - tells to use upstream git instead of git-buildpackage one.

Note

You may use --upstream-development to pull latest sources (ros2 branch).

Clone repos to workspace

vcs import src < /tmp/mavlink.repos
vcs import src < /tmp/mavros.repos

Install dependencies

rosdep update
rosdep install --from-paths src --ignore-src -y

Note

If rosdep update fails due to permission issues in your environment, rerun it with sudo.

Install GeographicLib datasets

sudo ./src/mavros/scripts/install_geographiclib_datasets.sh

Build

colcon build

Update environment

source ./install/setup.bash

Verify installation

ros2 pkg list | grep -E "^mavros$|^mavros_extras$|^mavros_msgs$"

Note

Make sure that you use setup.bash or setup.zsh from workspace. Otherwise ros2 run can't find nodes.

Devcontainer (optional)

You can use the provided devcontainer for a reproducible ROS 2 environment.

cd ~/ros2_ws/src/mavros

Open the folder in VS Code / VSCodium and run Dev Containers: Reopen in Container.

Available configs: - default: .devcontainer/devcontainer.json (mounts only this repository) - full workspace: .devcontainer/whole-workspace/devcontainer.json (expects repository at <workspace>/src/mavros)

After container creation, dependencies and tools are bootstrapped automatically by .devcontainer/post-create.sh.