# devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks architecture

> Architecture diagram of the GitHub repository devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks
- Repository: https://github.com/devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks

## Overview

##### Main Components
- Environment Modules:
- sim_env.py – Implements simulation environments with joint space control (using Mujoco + DM_Control)
- ee_sim_env.py – Implements simulation environments with end-effector (EE) space control
- Policy and Model Components:
- policy.py – Serves as the adapter for the ACT policy
- scripted_policy.py – Contains scripted control logic for simulated environments (often used as baseline or for generating scripted episodes)
- (Potentially a ‘detr’ directory, as mentioned in the README, holding modified ACT models based on DETR)
- Training and Evaluation Modules:
- imitate_episodes.py – Script for training and evaluating the ACT policy (which likely runs episodes in simulation)
- record_sim_episodes.py – Used to record episodes (data collection in the simulation environment)
- visualize_episodes.py – Takes recorded data (stored in .hdf5) and converts it into visual media (videos), facilitating analysis
- Shared Utilities:
- constants.py – Shared constants across all modules, ensuring consistency of parameters and configuration
- utils.py – Contains helper functions and data loading capabilities which support all of the above components

##### Relationships and Interactions
- The simulation environments (sim_env.py and ee_sim_env.py) are central to both training and data collection, interfacing with the policy components.
- Policy components (policy.py and scripted_policy.py) interact with the environments to generate trajectories. They can be swapped or compared (ACT vs. scripted).
- imitate_episodes.py ties together the training, evaluation, and interaction between the policy and simulation environment. It is at the core of the training loop.
- record_sim_episodes.py and visualize_episodes.py handle the generation of test cases and the post hoc visualization and debugging of generated episodes.
- The constants and utils modules provide uniform support across all these components such that changes in configuration or data handling propagate consistently.

##### Architectural Patterns and Design Principles
- Modularity: Each file represents distinct functionality (simulation, policy, training, visualization), which allows for easy testing and replacement of components.
- Separation of Concerns: The system clearly separates simulation (environment generation and testing), policy logic (learning and scripted behavior), training/evaluation workflows, and auxiliary functionalities (constants and helper functions).
- Extensibility: With dedicated modules for environment types and clear adapter patterns in the policy, the system is built to support further extensions, whether to real-world trials or additional simulation modes.
- Use of Frameworks: The project relies on frameworks like Mujoco, DM_Control, PyTorch (and torchvision), and even DETR adaptations, as indicated by installation requirements and README instructions.

##### Technologies, Frameworks, and Libraries
- Python 3.8.10, PyTorch, torchvision for deep learning
- Mujoco and DM_Control for physics-based simulation environments
- OpenCV, matplotlib for visualization
- Other utilities (pyyaml, pyyaml, packaging, etc.) that support environment setup and configuration

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Simulation Environments
    subgraph "Simulation Environments"
        A["Joint Space (sim_env.py)"]:::simulation
        B["EE Space (ee_sim_env.py)"]:::simulation
    end

    %% Policy Components
    subgraph "Policy Components"
        C["ACT Policy Adapter (policy.py)"]:::policy
        D["Scripted Policy (scripted_policy.py)"]:::policy
    end

    %% Training and Evaluation
    subgraph "Training and Evaluation"
        E["Training Script (imitate_episodes.py)"]:::training
        F["Episode Recording (record_sim_episodes.py)"]:::training
        G["Episode Visualization (visualize_episodes.py)"]:::training
    end

    %% Shared Utilities
    subgraph "Shared Utilities"
        H["Shared Constants (constants.py)"]:::utility
        I["Helper Utilities (utils.py)"]:::utility
    end

    %% External Dependencies
    subgraph "External Dependencies"
        J["PyTorch/torchvision"]:::external
        K["Mujoco+DM_Control"]:::external
        L["OpenCV/Matplotlib"]:::external
    end

    %% Connections between modules
    %% Training Script interacts with Simulation Environments and Policy Components
    E -->|"trains"| C
    E -->|"trains"| D
    E -->|"executes on"| A
    E -->|"executes on"| B

    %% Simulation Environments provide data to Policy Components
    A -->|"env_data"| C
    B -->|"env_data"| D

    %% Policy outputs are recorded
    C -->|"trajectory"| F
    D -->|"trajectory"| F

    %% Recorded episodes are visualized
    F -->|"feeds_data"| G

    %% External dependencies support various components
    J -->|"supports"| C
    J -->|"supports"| D
    K -->|"supports"| A
    K -->|"supports"| B
    L -->|"supports"| G

    %% Shared Utilities support common configurations and functionalities
    H ---|"configures"| A
    H ---|"configures"| B
    H ---|"configures"| C
    H ---|"configures"| D
    H ---|"configures"| E
    I ---|"assists"| A
    I ---|"assists"| B
    I ---|"assists"| C
    I ---|"assists"| D
    I ---|"assists"| E
    I ---|"assists"| F
    I ---|"assists"| G

    %% Click Events
    click A "https://github.com/devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks/blob/main/sim_env.py"
    click B "https://github.com/devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks/blob/main/ee_sim_env.py"
    click C "https://github.com/devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks/blob/main/policy.py"
    click D "https://github.com/devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks/blob/main/scripted_policy.py"
    click E "https://github.com/devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks/blob/main/imitate_episodes.py"
    click F "https://github.com/devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks/blob/main/record_sim_episodes.py"
    click G "https://github.com/devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks/blob/main/visualize_episodes.py"
    click H "https://github.com/devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks/blob/main/constants.py"
    click I "https://github.com/devvirani13/generate-real-time-trajectories-for-a-single-handed-robotic-arm-for-different-tasks/blob/main/utils.py"

    %% Styles
    classDef simulation fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef policy fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef training fill:#ABEBC6,stroke:#239B56,stroke-width:2px;
    classDef utility fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
```
