# gsarenas/mogbe architecture

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

- Interactive diagram: https://gitdiagram.com/gsarenas/mogbe
- Repository: https://github.com/gsarenas/mogbe

## Overview

##### Project type and purpose
- MOGBE is a ROS 2–based autonomous mobile robotics platform for both simulation (Gazebo+RViz) and real‐world use (Raspberry Pi + Arduino Nano + LiDAR). It is not a monolithic app but a distributed robotics system combining hardware, sensor drivers, control nodes, SLAM, navigation, and simulation nodes.

##### File‐structure analysis
- Top‐level:
- config/: ROS 2 parameter YAMLs for Gazebo, Nav2, SLAM, controllers, twist_mux, RViz configs
- description/: URDF/XACRO robot description, inertial, sensors, ros2_control integration
- launch/: Python launch scripts for simulation, real robot (Pi), dev environment, online/async SLAM, navigation
- worlds/: Gazebo world files (hospital, warehouse, wall, empty)
- meshes/, models/: 3D assets for Gazebo simulation
- scripts/: simple ROS 2 “talker”–style Python scripts for manual movement, line follower
- mogbe/: ROS 2 package source code (nodes, controllers, interfaces)
- package.xml, CMakeLists.txt: ROS 2 build and dependency definitions

##### Key runtime components (to show
- Hardware (Real)
- Raspberry Pi (runs ROS 2 core, sensor nodes, controllers)
- Arduino Nano (low‐level PWM/motor control)
- LiDAR (LD19‐STL)
- Motor drivers/wheels, battery, IMU (via XACRO)

- Dev Machine
- Gazebo simulator (+ gazebo_ros)
- RViz2 for visualization
- SLAM Toolbox (online_async, localization)
- Navigation2 stack (nav2)
- teleop_twist_keyboard, twist_mux
- Controller Manager (spawner diff_cont, joint_broadcaster)

- ROS 2 Middleware
- DDS-based communication between Pi↔Dev/simulation nodes

- Data flows
- sensor → scan topic → SLAM/Navigation
- cmd_vel → twist_mux → diff_drive_controller → motor commands → Arduino
- robot_description (URDF) broadcast by robot_state_publisher → TF2 tree
- Gazebo ↔ spawn_entity, gazebo_ros plugins ↔ robot_description

