# ioloizou/g1_locomotion architecture

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

- Interactive diagram: https://gitdiagram.com/ioloizou/g1_locomotion
- Repository: https://github.com/ioloizou/g1_locomotion

## Overview

##### Main Components
- Robot Description Module (g1_description):
- Contains URDF and XML files describing different robot configurations (23-dof, 29-dof, dual arm, etc.).
- Provides the 3D meshes for each robot part, which are used for visualization/simulation.
- Acts as the “hardware” abstraction layer in a virtual sense.

- Message Definitions (g1_msgs):
- Defines custom messages (e.g., ContactPoint.msg, SRBD_state.msg).
- Serves as the interface between different modules (e.g., sending sensor data, state feedback, or control commands).

- Model Predictive Control Module (g1_mpc):
- Implements the convex MPC algorithm, the heart of the locomotion stack.
- This module is likely integrated with the simulation to compute control inputs based on robot state data.

- Simulation Environment (g1_mujoco_sim):
- Provides a simulation environment using MuJoCo.
- Contains launch files, Python scripts (run_simulation.py, PD_controller.py, ros_run_simulation.py) and configuration files.
- Simulates the robot’s dynamic behavior according to the description provided in g1_description, while receiving control inputs from g1_mpc and possibly using the messages defined in g1_msgs.

##### Relationships and Data Flow
- The Simulation Environment utilizes the Robot Description to instantiate a virtual model of the robot.
- Sensor data or simulation state is packaged and exchanged using the ROS messages from g1_msgs.
- The MPC module (g1_mpc) receives state data and computes control commands.
- These control commands are then sent back to the simulation (g1_mujoco_sim) where controllers (e.g., the PD_controller.py) may further refine or execute them.
- There is a continuous loop: simulation state → message broadcasting → MPC control computation → updated commands → simulation actuation.

##### Architectural Patterns and Design Principles
- Modular Architecture: The clear separation among description, messaging, control, and simulation demonstrates an emphasis on modularity which improves maintainability and scalability.
- Separation of Concerns: Each top-level directory is focused on one aspect of the system – description, control, messaging, and simulation.
- Data Flow and Dependency Management: Using ROS messages suggests a publish/subscribe design, ensuring that state and control messages are decoupled from hardware or simulation specifics.

- Critical system elements are represented.
- Validate that every module’s responsibility and interconnection is clear.
- Avoid overcomplicating—the goal is a clear, detailed depiction of the data/control flows within a modular, ROS-based humanoid locomotion architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Simulation (g1_mujoco_sim)<br/>MuJoCo Simulation, PD Controller, Launch Files"]:::simulation
    C["Message Interface (g1_msgs)<br/>Custom ROS Messages (SRBD_state,ContactPoint)"]:::message
    B["MPC Control (g1_mpc)<br/>Convex MPC Algorithm"]:::control
    D["Robot Description (g1_description)<br/>URDF, Meshes,Config Files"]:::hardware

    A -->|"instantiates"| D
    A -->|"publishes_state"| C
    C -->|"forwards_state"| B
    B -->|"sends_command"| C
    C -->|"updates_simulation"| A

    click A "https://github.com/ioloizou/g1_locomotion/tree/main/g1_mujoco_sim"
    click B "https://github.com/ioloizou/g1_locomotion/tree/main/g1_mpc"
    click C "https://github.com/ioloizou/g1_locomotion/tree/main/g1_msgs"
    click D "https://github.com/ioloizou/g1_locomotion/tree/main/g1_description"

    classDef simulation fill:#ffd700,stroke:#333,stroke-width:2px
    classDef control fill:#90ee90,stroke:#333,stroke-width:2px
    classDef message fill:#ffcccb,stroke:#333,stroke-width:2px
    classDef hardware fill:#add8e6,stroke:#333,stroke-width:2px
```
