# allan-almeida1/ur5-pick-and-place architecture

> Architecture diagram of the GitHub repository allan-almeida1/ur5-pick-and-place, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/allan-almeida1/ur5-pick-and-place
- Repository: https://github.com/allan-almeida1/ur5-pick-and-place

## Overview

##### Main components
- Simulation Environment – CoppeliaSim with the “UR5.ttt” scene.
- Robot Control Module – The Python code (found in src/ur5.py) that implements the kinematics, trajectory planning, and control logic.
- Communication/Interface Layer – The ZMQRemote API libraries present in the “src/coppeliasim_zmqremoteapi_client” and “zmqRemoteApi” directories. These mediate command exchange between the control module and the simulator.
- Machine Learning Module – The CNN model stored as “machine_learning/cup_position_model.h5” and supporting routines (likely invoked within the Jupyter Notebook “Trabalho.ipynb”) that performs cup detection (converting image inputs to relative cup positions).
- Jupyter Notebook Interface – “Trabalho.ipynb” provides an interactive way to initialize the simulation, load dependencies, and execute various control scripts.

##### Relationships and interactions
- Data Flow from Camera to ML Module: Images (or image data) captured in the simulation could be fed into the CNN to predict the cup’s coordinates.
- ML to Control Module: The predicted positions (in image space converted to real-world XYZ coordinates) are used by the robot control logic to compute trajectories.
- Control Module to Communication Layer: The computed joint velocities (via forward/inverse kinematics and quintic trajectories) are sent to the CoppeliaSim simulator using the ZMQRemote API.
- User Interface (Jupyter Notebook) sits at the top, orchestrating the overall flow by invoking functions from both the machine learning and control modules.

##### Architectural patterns and design principles
- Separation of Concerns – Distinct modules for simulation interfacing, robot kinematics/control and vision (machine learning) make the system modular and easier to maintain.
- Asynchronous Communication – The presence of an “asyncio” directory suggests non-blocking operations in the simulation communication channel.
- Integration of Machine Learning with Real-Time Control – The design clearly decouples the prediction model from the control logic, connected through clearly defined data flows.
- Use of a Client-Server Pattern – The ZMQRemote API acts as a middleware between the control code and the simulation server (CoppeliaSim).

##### Final advice
- Every component shows its relationship with others.
- Avoid a “flat” picture – separate the conceptual layers (presentation/interface, application logic, simulation interfacing, and ML vision) to improve clarity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    Notebook["User Interface (Trabalho.ipynb)"]:::ui

    %% Machine Learning Layer
    MLModule["Machine Learning Module (CNN, cup_position_model.h5)"]:::ml

    %% Control Layer
    Control["Robot Control Module (ur5.py)"]:::control

    %% Communication/Interface Layer
    subgraph "Communication Layer (ZMQRemote API)"
        SyncAPI["Synchronous API"]:::comm
        AsyncAPI["Asynchronous API"]:::comm
    end

    %% Simulation Layer
    CSim["CoppeliaSim Environment (UR5.ttt Scene)"]:::sim

    %% External Input (Camera Data)
    Camera["Camera Data"]:::camera

    %% Relationships
    Notebook -->|"calls"| Control
    Notebook -->|"initiate"| MLModule
    Camera -->|"images"| MLModule
    MLModule -->|"predictions"| Control
    Control -->|"commands"| SyncAPI
    Control -->|"async_commands"| AsyncAPI
    SyncAPI -->|"sends"| CSim
    AsyncAPI -->|"sends"| CSim

    %% Click Events
    click Notebook "https://github.com/allan-almeida1/ur5-pick-and-place/blob/main/Trabalho.ipynb"
    click Control "https://github.com/allan-almeida1/ur5-pick-and-place/blob/main/src/ur5.py"
    click SyncAPI "https://github.com/allan-almeida1/ur5-pick-and-place/blob/main/zmqRemoteApi/__init__.py"
    click AsyncAPI "https://github.com/allan-almeida1/ur5-pick-and-place/blob/main/src/coppeliasim_zmqremoteapi_client/asyncio/__init__.py"
    click MLModule "https://github.com/allan-almeida1/ur5-pick-and-place/blob/main/machine_learning/cup_position_model.h5"
    click CSim "https://github.com/allan-almeida1/ur5-pick-and-place/blob/main/UR5.ttt"

    %% Styles
    classDef ui fill:#FFCC00,stroke:#333,color:#000,stroke-width:2px;
    classDef control fill:#99CCFF,stroke:#333,color:#000,stroke-width:2px;
    classDef ml fill:#CCFFCC,stroke:#333,color:#000,stroke-width:2px;
    classDef comm fill:#FFCCCC,stroke:#333,color:#000,stroke-width:2px;
    classDef sim fill:#CCCCFF,stroke:#333,color:#000,stroke-width:2px;
    classDef camera fill:#FFFFCC,stroke:#333,color:#000,stroke-width:2px;
```