##### Architectural patterns and principles
- Modular, node‐based microservices: each ROS 2 node has a single responsibility (SLAM, navigation, controller, state publisher, teleop).
- Parameter‐driven configuration: YAML files injected at launch.
- Separation of simulation vs real‐hardware: use_sim_time parameter toggles time source; use_ros2_control toggles hardware interface.
- Publish/subscribe for sensor and control data; service/action for nav goals.
- tf2 for coordinate transforms; launch files for composition.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Middleware
    subgraph "DDS Network"
        direction TB
        DDS("DDS-based ROS 2 Middleware"):::middleware
    end

    %% Configuration and Description
    ConfigStore["Config Store (YAML & RViz configs)"]:::config
    Description["Robot Description (URDF/XACRO)"]:::config

    %% Simulation Lane
    subgraph "Simulation" 
        direction TB
        Gazebo["Gazebo Simulator"]:::sim
        SpawnEntity["spawn_entity + gazebo_ros plugins"]:::sim
        SimStatePub["robot_state_publisher (use_sim_time)"]:::sim
    end

    %% Development Machine Lane
    subgraph "Dev Machine"
        direction TB
        RViz["RViz2"]:::sim
        SLAM["SLAM Toolbox (online_async)"]:::control
        Nav2["Navigation2 Stack"]:::control
        Teleop["teleop_twist_keyboard"]:::control
        TwistMux["twist_mux"]:::control
        CtrlMgr["Controller Manager"]:::control
    end

    %% Raspberry Pi Lane
    subgraph "Raspberry Pi (Real Robot)"
        direction TB
        PiCore["Raspberry Pi - ROS 2 Core"]:::hardware
        LiDAR["LiDAR Driver"]:::hardware
        DiffCont["diff_drive_controller"]:::control
        JointBroad["joint_broadcaster"]:::control
        Arduino["Arduino Nano"]:::hardware
    end

    %% 3D Assets and Worlds
    Meshes["Meshes (.obj/.mtl)"]:::sim
    Models["Gazebo Models"]:::sim
    Worlds["Gazebo World Files"]:::sim

    %% Data Store
    ConfigStore -->|loads params| SimStatePub
    ConfigStore -->|loads params| Gazebo
    ConfigStore -->|loads params| PiCore

    Description -->|provides URDF| SimStatePub
    Description -->|provides URDF| PiCore

    %% Simulation interactions
    Gazebo -->|spawns robot| SpawnEntity
    SpawnEntity -->|requires robot_description| SimStatePub
    SimStatePub -->|publishes TF2| Gazebo
    SimStatePub -->|publishes TF2| RViz

    %% DDS connections
    RViz <--> DDS
    Gazebo <--> DDS
    SLAM <--> DDS
    Nav2 <--> DDS
    Teleop <--> DDS
    PiCore <--> DDS

    %% Topic flows
    LiDAR -->|/scan| DDS
    DDS -->|/scan| SLAM
    SLAM -->|map & pose| Nav2
    Nav2 -->|/cmd_vel| DDS
    DDS -->|/cmd_vel| TwistMux
    TwistMux -->|commands| DiffCont
    DiffCont -->|motor PWM| Arduino

    %% Controller manager and hardware interfaces
    CtrlMgr -->|spawns| DiffCont
    CtrlMgr -->|spawns| JointBroad
    DiffCont -->|hardware_interface| PiCore
    JointBroad -->|hardware_interface| PiCore

    %% Asset grouping
    Meshes --> Gazebo
    Models --> Gazebo
    Worlds --> Gazebo

    %% Launch scripts annotations
    click ConfigStore "https://github.com/gsarenas/mogbe/tree/main/config/"
    click Description "https://github.com/gsarenas/mogbe/tree/main/description/"
    click Gazebo "https://github.com/gsarenas/mogbe/blob/main/launch/mogbe_simulation.launch.py"
    click SpawnEntity "https://github.com/gsarenas/mogbe/blob/main/launch/mogbe_simulation_all.launch.py"
    click RViz "https://github.com/gsarenas/mogbe/blob/main/launch/mogbe_robot_dev.launch.py"
    click PiCore "https://github.com/gsarenas/mogbe/blob/main/launch/mogbe_robot_pi.launch.py"
    click Arduino "https://github.com/gsarenas/mogbe/blob/main/launch/mogbe_robot_pi_all.launch.py"
    click SLAM "https://github.com/gsarenas/mogbe/blob/main/launch/online_async.launch.py"
    click Nav2 "https://github.com/gsarenas/mogbe/blob/main/launch/navigation.launch.py"
    click TwistMux "https://github.com/gsarenas/mogbe/blob/main/launch/localization.launch.py"
    click SimStatePub "https://github.com/gsarenas/mogbe/blob/main/launch/rsp.launch.py"
    click Worlds "https://github.com/gsarenas/mogbe/tree/main/worlds/"
    click Meshes "https://github.com/gsarenas/mogbe/tree/main/meshes/"
    click Models "https://github.com/gsarenas/mogbe/tree/main/models/"
    click MogbeSrc "https://github.com/gsarenas/mogbe/tree/main/mogbe/"
    click Teleop "https://github.com/gsarenas/mogbe/blob/main/scripts/mogbe_move.py"
    click Arduino "https://github.com/gsarenas/mogbe/blob/main/scripts/mogbe_line_follower.py"
    click TwistMux "https://github.com/gsarenas/mogbe/blob/main/scripts/mogbe_new_goal.py"
    click PackageDef "https://github.com/gsarenas/mogbe/blob/main/package.xml"
    click BuildFiles "https://github.com/gsarenas/mogbe/blob/main/CMakeLists.txt"

    %% Styles
    classDef hardware fill:#AED6F1,stroke:#1B4F72,color:#1B2631;
    classDef sim fill:#ABEBC6,stroke:#145A32,color:#0B5345;
    classDef control fill:#F9E79F,stroke:#7D6608,color:#7D6608;
    classDef config fill:#D5D8DC,stroke:#626567,color:#2C3E50;
    classDef middleware fill:#E5E8E8,stroke:#566573,color:#1C2833;
```
