Skip to main content

6.5 MAVROS2

MAVROS

MAVLink scalable communication node for ROS2.

The ROS API documentation has moved to wiki.ros.org.

Features

  • Communicate with an autopilot (e.g. PX4 Pro or ArduPilot ) via serial port, UDP or TCP
  • Internal proxy for ground control station (serial, UDP, TCP)
  • ROS-MAVLink translation plugin system
  • Parameter manipulation tools
  • Waypoint operation tools
  • PX4Flow support (provided by mavros_extras )
  • OFFBOARD mode support
  • Geographic coordinate conversion.

Limitations

Only available for Linux.

This package depends on the ros-*-mavlink build, which is derived from mavlink-gbp-release. It is located in the ROS Package Index and is typically updated monthly.

Connection

The connection is defined by a URL, and you can use any type supported by FCU and GCS.

Supported architectures:

  • Serial Number:/path/to/serial/device[:baudrate]
  • Serial Number:serial:///path/to/serial/device[:baudrate][?ids=sysid,compid]
  • Serial with hardware flow control:serial-hwfc:///path/to/serial/device[:baudrate][?ids=sysid,compid]
  • UDP: udp://[bind_host][:port]@[remote_host[:port]][/?ids=sysid,compid]
  • UDP broadcast until GCS finds:udp-b://[bind_host][:port]@[:port][/?ids=sysid,compid]
  • UDP broadcast (permanent):udp-pb://[bind_host][:port]@[:port][/?ids=sysid,compid]
  • TCP Client:tcp://[server_host][:port][/?ids=sysid,compid]
  • TCP Server:tcp-l://[bind_host][:port][/?ids=sysid,compid]

illustrate:

  • The ID in the URL overrides the values given by the system_id and component_id parameters.
  • bind_host - default 0.0.0.0 - i.e. IP4 ANY
  • UDP default ports: 14555 @ 14550
  • The UDP remote address is updated with each incoming packet on the bound port.
  • TCP default port: 5760

Coordinate

MAVROS can convert the aerospace NED coordinate system used in the FCU to the ROS ENU coordinate system, and vice versa. For airframe-related data, we simply rotate 180° around the roll (X) axis. For local data, we rotate 180° around the roll (X) axis and 90° around the yaw (Z) axis. For more information, see the documentation in issue #473.

All transformations src/lib/ftf_frame_conversions.cpp are handled in and and tested in and, respectively src/lib/ftf_quaternion_utils.cpp.test/test_frame_conversions.cpp test/test_quaternion_utils.cpp

Related issues: #49 (obsolete), #216 (obsolete), #317 (obsolete), #319 (obsolete), #321 (obsolete), #473. Documentation: Coordinate System Conversion, MavLink Coordinate System.

MAVROS also allows conversion between geodetic and geocentric coordinates via GeographicLib, because:

  • geographic_msgs The LLA field is required NatSatFix.msg to use the WGS-84 datum, which means that the height should be above the WGS-84 ellipsoid. For this purpose, a conversion from height above the geoid (AMSL, taking into account the egm96 geoid model) to height above the WGS-84 ellipsoid and vice versa is provided and is used in several plugins.
  • According to ROS REP 105, earth the coordinate system should be propagated in the ECEF (Earth-centered, Earth-fixed) local coordinate system. For this purpose, it is necessary to use the functions of GeographicLib in order to transform geodetic coordinates into geocentric coordinates.
  • The conversion from GPS coordinates to local geocentric coordinates requires defining a local origin (ECEF) on the coordinate system map and calculating the offset from that origin (ENU). All conversions are supported by GeographicLib classes and methods and global_position implemented in the plugin.

Component

See also: https://docs.ros.org/en/foxy/Tutorials/Composition.html

mavros::router::

This is the router node required to support connectivity with Flight Control Units (FCU), Ground Control Stations (GCS), and Unmanned Aircraft System (UAS) nodes. The router allows you to dynamically add/remove endpoints without restarting the node.

mavros::uas::

This node is a plug-in container that manages all protocol plug-ins. Each plug-in is a child node of this node.

Program

mavros_node -- all-in-one container

This is a pre-configured component node container that provides similar parameters to the ROS1 mavros_node. This container loads the router, UAS and configures them to work together (setting uas_link, etc.).

Master node. Allows disabling the GCS proxy by setting an empty URL.

ros2 run mavros mavros_node --ros-args --params-file params.yaml

Startup

XXX To Do List! #1564

Boot files are provided for common FCUs, specifically the Pixhawk:

  • px4.launch - for the PX4 autopilot (for VTOL, multirotors, and aircraft)
  • apm.launch - used by the APM flight stack (e.g. all versions of ArduPlane, ArduCopter, etc.)

example:

roslaunch mavros px4.launch
roslaunch mavros apm.launch fcu_url:=tcp://localhost gcs_url:=udp://@

Installation

Required

Most ROS dependencies are supported and installed rosdep, including external libraries such as Eigen and Boost.

