# legorovers/pirover_simulator architecture

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

- Interactive diagram: https://gitdiagram.com/legorovers/pirover_simulator
- Repository: https://github.com/legorovers/pirover_simulator

## Overview

This project is a robot simulator called “PiRover Simulator” intended to simulate various robotic behaviors and environments. The file tree and README indicate that the project is a simulation environment with modular components—agents, robots, sensors, UI windows, and world configurations.

##### Main Components
- Simulator Core: At the heart of the project is the simulation engine. Key files include pysim.py (and pysimosx.py for MacOS) which serve as entry points.
- Source Modules (src folder): This organizes core functionalities into several sub-components:
– Robots (src/robots): Contains different robot implementations (e.g., initio.py, pi2go.py) and constants for their behavior.
– Sensors (src/sensors): Manages modules for distances, lights, lines, sonar, and LED sensors that provide environmental feedback.
– Sprites (src/sprites): Handles the visual representation and interactive components like selectable sprites and switches.
– Windows (src/windows): Provides the user interface components (start window, object window, simulator window) that interact with the simulation.
– Resource Management (src/resources.py and resources folder): Contains assets such as images, maps, and XML configurations for simulation environments (found in worlds/).
– Utility functions (src/util.py): General helper logic.
- Agents (agent and bdi folders): Provide different implementations of the robot agents. They may follow the BDI (Belief-Desire-Intention) pattern or other logic as seen in files like bdiagent.py, initioagent.py, pi2goagent.py.
- SimClient (simclient folder): Contains network/client simulation components such as simclient.py and simrobot.py, which might handle client-server interactions or simulation control.
- Example Scripts (examples folder): These demonstrate various robot behaviors such as line-following, obstacle avoidance, etc.
- World Definitions (worlds folder): Contains XML files defining simulation environments (mazes, houses, track layouts, etc.).

##### Relationships and Interactions
- The entry point (pysim.py / pysimosx.py) initializes the simulation core.
- The simulation engine accesses the src modules to load resources, instantiate robot objects (from src/robots), sensors (from src/sensors), manage sprites, and set up windows for the UI.
- World configuration files define the simulation’s environmental layout and obstacles, influencing how robots navigate.
- Agents interact with the simulation by sending commands or decisions based on sensor data and simulation events. They likely leverage modules in the agent and bdi directories.
- SimClient interfaces might be used to simulate remote control or network communication aspects between the simulation and any external controllers.
- The examples provide sample scenarios to test agent behaviors and simulation dynamics.

##### Architectural Patterns and Design Principles
- Modular Design: The project is organized into clear modules (agents, simulation core, resources, sensors, etc.) that encapsulate distinct functionalities.
- Separation of Concerns: There is a clean separation between simulation logic (engine and resources), interactive agent behaviors, and user interface elements.
- Extensibility: With clearly separated folders for agents (agent/ and bdi/), new agent behaviors can be added without large-scale modifications to the simulation engine.
- Configuration Driven: World environments are driven by XML files, making it easier to modify simulation scenarios without altering core code.
- Testability: The presence of a tests directory indicates unit testing for individual components (e.g., sensors).

##### Relevant Technologies, Frameworks, or Libraries
- Python is the primary language.
- The project probably uses common libraries (possibly pygame for graphics, given the simulation context) although not explicitly mentioned in the README.
- Pre-commit configuration suggests code quality tools are in place.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Points
    subgraph "Entry Points"
        entry1("pysim.py"):::coreEntry
        entry2("pysimosx.py"):::coreEntry
    end

    %% Simulation Engine and Core Modules
    subgraph "Simulation Engine"
        core("Core Engine"):::coreText
        subgraph "Core Modules"
            robots("Robots Module"):::coreModule
            sensors("Sensors Module"):::coreModule
            sprites("Sprites Module"):::coreModule
            windows("Windows Module"):::coreModule
            resources("Resource Management"):::coreModule
            util("Utility Functions"):::coreModule
        end
    end

    %% Agent Implementations
    subgraph "Agent Implementations"
        agent1("Agent (agent)"):::agentModule
        agent2("Agent (bdi)"):::agentModule
    end

    %% SimClient Components
    subgraph "SimClient Components"
        simclient("SimClient"):::simClient
    end

    %% External and Configuration Files
    subgraph "External/Configuration"
        worlds("World Definitions"):::externalConfig
        examples("Examples"):::externalConfig
    end

    %% Connections from Entry Points to Core Engine
    entry1 --> core
    entry2 --> core

    %% Core Engine accessing Core Modules
    core -->|"loads"| robots
    core -->|"loads"| sensors
    core -->|"loads"| sprites
    core -->|"loads"| windows
    core -->|"loads"| resources
    core -->|"loads"| util

    %% Resource Management loads World Configurations
    resources -->|"reads"| worlds

    %% Agents interact with Core Engine
    agent1 <-->|"commands/feedback"| core
    agent2 <-->|"commands/feedback"| core

    %% SimClient communication with Core Engine
    simclient <-->|"network/control"| core

    %% Examples demonstrate simulation behavior
    examples -->|"demonstrates"| core

    %% Click Events
    click entry1 "https://github.com/legorovers/pirover_simulator/blob/master/pysim.py"
    click entry2 "https://github.com/legorovers/pirover_simulator/blob/master/pysimosx.py"
    click robots "https://github.com/legorovers/pirover_simulator/tree/master/src/robots"
    click sensors "https://github.com/legorovers/pirover_simulator/tree/master/src/sensors"
    click sprites "https://github.com/legorovers/pirover_simulator/tree/master/src/sprites"
    click windows "https://github.com/legorovers/pirover_simulator/tree/master/src/windows"
    click resources "https://github.com/legorovers/pirover_simulator/blob/master/src/resources.py"
    click util "https://github.com/legorovers/pirover_simulator/blob/master/src/util.py"
    click agent1 "https://github.com/legorovers/pirover_simulator/tree/master/agent"
    click agent2 "https://github.com/legorovers/pirover_simulator/tree/master/bdi"
    click simclient "https://github.com/legorovers/pirover_simulator/tree/master/simclient"
    click examples "https://github.com/legorovers/pirover_simulator/tree/master/examples"
    click worlds "https://github.com/legorovers/pirover_simulator/tree/master/worlds"

    %% Style Definitions
    classDef coreEntry fill:#FCCD04,stroke:#333,stroke-width:2px,color:#000
    classDef coreText fill:#e0e0e0,stroke:#333,stroke-width:2px,color:#000
    classDef coreModule fill:#C2D4DD,stroke:#333,stroke-width:2px,color:#000
    classDef agentModule fill:#FFDFBA,stroke:#333,stroke-width:2px,color:#000
    classDef simClient fill:#D3F8E2,stroke:#333,stroke-width:2px,color:#000
    classDef externalConfig fill:#F1C0E8,stroke:#333,stroke-width:2px,color:#000
```
