# alberto-mate/carla-sb3-rl-training-environment architecture

> Architecture diagram of the GitHub repository alberto-mate/carla-sb3-rl-training-environment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alberto-mate/carla-sb3-rl-training-environment
- Repository: https://github.com/alberto-mate/carla-sb3-rl-training-environment

## Overview

This repository provides a CARLA driving environment and Stable-Baselines3 training/evaluation workflows, with configurable observations, rewards, navigation, and optional VAE image encoding. The main loop configures an environment, obtains observations and rewards through simulation steps, and trains or evaluates a policy. README capabilities also include manual/RL data collection and VAE training. Connections reflect README statements and the supplied source index or excerpts; some internal wiring is not visible in the sampled code.

Main entry points: [`train.py`](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/train.py) (Training workflow), [`eval.py`](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/eval.py) (Evaluation workflow), [`carla_env/envs/collect_data_rl_env.py`](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/envs/collect_data_rl_env.py) (RL collection), [`carla_env/envs/carla_route_env.py`](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/envs/carla_route_env.py) (Route environment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_simulation["Simulation environment"]
  node_route_env["Route environment<br/>[carla_route_env.py]"]
  node_birdview["Birdview environment<br/>[birdview_env.py]"]
  node_manual_collection["Manual collection"]
  node_rl_collection["RL collection"]
  node_wrappers["Environment wrappers<br/>[wrappers.py]"]
  node_hud["HUD<br/>[hud.py]"]
end

subgraph group_navigation["Route navigation"]
  node_route_planning["Route planning<br/>[planner.py]"]
  node_global_planner["Global route planner"]
  node_planner_dao["Planner map access"]
  node_local_planner["Local planner<br/>[local_planner.py]"]
  node_controller["Vehicle controller<br/>[controller.py]"]
end

subgraph group_learning["RL experiments"]
  node_config["Experiment configuration<br/>[config.py]"]
  node_training["Training workflow<br/>[train.py]"]
  node_evaluation["Evaluation workflow<br/>[eval.py]"]
  node_plots["Evaluation plots<br/>[eval_plots.py]"]
  node_utils["RL utilities<br/>[utils.py]"]
end

subgraph group_observations["State and rewards"]
  node_state["State encoding<br/>[state_commons.py]"]
  node_rewards["Reward functions<br/>[rewards.py]"]
end

subgraph group_vae["VAE and data"]
  node_vae_model["VAE model<br/>[models.py]"]
  node_vae_training["VAE training<br/>[train_vae.py]"]
  node_vae_learning["VAE learning<br/>[learning.py]"]
  node_vae_loaders["Image loaders<br/>[loaders.py]"]
  node_vae_misc["VAE utilities<br/>[misc.py]"]
end

node_driver(("User"))
node_carla["CARLA simulator"]
node_sb3["Stable Baselines3"]

node_driver -->|"starts training"| node_training
node_driver -->|"starts evaluation"| node_evaluation
node_training -->|"uses settings"| node_config
node_evaluation -->|"uses settings"| node_config
node_training -->|"trains in"| node_route_env
node_evaluation -->|"evaluates in"| node_route_env
node_training -->|"trains policy"| node_sb3
node_evaluation -->|"evaluates policy"| node_sb3
node_route_env -.->|"steps simulation"| node_carla
node_route_env -->|"computes routes"| node_route_planning
node_route_env -->|"uses sensors"| node_wrappers
node_route_env -->|"updates display"| node_hud
node_birdview -->|"uses routes"| node_route_planning
node_birdview -->|"uses sensors"| node_wrappers
node_manual_collection -->|"updates display"| node_hud
node_manual_collection -->|"uses sensors"| node_wrappers
node_rl_collection -->|"uses routes"| node_route_planning
node_rl_collection -->|"encodes observations"| node_state
node_rl_collection -->|"computes reward"| node_rewards
node_rl_collection -->|"reads settings"| node_config
node_rl_collection -->|"updates display"| node_hud
node_route_planning -->|"builds global route"| node_global_planner
node_route_planning -->|"creates map access"| node_planner_dao
node_route_planning -->|"uses road options"| node_local_planner
node_local_planner -->|"delegates control"| node_controller
node_training -->|"configures observations"| node_state
node_training -->|"configures rewards"| node_rewards
node_evaluation -->|"configures observations"| node_state
node_evaluation -->|"configures rewards"| node_rewards
node_training -.->|"uses callbacks"| node_utils
node_evaluation -->|"generates plots"| node_plots
node_state -->|"encodes images"| node_vae_model
node_state -->|"uses transforms"| node_vae_misc
node_vae_training -->|"trains model"| node_vae_model
node_vae_training -->|"uses learning routines"| node_vae_learning
node_vae_training -->|"loads images"| node_vae_loaders
node_vae_training -->|"uses utilities"| node_vae_misc
node_driver -->|"starts VAE training"| node_vae_training
node_driver -->|"collects images"| node_manual_collection
node_driver -->|"collects images"| node_rl_collection

click node_route_env "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/envs/carla_route_env.py"
click node_birdview "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/envs/birdview_env.py"
click node_manual_collection "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/envs/collect_data_manual_env.py"
click node_rl_collection "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/envs/collect_data_rl_env.py"
click node_wrappers "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/wrappers.py"
click node_hud "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/tools/hud.py"
click node_route_planning "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/navigation/planner.py"
click node_global_planner "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/navigation/global_route_planner.py"
click node_planner_dao "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/navigation/global_route_planner_dao.py"
click node_local_planner "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/navigation/local_planner.py"
click node_controller "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/navigation/controller.py"
click node_config "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/config.py"
click node_training "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/train.py"
click node_evaluation "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/eval.py"
click node_plots "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/eval_plots.py"
click node_utils "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/utils.py"
click node_state "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/state_commons.py"
click node_rewards "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/rewards.py"
click node_vae_model "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/vae/models.py"
click node_vae_training "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/vae/train_vae.py"
click node_vae_learning "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/vae/utils/learning.py"
click node_vae_loaders "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/vae/utils/loaders.py"
click node_vae_misc "https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/vae/utils/misc.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_route_env,node_birdview,node_manual_collection,node_rl_collection,node_wrappers,node_hud,node_driver toneBlue
class node_route_planning,node_global_planner,node_planner_dao,node_local_planner,node_controller toneAmber
class node_config,node_training,node_evaluation,node_plots,node_utils toneMint
class node_state,node_rewards toneRose
class node_vae_model,node_vae_training,node_vae_learning,node_vae_loaders,node_vae_misc,node_carla,node_sb3 toneIndigo
```

## Components

### Simulation environment

- [Route environment](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/envs/carla_route_env.py): `carla_env/envs/carla_route_env.py`
- [Birdview environment](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/envs/birdview_env.py): `carla_env/envs/birdview_env.py`
- [Manual collection](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/envs/collect_data_manual_env.py): `carla_env/envs/collect_data_manual_env.py`
- [RL collection](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/envs/collect_data_rl_env.py): `carla_env/envs/collect_data_rl_env.py`
- [Environment wrappers](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/wrappers.py): `carla_env/wrappers.py`
- [HUD](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/tools/hud.py): `carla_env/tools/hud.py`

### Route navigation

- [Route planning](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/navigation/planner.py): `carla_env/navigation/planner.py`
- [Global route planner](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/navigation/global_route_planner.py): `carla_env/navigation/global_route_planner.py`
- [Planner map access](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/navigation/global_route_planner_dao.py): `carla_env/navigation/global_route_planner_dao.py`
- [Local planner](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/navigation/local_planner.py): `carla_env/navigation/local_planner.py`
- [Vehicle controller](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/navigation/controller.py): `carla_env/navigation/controller.py`

### RL experiments

- [Experiment configuration](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/config.py): `config.py`
- [Training workflow](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/train.py): `train.py`
- [Evaluation workflow](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/eval.py): `eval.py`
- [Evaluation plots](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/eval_plots.py): `eval_plots.py`
- [RL utilities](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/utils.py): `utils.py`

### State and rewards

- [State encoding](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/state_commons.py): `carla_env/state_commons.py`
- [Reward functions](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/carla_env/rewards.py): `carla_env/rewards.py`

### VAE and data

- [VAE model](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/vae/models.py): `vae/models.py`
- [VAE training](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/vae/train_vae.py): `vae/train_vae.py`
- [VAE learning](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/vae/utils/learning.py): `vae/utils/learning.py`
- [Image loaders](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/vae/utils/loaders.py): `vae/utils/loaders.py`
- [VAE utilities](https://github.com/alberto-mate/carla-sb3-rl-training-environment/blob/main/vae/utils/misc.py): `vae/utils/misc.py`

### Other components

- **User**
- **CARLA simulator**
- **Stable Baselines3**

## Connections

- User → Training workflow: starts training (evidence: `README.md`)
- User → Evaluation workflow: starts evaluation (evidence: `README.md`)
- Training workflow → Experiment configuration: uses settings (evidence: `train.py`)
- Evaluation workflow → Experiment configuration: uses settings (evidence: `eval.py`)
- Training workflow → Route environment: trains in (evidence: `train.py`)
- Evaluation workflow → Route environment: evaluates in (evidence: `eval.py`)
- Training workflow → Stable Baselines3: trains policy (evidence: `README.md`)
- Evaluation workflow → Stable Baselines3: evaluates policy (evidence: `README.md`)
- Route environment → CARLA simulator: steps simulation
- Route environment → Route planning: computes routes (evidence: `carla_env/envs/carla_route_env.py`)
- Route environment → Environment wrappers: uses sensors (evidence: `carla_env/envs/carla_route_env.py`)
- Route environment → HUD: updates display (evidence: `carla_env/envs/carla_route_env.py`)
- Birdview environment → Route planning: uses routes (evidence: `carla_env/envs/birdview_env.py`)
- Birdview environment → Environment wrappers: uses sensors (evidence: `carla_env/envs/birdview_env.py`)
- Manual collection → HUD: updates display (evidence: `carla_env/envs/collect_data_manual_env.py`)
- Manual collection → Environment wrappers: uses sensors (evidence: `carla_env/envs/collect_data_manual_env.py`)
- RL collection → Route planning: uses routes (evidence: `carla_env/envs/collect_data_rl_env.py`)
- RL collection → State encoding: encodes observations (evidence: `carla_env/envs/collect_data_rl_env.py`)
- RL collection → Reward functions: computes reward (evidence: `carla_env/envs/collect_data_rl_env.py`)
- RL collection → Experiment configuration: reads settings (evidence: `carla_env/envs/collect_data_rl_env.py`)
- RL collection → HUD: updates display (evidence: `carla_env/envs/collect_data_rl_env.py`)
- Route planning → Global route planner: builds global route (evidence: `carla_env/navigation/planner.py`)
- Route planning → Planner map access: creates map access (evidence: `carla_env/navigation/planner.py`)
- Route planning → Local planner: uses road options (evidence: `carla_env/navigation/planner.py`)
- Local planner → Vehicle controller: delegates control (evidence: `carla_env/navigation/local_planner.py`)
- Training workflow → State encoding: configures observations (evidence: `train.py`)
- Training workflow → Reward functions: configures rewards (evidence: `train.py`)
- Evaluation workflow → State encoding: configures observations (evidence: `eval.py`)
- Evaluation workflow → Reward functions: configures rewards (evidence: `eval.py`)
- Training workflow → RL utilities: uses callbacks (evidence: `train.py`)
- Evaluation workflow → Evaluation plots: generates plots (evidence: `eval.py`)
- State encoding → VAE model: encodes images (evidence: `carla_env/state_commons.py`)
- State encoding → VAE utilities: uses transforms (evidence: `carla_env/state_commons.py`)
- VAE training → VAE model: trains model (evidence: `vae/train_vae.py`)
- VAE training → VAE learning: uses learning routines (evidence: `vae/train_vae.py`)
- VAE training → Image loaders: loads images (evidence: `vae/train_vae.py`)
- VAE training → VAE utilities: uses utilities (evidence: `vae/train_vae.py`)
- User → VAE training: starts VAE training (evidence: `README.md`)
- User → Manual collection: collects images (evidence: `README.md`)
- User → RL collection: collects images (evidence: `README.md`)
