# ros-controls/ros_control architecture

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

- Interactive diagram: https://gitdiagram.com/ros-controls/ros_control
- Repository: https://github.com/ros-controls/ros_control

## Overview

##### Main Components
- Hardware Abstraction and Interfaces:
- hardware_interface: Contains the base classes and interfaces for actuators, sensors, and robot hardware. It defines key interfaces (such as joint_command_interface, joint_state_interface) used by controllers.
- joint_limits_interface: Provides constraints that help enforce joint limits and safety rules.
- transmission_interface: Manages the transmission mechanisms from abstract commands to the physical actuators (includes loaders for differential, four bar transmissions, etc.).
- combined_robot_hw: Wraps these low-level hardware interfaces into a unified hardware layer.

- Controller Management:
- controller_interface: Provides generic base classes for controllers.
- controller_manager: Handles lifecycle, loading, unloading, and switching between various controllers.
- controller_manager_msgs: Defines ROS messages and service types to enable communication with the Controller Manager.
- controller_manager_tests: Contains tests and example controllers that validate the Controller Manager functionalities.

- User Interface and Tools:
- rqt_controller_manager: Offers a graphical user interface (GUI) for interacting with controllers (starting, stopping, debugging, etc.).

- Supporting and Auxiliary Elements:
- ROS configuration files (package.xml, CMakeLists.txt, rosdoc.yaml) are spread throughout the packages indicating how these modules integrate into the larger ROS ecosystem.
- Test directories in multiple packages ensure that each functional block is properly validated through unit tests and integration tests.

##### Depicting the Relationships and Interactions
◦ Hardware Interfaces (hardware_interface, joint_limits_interface, transmission_interface, combined_robot_hw)
◦ Controller Management (controller_interface, controller_manager, controller_manager_msgs, controller_manager_tests)
◦ User Interface (rqt_controller_manager)
- Controller Manager communicates with the hardware interface layer. It loads controllers (from controller_interface) which, in turn, send commands to and read data from the hardware interfaces.
- ROS messages and services (from controller_manager_msgs) serve as the “communication glue” between the controller manager and external nodes.
- The rqt_controller_manager (GUI) interacts with the controller manager, invoking scripts and services (as seen in its scripts and source directories).
- That tests modules exist alongside these components and are used to verify interactions.

##### Highlighting Architectural Patterns and Design Principles
- Modular nature: Each package is responsible for a specific concern and follows ROS best practices.
- Clear component boundaries where abstraction layers hide the low-level hardware details (hardware_interface) from the high-level controller logic (controller_manager).
- Use of standardized message passing, service calls, and plugins (such as test controllers and controller loaders) for extensibility.
- Dependency inversion where abstract classes (in hardware_interface or controller_interface) allow for flexible implementation and testing.

##### Including Specific Technologies and Frameworks
- ROS: The framework is built entirely around the ROS ecosystem, relying on message passing, service definitions, and ROS package management.
- CMake: All packages use CMake for building, as indicated by the CMakeLists.txt in most directories.
- Python: Some components in controller_manager (e.g., __init__.py and controller_manager_interface.py) are developed in Python, which indicates mixed-language components.
- Testing Frameworks: C++ tests and Python-based tests are used to validate the functionality.

##### Specific Elements
- Controller Manager → Hardware Interface (commands, sensor feedback).
- rqt_Controller_Manager → Controller Manager (service calls, monitoring).
- Optionally, include auxiliary elements like configuration/build elements if needed (this may be a secondary layer showing integration with ROS build and deployment systems).

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface"
        U1["rqt_controller_manager"]:::ui
    end

    subgraph "Controller Management"
        C1["controller_interface"]:::controller
        C2["controller_manager"]:::controller
        C3["controller_manager_msgs"]:::controller
        C4["controller_manager_tests"]:::tests
    end

    subgraph "Low-Level Hardware Abstraction"
        H1["hardware_interface"]:::hardware
        H2["joint_limits_interface"]:::hardware
        H3["transmission_interface"]:::hardware
        H4["combined_robot_hw"]:::hardware
    end

    U1 -->|"service_calls"| C2
    C2 -->|"loads"| C1
    C2 -->|"ROS_msgs"| C3
    C4 ---|"validates"| C2

    C2 -->|"commands_feedback"| H1
    C2 -->|"commands_feedback"| H2
    C2 -->|"commands_feedback"| H3
    C2 -->|"commands_feedback"| H4

    click H1 "https://github.com/ros-controls/ros_control/tree/noetic-devel/hardware_interface/"
    click H2 "https://github.com/ros-controls/ros_control/tree/noetic-devel/joint_limits_interface/"
    click H3 "https://github.com/ros-controls/ros_control/tree/noetic-devel/transmission_interface/"
    click H4 "https://github.com/ros-controls/ros_control/tree/noetic-devel/combined_robot_hw/"
    click C1 "https://github.com/ros-controls/ros_control/tree/noetic-devel/controller_interface/"
    click C2 "https://github.com/ros-controls/ros_control/tree/noetic-devel/controller_manager/"
    click C3 "https://github.com/ros-controls/ros_control/tree/noetic-devel/controller_manager_msgs/"
    click C4 "https://github.com/ros-controls/ros_control/tree/noetic-devel/controller_manager_tests/"
    click U1 "https://github.com/ros-controls/ros_control/tree/noetic-devel/rqt_controller_manager/"

    classDef hardware fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef controller fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef ui fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef tests fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
