MAVROS Documentation

repository·ros2·Indexed 22 days ago

https://github.com/mavlink/mavros

An extendable communication node for ROS that enables seamless communication between the Robot Operating System (ROS) and MAVLink-enabled flight controllers such as PX4 or ArduPilot. The project includes the core mavros package, mavros_extras for specialized plugins (e.g., gimbal_control, px4flow), the libmavconn library for independent MAVLink connections, and mavros_examples for ROS 2 implementation demonstrations.

Tokens
70.1K
Snippets
205
Records
375
Agent score
77%

What's inside MAVROS

  1. What is MAVROS and its core components

    ros2

    MAVROS is a MAVLink-to-ROS 2 bridge designed for PX4, ArduPilot, and other MAVLink-based autopilots. The project is organized into several key packages:

    • mavros: Contains the core ROS 2 nodes, including the Router, UAS, and standard plugins.
    • mavros_extras: Provides optional plugins for extended functionality.
    • mavros_msgs: Defines the ROS 2 message and service interfaces used for communication.
    • libmavconn: The underlying MAVLink transport library.
  2. Overview of MAVROS packages

    ros2

    MAVROS is an extendable communication node for ROS that facilitates MAVLink communication. The repository is organized into several functional packages:

    • mavros: The main package containing core functionality and installation instructions.
    • mavros_extras: Contains additional nodes and plugins for MAVROS.
    • libmavconn: The mavconn library, which can be used independently of the ROS environment.
    • mavros_msgs: Defines the messages and services used throughout MAVROS.
    • test_mavros: Contains manual tests and documentation for APM and PX4 SITL (Software In The Loop) testing.
  3. Overview of MAVROS Examples package

    ros2
    The mavros_examples package provides hands-on demonstrations for implementing MAVROS services and topics within the ROS 2 ecosystem. It is designed to help users learn how to communicate with autopilot systems running ArduPilot or PX4 firmware using standardized ROS interfaces. The package serves as a practical reference to ensure code complies with the latest MAVROS API specifications and best practices, avoiding issues with deprecated or renamed topics and services.
  4. Use the Landing Target plugin

    ros2

    The LandingTargetPlugin (namespace landing_target) is designed to facilitate landing target tracking. It can either publish the location of a landing area (captured via a downward-facing camera) to the Flight Control Unit (FCU) or receive landing target tracking data coming from the FCU.

    ROS 2 Interfaces

    Publishers

    • ~/pose_in (geometry_msgs/msg/PoseStamped): Publishes the target pose.
    • ~/lt_marker (geometry_msgs/msg/Vector3Stamped): Publishes the landing target marker.

    Subscribers

    • ~/raw (mavros_msgs/msg/LandingTarget): Receives raw landing target data.
    • ~/pose (geometry_msgs/msg/PoseStamped): Receives target pose data.
    • Subscriptions: Listens to the LANDING_TARGET MAVLink message (ID 149, common dialect).
    • Publications: Sends the LANDING_TARGET MAVLink message (ID 149, common dialect) to the FCU.
  5. Use the Optical Flow plugin in MAVROS

    ros2

    The OpticalFlowPlugin (part of mavros_extras) allows you to bridge Optical Flow camera data between MAVLink and ROS. It can publish raw optical flow data and ground distance to ROS topics, and can also subscribe to ROS topics to send optical flow data back to the flight controller via MAVLink.

    Key Functionality:

    • Data Flow (MAVLink to ROS): Subscribes to MAVLink OPTICAL_FLOW messages and publishes them to ROS topics.
    • Data Flow (ROS to MAVLink): Subscribes to ROS ~/raw/send and publishes to MAVLink OPTICAL_FLOW messages.
    • Ground Distance: Calculates and publishes ground distance based on the optical flow sensor and range parameters.
  6. How MAVROS coordinate frames and conversions work

    ros2

    MAVROS handles several types of coordinate transformations:

    Aerospace to ROS Frames

    MAVROS translates Aerospace NED (North-East-Down) frames used by FCUs to ROS ENU (East-North-Up) frames.

    • Airframe related data: Applies a 180° rotation about the ROLL (X) axis.
    • Local frames: Applies a 180° rotation about the ROLL (X) axis and a 90° rotation about the YAW (Z) axis.

    Geodetic and Geocentric Conversions

    Using GeographicLib, MAVROS supports:

    • WGS-84 Datum: Converts between height above the geoid (AMSL) and height above the WGS-84 ellipsoid.
    • ECEF (Earth-Centered, Earth-Fixed): Propagates the earth frame in ECEF local coordinates (per ROS REP 105).
    • Local Geocentric: Translates GPS coordinates to local geocentric coordinates by defining a local origin on the map frame in ECEF and calculating the offset to it in ENU.
  7. Use the Local Position plugin

    ros2

    The LocalPositionPlugin (class mavros::std_plugins::LocalPositionPlugin) provides ROS messages representing the vehicle's local position, velocity, and acceleration. It converts MAVLink local position data into standard ROS messages and can also publish transforms (TF) to represent the vehicle's pose in the world frame.

    // Implementation reference
    // Namespace: local_position
    // Class: mavros::std_plugins::LocalPositionPlugin
  8. Use the IMU plugin for attitude and sensor data

    ros2
    The IMU plugin (mavros::std_plugins::IMUPlugin) is responsible for publishing IMU, attitude, and related sensor data from MAVLink messages to ROS topics. It subscribes to various MAVLink IMU and attitude messages to provide processed sensor readings.
  9. Use the PX4Flow plugin to publish camera data to ROS

    ros2
    The PX4FlowPlugin (class mavros::extra_plugins::PX4FlowPlugin) is an extra plugin in MAVROS that bridges PX4Flow camera data to ROS. It subscribes to MAVLink OPTICAL_FLOW_RAD messages and publishes the data as ROS messages, including optical flow rates, ground distance, and temperature.
  10. Use the setpoint_raw plugin to send raw setpoints

    ros2

    The setpoint_raw plugin (class mavros::std_plugins::SetpointRawPlugin) allows you to send raw position, global, or attitude setpoints to the flight controller. It supports a 'return loop' where the current state is published back to ROS.

    Users can control which specific fields are sent to the flight controller by using the IGNORE bits within the message structures. This allows for fine-grained control over whether you are commanding position, velocity, acceleration, or attitude components.

  11. Use the cam_imu_sync plugin for camera and IMU synchronization

    ros2

    The cam_imu_sync plugin (class mavros::extra_plugins::CamIMUSyncPlugin) is used to synchronize external camera systems with the Flight Control Unit (FCU). It works by publishing a timestamp indicating when the FCU triggered the external camera. By correlating the Sequence ID from the MAVLink message with the image sequence from the camera, you can determine the exact shutter trigger time.

    • Subscribes to: CAMERA_TRIGGER (MAVLink message ID 112, dialect: common).
    • Logic: The plugin uses the handle_cam_trig handler to process incoming camera trigger messages.