# 2b-t/myactuator_rmd architecture

> Architecture diagram of the GitHub repository 2b-t/myactuator_rmd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/2b-t/myactuator_rmd
- Repository: https://github.com/2b-t/myactuator_rmd

## Overview

##### Project type and purpose
- This is a hardware‐driver SDK (C++17 library) for communicating with MyActuator RMD X actuators over Linux SocketCAN, plus Python bindings via pybind11.
- It is consumed by C++ applications (or ROS 2 nodes) and by Python scripts.

##### File structure
- Top-level
– CMakeLists.txt & cmake/ → build system and packaging
– include/myactuator_rmd/ → public C++ headers (constants, interface, state, protocol, CAN abstractions)
– src/ → C++ implementation (actuator_interface, can/node, protocol requests/responses)
– bindings/ → pybind11 glue (myactuator_rmd_py)
– test/ → unit tests for C++ modules and mocks
- Patterns
– Layered architecture: Protocol ← Driver ← Interface
– Build flags to enable Python bindings, tests, ROS 2 integration

##### Extract insights from README
- Core components: CanDriver, ActuatorInterface, protocol/message types
- External dependencies: Linux SocketCAN, pybind11, Boost/GoogleTest (for tests), ROS 2 (optional)
- Usage flows: C++ API, Python API, ROS 2 integration, virtual CAN for testing

a. Application layer
– C++ consumer (e.g. your_node)
– Python consumer (myactuator_rmd_py module)
– Optional ROS 2 nodes
b. SDK layer
– ActuatorInterface (high-level commands)
– CanDriver (wrapper around socket CAN frames)
– Protocol module (request/response message builder & parser)
– Utilities & exceptions
c. System/OS layer
– Linux SocketCAN socket API
– vcan (for tests) or physical CAN interface
d. Hardware layer
– CAN bus
– MyActuator RMD X actuators (nodes)
e. Build/Test infrastructure
– CMake / setup.py / pip installer
– Unit tests & mocks (GoogleTest, vcan setup)

##### Relationships & data flows
- C++/Python applications invoke ActuatorInterface → internally calls CanDriver → builds Protocol messages → calls SocketCAN API → transmits CAN frames → actuator hardware receives & responds → frame returned via SocketCAN → Protocol parser → ActuatorInterface → back to application.
- In Python flow, calls go through pybind11 binding into same C++ SDK core.
- Tests intercept or mock CanDriver to simulate frames without real hardware (vcan).

##### Architectural patterns & principles
- Layered abstraction: separation of concerns (Interface vs Driver vs Protocol)
- Dependency injection: ActuatorInterface takes a CanDriver instance
- Extensibility points: custom driver implementations, new protocol messages
- Build‐time configurability: toggling Python bindings, tests, coverage

