# scifiswapnil/ros2_ddsm115_driver architecture

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

- Interactive diagram: https://gitdiagram.com/scifiswapnil/ros2_ddsm115_driver
- Repository: https://github.com/scifiswapnil/ros2_ddsm115_driver

## Overview

##### Project Type and Purpose
- This is a robotics driver package for ROS2 Humble, comprised of two ROS2 packages:
– **ddsm115_driver**: a C++ library (DDSM115Communicator), a ROS2 node, a ros2_control HardwareInterface plugin, and custom ROS2 services.
– **ddsm115_example**: an example robot description (URDF), controller configs, launch files, and RViz configs that demonstrate how to use the driver in a ros2_control ecosystem.

##### File Structure
- Top-level packages:
– `src/ddsm115_driver/…`
– `src/ddsm115_example/…`
- Key sub-directories:
– `config/` (YAML configurations for both driver and example)
– `include/` & `src/` (library headers & implementations)
– `srv/` (service definitions)
– `plugin_description.xml` (registers the HardwareInterface plugin)
– `launch/`, `urdf/`, `rviz/` (example usage)

##### Extract Additional Insights from README
- **Core library**:
– DDSM115Communicator handles serial port communication using the motor’s protocol.
– Exposes methods to switch modes, set IDs, drive motor, and read feedback.
- **ROS2 node**:
– Subscribes to command topics
– Calls communicator methods
– Publishes motor state
- **ros2_control plugin**:
– Implements the HardwareInterface for use inside a controller_manager via URDF.

##### Main Components
a. **DDSM115Communicator Library (C++ Layer)**
– Serial Port Interface
– Protocol Parser & Builder
b. **Driver Node**
– ROS2 Subscription (e.g. `/ddsm115/command`)
– ROS2 Publication (e.g. `/ddsm115/state`)
– ROS2 Services (ChangeMotorMode, QueryMotorId, SetMotorId)
c. **ros2_control Components (Example Package)**
– `controller_manager`
– Controllers (position, velocity controllers)
– HardwareInterface Plugin (registered via `plugin_description.xml`)
d. **Robot Description & Visualization**
– URDF XACRO with `<transmission>` referencing the plugin
– RViz config for TFs & joint states
e. **External Hardware**
– DDSM115 Motor over Serial Bus (e.g. `/dev/ttyUSB0`)

##### Relationships & Interactions
- Data flow from **controllers** → **HardwareInterface** → **DDSM115Communicator** → **Serial Port** → **Motor**.
- **Driver Node** path: topic subscription → communicator → service calls → publish feedback → topic.

##### Architectural Patterns & Design Principles
- **Layered Architecture**:
– Application Layer (controllers, nodes)
– Abstraction Layer (HardwareInterface plugin)
– Communication Layer (DDSM115Communicator)
– Physical Layer (Serial Bus & Motor)
- **Plugin Pattern**: ros2_control plugin dynamically loaded via XML.
- **Separation of Concerns**:
– Serial protocol code isolated in Communicator library
– ROS2 node logic distinct from hardware interface

