# mavlink/mavros architecture

> Architecture diagram of the GitHub repository mavlink/mavros, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mavlink/mavros
- Repository: https://github.com/mavlink/mavros

## Overview

This project is a ROS-based communication system that implements MAVLink connectivity – in other words, it provides a MAVLink extendable communication node for ROS. The repository is organized into several dedicated packages, each with a specific role:

##### Project type and purpose
- The README makes it clear that the project (“MAVROS”) is a communication node that bridges MAVLink (used in autopilots and UAVs) with ROS.
- It is composed of multiple related packages: the main MAVROS package (the core ROS node), mavros_extras (additional nodes and plugins), libmavconn (a standalone library providing low-level communication support), mavros_msgs (message and service definitions), and test_mavros (for manual and SITL testing).

##### Key directories and their architectural roles
- libmavconn – Provides abstracted communication interfaces (serial, TCP, UDP) which the core node relies upon for actual data transfer. It is both used by MAVROS and can be employed independently outside ROS.
- mavros_msgs – Houses the definitions for custom messages and service calls. This is critical for defining the ROS interfaces that the node exposes.
- mavros_extras – Contains extra plugins and nodes that extend core functionalities provided by MAVROS.
- test_mavros – Contains test harnesses and demonstration setups, particularly for SITL (Software In The Loop) testing of APM and PX4 environments.

a. Main Components:
- ROS Middleware: The central nervous system that MAVROS integrates with.
- Core MAVROS Node: Represented as a container/component that processes incoming MAVLink messages and publishes/subscribes to ROS topics and services.
- mavros_msgs: A dedicated component that defines the data contracts (messages and services) which the core node uses to interact with other ROS nodes.
- mavros_extras: An extendable set of plugins that plug into the core node to provide additional functionality (like advanced command control, sensor data processing, etc.).
- External Systems/Hardware: Represent autopilot hardware or simulators (e.g., SITL for APM and PX4). This illustrates how MAVROS acts as a bridge between them and the ROS ecosystem.

b. Relationships and Data Flow:
- The core node utilizes the mavros_msgs definitions to send and receive ROS topics and services.
- MAVROS_extras plugins are connected to the core node, processing or augmenting data flows.
- In a testing environment, test_mavros simulates external inputs and verifies outputs.

c. Architectural Patterns / Design Principles:
- Modular design: Separation into distinct packages (core, extras, messages, low-level communication) promotes clear boundaries and independent development/testing.
- Plugin architecture: The extras and command modules indicate extensibility.
- Middleware abstraction: libmavconn abstracts protocol-specific communication details.

d. Relevant Technologies, Frameworks and Libraries:
- ROS (Robot Operating System) forms the backbone for inter-node communication.
- MAVLink protocol is key to communicating with UAV/autopilot hardware.
- CMake is used for build configuration across packages.
- Python scripts and shell scripts appear in testing and deployment contexts.

- Use clear labels for each major component (e.g., “MAVROS Core Node”, “libmavconn (TCP/UDP/Serial)”, “mavros_msgs”, “MAVROS Extras”, “External Autopilot/Simulators”).
- From External Autopilot hardware → libmavconn modules → MAVROS Core Node → ROS Topics/Services (via mavros_msgs).
- From MAVROS Core Node → MAVROS Extras (plugins) where additional processing occurs.
- Rectangles for ROS nodes,
- Document symbols for message/service definitions.

##### Putting it all together
- Expand into a lower-level view that reflects both the internal structure (core node and its dependencies) and the external interactions (hardware/simulators).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["External Autopilot/Simulators"]:::external
    B["Communication Library (libmavconn)"]:::library

    subgraph "ROS Middleware"
        C["MAVROS Core Node"]:::ros
        D["Message and Service Definitions (mavros_msgs)"]:::msg
        E["MAVROS Extras"]:::plugin
    end

    F["Test Harnesses and SITL Testing (test_mavros)"]:::test

    A -->|"MAVLinkCmds"| B
    B -->|"DataTransfer"| C
    C -->|"ROSTopicsServices"| D
    C -->|"PluginData"| E
    F -->|"TestInputsVerification"| C

    click C "https://github.com/mavlink/mavros/blob/ros2/mavros/src/mavros_node.cpp"
    click B "https://github.com/mavlink/mavros/tree/ros2/libmavconn/"
    click D "https://github.com/mavlink/mavros/tree/ros2/mavros_msgs/"
    click E "https://github.com/mavlink/mavros/tree/ros2/mavros_extras/"
    click F "https://github.com/mavlink/mavros/tree/ros2/test_mavros/"

    classDef external fill:#ffd700,stroke:#333,stroke-width:2px;
    classDef library fill:#d0e9f6,stroke:#333,stroke-width:2px;
    classDef ros fill:#ffdead,stroke:#333,stroke-width:2px;
    classDef msg fill:#c3f3c3,stroke:#333,stroke-width:2px;
    classDef plugin fill:#f6d0e9,stroke:#333,stroke-width:2px;
    classDef test fill:#e9f6d0,stroke:#333,stroke-width:2px;
```