##### Final checklist
- All components labeled (ActuatorInterface, CanDriver, Protocol, Python Bindings, SocketCAN, vcan_test, actuators)
- Callouts for build/test flags (PYTHON_BINDINGS, BUILD_TESTING, SETUP_TEST_IFNAME)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Application Layer"
        CPPApp["C++ Application"]:::app
        PythonApp["Python Script"]:::app
        ROSNode["ROS 2 Node"]:::app
    end

    subgraph "Python Bindings"
        PyBind["pybind11 Module"]:::sdk
    end

    subgraph "SDK Core"
        ActInt["ActuatorInterface"]:::sdk
        CanDrv["CanDriver"]:::sdk
        subgraph "Protocol Module"
            ProtMsg["message.hpp"]:::sdk
            ProtReq["requests.hpp"]:::sdk
            ProtRes["responses.hpp"]:::sdk
            ProtReqCPP["requests.cpp"]:::sdk
            ProtResCPP["responses.cpp"]:::sdk
        end
        CANNode["CAN Node Abstraction"]:::sdk
        CANUtil["CAN Utilities & Exceptions"]:::sdk
        PublicUtil["Public Constants & IO"]:::sdk
    end

    subgraph "OS Layer"
        SocketCAN["Linux SocketCAN API"]:::os
        vCAN["vcan (virtual CAN)"]:::os
    end

    subgraph "Hardware Layer"
        CANBus["CAN Bus"]:::hw
        ActuatorHW["MyActuator RMD X Actuators"]:::hw
    end

    subgraph "Build/Test Infrastructure"
        CMake["CMake (CMakeLists.txt & cmake/)"]:::infra
        PyPkg["Python Packaging (setup.py, setup.cfg, package.xml)"]:::infra
        Tests["Unit Tests & Mocks (test/)"]:::infra
    end

    CPPApp -->|"invoke"| ActInt
    PythonApp -->|"invoke via pybind11"| PyBind
    ROSNode -->|"invoke"| ActInt
    PyBind -->|"calls"| ActInt

    ActInt -->|"build message"| ProtMsg
    ProtMsg -->|"uses"| ProtReq
    ProtReq -->|"uses"| ProtRes
    ProtRes -->|"serialized"| ProtReqCPP
    ProtReqCPP -->|"serialized"| ProtResCPP
    ProtResCPP -->|"parsed"| ActInt

    ActInt -->|"sends command"| CanDrv
    CanDrv -->|"formats frame"| ProtMsg

    CanDrv -->|"write()/read()"| SocketCAN
    vCAN -.->|"mock frames"| CanDrv

    SocketCAN -->|"transmit"| CANBus
    CANBus -->|"frame"| ActuatorHW
    ActuatorHW -->|"response frame"| SocketCAN

    CMake --> ActInt
    CMake --> PyBind
    CMake --> CanDrv
    CMake --> ProtMsg

    Tests --> CanDrv
    Tests --> ProtReqCPP
    Tests --> ProtResCPP

    click ActInt "https://github.com/2b-t/myactuator_rmd/blob/main/include/myactuator_rmd/actuator_interface.hpp"
    click CanDrv "https://github.com/2b-t/myactuator_rmd/tree/main/include/myactuator_rmd/driver"
    click ProtMsg "https://github.com/2b-t/myactuator_rmd/blob/main/include/myactuator_rmd/protocol/message.hpp"
    click ProtReq "https://github.com/2b-t/myactuator_rmd/blob/main/include/myactuator_rmd/protocol/requests.hpp"
    click ProtRes "https://github.com/2b-t/myactuator_rmd/blob/main/include/myactuator_rmd/protocol/responses.hpp"
    click ProtReqCPP "https://github.com/2b-t/myactuator_rmd/blob/main/src/protocol/requests.cpp"
    click ProtResCPP "https://github.com/2b-t/myactuator_rmd/blob/main/src/protocol/responses.cpp"
    click CANNode "https://github.com/2b-t/myactuator_rmd/blob/main/include/myactuator_rmd/can/node.hpp"
    click CANUtil "https://github.com/2b-t/myactuator_rmd/blob/main/include/myactuator_rmd/can/utilities.hpp"
    click PublicUtil "https://github.com/2b-t/myactuator_rmd/blob/main/include/myactuator_rmd/actuator_constants.hpp"
    click PyBind "https://github.com/2b-t/myactuator_rmd/blob/main/bindings/myactuator_rmd.cpp"
    click CMake "https://github.com/2b-t/myactuator_rmd/blob/main/CMakeLists.txt"
    click PyPkg "https://github.com/2b-t/myactuator_rmd/blob/main/setup.py"
    click Tests "https://github.com/2b-t/myactuator_rmd/tree/main/test/"

    classDef app fill:#8fbc8f,stroke:#333,stroke-width:1px
    classDef sdk fill:#add8e6,stroke:#333,stroke-width:1px
    classDef os fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef hw fill:#f9d56e,stroke:#333,stroke-width:1px
    classDef infra fill:#f4a261,stroke:#333,stroke-width:1px
```