##### Relevant Technologies & Frameworks
- ROS2 Humble (rclcpp, ros2_control, controller_manager)
- CMake / ament_cmake build system
- YAML for runtime configuration
- URDF XACRO for robot description
- RViz for visualization

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Driver Package
    subgraph "ddsm115_driver" 
        style ddsm115_driver fill:#f9f,stroke:#333,stroke-width:1px
        DDSMComm["DDSM115Communicator Library"]:::software
        Node["ROS2 Driver Node"]:::software
        subgraph "HardwareInterface Plugin"
            style HardwareInterface Plugin fill:none,stroke:none
            HWImpl["ddsm115_hardware_interface.cpp/.hpp"]:::software
            PluginXML["plugin_description.xml"]:::other
        end
        subgraph "Custom Services"
            ChangeMode["ChangeMotorMode.srv"]:::middleware
            QueryID["QueryMotorId.srv"]:::middleware
            SetID["SetMotorId.srv"]:::middleware
        end
        ConfigDrv["config.yaml"]:::config
        CMakeDrv["CMakeLists.txt & package.xml"]:::other
    end

    %% Example Package
    subgraph "ddsm115_example"
        style ddsm115_example fill:#efe,stroke:#333,stroke-width:1px
        Launch["view_ddsm115.launch.py"]:::software
        RViz["tf.rviz"]:::software
        URDF["ddsm115_example.urdf.xacro"]:::software
        subgraph "ros2_control Configs"
            ControllersCfg["controllers.yaml"]:::config
            HardwareCfg["hardware.yaml"]:::config
            OverrideCfg["hardware_override.yaml"]:::config
        end
        CMakeEx["CMakeLists.txt & package.xml"]:::other
        ControllerMgr["controller_manager"]:::middleware
        Controllers["Position/Velocity Controllers"]:::middleware
    end

    %% Hardware Layer
    Serial["Serial Port (/dev/ttyUSB0)"]:::hardware
    Motor["DDSM115 Motor"]:::hardware

    %% Data Flows
    Controllers -->|"load plugin"| HWImpl
    ControllerMgr -->|"manages"| Controllers
    Controllers -->|"commands via HardwareInterface"| HWImpl
    HWImpl -->|"uses Communicator API"| DDSMComm
    DDSMComm -->|"serial protocol"| Serial
    Serial -->|"electrical signals"| Motor

    Launch -->|"loads URDF & configs"| URDF
    Launch -->|"spawns driver node"| Node
    Launch -->|"spawns controller_manager"| ControllerMgr
    ControllersCfg -->|"parameters"| ControllerMgr
    HardwareCfg -->|"parameters"| HWImpl
    OverrideCfg -->|"override params"| HWImpl
    RViz -->|"visualizes TFs & joint_states"| ControllerMgr

    Node -->|"subscribes /ddsm115/command"| DDSMComm
    Node -->|"calls services"| ChangeMode
    Node -->|"calls services"| QueryID
    Node -->|"calls services"| SetID
    Node -->|"publishes /ddsm115/state"| ControllerMgr

    ConfigDrv -->|"loaded by node & plugin"| Node

    %% Click Events
    click DDSMComm "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/include/ddsm115_driver/DDSM115Communicator.h"
    click DDSMComm "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/src/DDSM115Communicator.cpp"
    click Node "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/src/ddsm115_node.cpp"
    click HWImpl "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/src/ddsm115_hardware_interface.cpp"
    click HWImpl "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/src/ddsm115_hardware_interface.hpp"
    click PluginXML "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/plugin_description.xml"
    click ChangeMode "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/srv/ChangeMotorMode.srv"
    click QueryID "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/srv/QueryMotorId.srv"
    click SetID "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/srv/SetMotorId.srv"
    click ConfigDrv "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/config/config.yaml"
    click CMakeDrv "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/CMakeLists.txt"
    click CMakeDrv "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_driver/package.xml"
    click Launch "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_example/launch/view_ddsm115.launch.py"
    click RViz "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_example/rviz/tf.rviz"
    click URDF "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_example/urdf/ddsm115_example.urdf.xacro"
    click ControllersCfg "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_example/config/controllers.yaml"
    click HardwareCfg "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_example/config/hardware.yaml"
    click OverrideCfg "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_example/config/hardware_override.yaml"
    click CMakeEx "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_example/CMakeLists.txt"
    click CMakeEx "https://github.com/scifiswapnil/ros2_ddsm115_driver/blob/main/src/ddsm115_example/package.xml"

    %% Styles
    classDef software fill:#bbf,stroke:#333,stroke-width:1px
    classDef middleware fill:#bfb,stroke:#333,stroke-width:1px
    classDef hardware fill:#fb8,stroke:#333,stroke-width:1px
    classDef config fill:#ddd,stroke:#333,stroke-width:1px
    classDef other fill:#ffb,stroke:#333,stroke-width:1px
```