GeographicLib can be installed as follows apt-get; it is included in the MAVROS package with rosdep. It can also be compiled and installed from src, but it is recommended to use the same installation directory as the correct one apt-get to ensure that FindGeographicLib.cmake the required shared libraries are found libGeographic.so.

Because GeographicLib requires certain datasets (primarily the geoid dataset) to perform certain calculations, users need to manually install these datasets. geographiclib-tools On Debian systems, this can be done via apt-get. To speed up the installation, simply run the scripts in the "mavros/scripts" folder install_geographiclib_datasets.sh.

Please note that if you are using an older MAVROS release source installation and want to update to a newer version, remember to run from the src folder of your catkin workspace rosdep update before running. This will allow to update the list and install the required dependencies when publishing .rosdep install --from-paths ${ROS_WORKSPACE} --ignore-src --rosdistro=${ROSDISTRO} ROS_WORKSPACE rosdep rosdep install

‼ ️ In order to comply with the ROS msg API, a geoid dataset is required in order to perform elevation conversions. If no dataset is available, the system will shut down mavros_node ‼ ️

❗ Run install_geographiclib_datasets.sh to install all datasets or geographiclib-datasets-download egm96_5 ( Debian 7, Ubuntu 14.04, 14.10 ) or ( Debian 8, Fedora 22, Ubuntu 15.04 or later ) only the geoid dataset: heavy_exclamation_mark:geographiclib-get-geoids egm96-5

Binary installation (deb

The ROS repository contains binary packages for Ubuntu x86, amd64 (x86_64), and armhf (ARMv7). Kinetic also supports Debian Jessie amd64 and arm64 (ARMv8).

Just use to apt install:

sudo apt install ros-foxy-mavros

install_geographiclib_datasets.sh Then install the GeographicLib dataset by running the script:

ros2 run mavros install_geographiclib_datasets.sh

# Alternative:
wget https://raw.githubusercontent.com/mavlink/mavros/ros2/mavros/scripts/install_geographiclib_datasets.sh
./install_geographiclib_datasets.sh

Source

Use vcs the utilities to retrieve the source and colcon build it using the tools.

Note: The source installation instructions are for the ROS Foxy version.

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

# 1. Create the workspace: unneeded if you already has workspace
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws

# 2. Install MAVLink
# we use the Kinetic reference for all ROS distros as it's not distro-specific and up to date
rosinstall_generator --format repos mavlink | tee /tmp/mavlink.repos

# 3. Install MAVROS: get source (upstream - released)
rosinstall_generator --format repos --upstream mavros | tee -a /tmp/mavros.repos
# alternative: latest source
# rosinstall_generator --format repos --upstream-development mavros | tee -a /tmp/mavros.repos
# For fetching all the dependencies into your ros2_ws, just add '--deps' to the above scripts
# ex: rosinstall_generator --format repos --upstream mavros --deps | tee -a /tmp/mavros.repos

# 4. Create workspace & deps
vcs import src < /tmp/mavlink.repos
vcs import src < /tmp/mavros.repos
rosdep install --from-paths src --ignore-src -y

# 5. Install GeographicLib datasets:
./src/mavros/mavros/scripts/install_geographiclib_datasets.sh

# 6. Build source
colcon build

# 7. Make sure that you use setup.bash or setup.zsh from workspace.
# Else ros2 run can't find nodes from this workspace.
source install/setup.bash

Build error. If you get a missing error mavlink*, you need to update the mavlink package. You can update from ros-shadow-fixed (binary installation), or redo steps 2 and 4 of the script.

NOTE: Since the MAVLink 2.0 (0.18) merge, all dialects are supported by the same binary. Unfortunately, the overlap of v1.0 message IDs has not been fully handled, so the first loaded message prohibits further changes. The load order is always:

  1. Common
  2. ardupilotmega
  3. Alphabetical list
  4. ...

Note: MAVLINK_DIALECT No longer used.

Troubleshooting

Error:serial0:receive:

This issue should be resolved in mavros v0.23.2, it was found to be a Boost.ASIO bug and should be fixed in versions > v1.12.0 (> Boost 1.66).

Contribution

See CONTRIBUTING.md.

Glossary

  • GCS: Ground Control Station
  • FCU — Flight Control Unit (aka FC )
  • OBC — Onboard Computer (your odroid or raspberry)
  • MAVLink – a communication protocol for drones, used by flight controllers, ground control stations, and peripheral devices
  • mavlink_ros - raw ROS node (small number of messages, no proxy)
  • Pixhawk – the open standard for drone hardware
  • PX4 AutoPilot - Support for most vehicle types and hardened/tested MAVROS-supported flight controllers
  • ArduPilot - tested autopilot APM :Plane (default command set)
  • QGroundControl - A ground control station for MAVLink autopilots, tested on Android, iOS, Mac OS, Linux, and Windows
  • mavros_extras -- Extra plugins and nodes for Mavros

More information

Please refer to the official Mavros link https://github.com/mavlink/mavros/blob/ros2/mavros/README.md#installation