Metadata-Version: 2.5
Name: CarlaBEV
Version: 0.9.0
Summary: Bird's-eye-view Gymnasium simulator for autonomous-driving RL research
Project-URL: Homepage, https://github.com/danielmtzbarba/carlabev-env
Project-URL: Repository, https://github.com/danielmtzbarba/carlabev-env
Project-URL: Documentation, https://github.com/danielmtzbarba/carlabev-env/tree/main/CarlaBEV/docs
Project-URL: Issues, https://github.com/danielmtzbarba/carlabev-env/issues
License-File: CarlaBEV/assets/Town01/NOTICE
License-File: LICENSE.md
License-File: LICENSES/PythonRobotics-MIT.txt
Requires-Python: >=3.12
Requires-Dist: gymnasium
Requires-Dist: loguru>=0.7.3
Requires-Dist: matplotlib
Requires-Dist: moviepy>=2.2.1
Requires-Dist: networkx
Requires-Dist: numpy
Requires-Dist: opencv-python
Requires-Dist: pandas
Requires-Dist: pillow
Requires-Dist: plotly>=6.8.0
Requires-Dist: pydantic>=2
Requires-Dist: pygame>=2.1.3
Requires-Dist: rich
Requires-Dist: scipy
Requires-Dist: tyro
Description-Content-Type: text/markdown

# CarlaBEV

A lightweight bird’s-eye-view driving simulator for reinforcement-learning research, with a Gymnasium API, procedural traffic, and repeatable scenarios on Town01. It uses simplified vehicle dynamics for fast experimentation.

![CarlaBEV random traffic rendered at 512 × 512](https://raw.githubusercontent.com/danielmtzbarba/carlabev-env/main/CarlaBEV/assets/images/carlabev-sim-512.png)

*Random Town01 traffic, rendered at 512 × 512: ego in cyan, traffic in blue, and route checkpoints in green.*

## Install and run

Requires Python 3.12 or newer. Once the first PyPI release is available, install it in your Python environment:

```bash
python -m pip install carlabev
carlabev run sim --size 512
```

In the meantime, you can install the current GitHub version with pip:

```bash
python -m pip install "carlabev @ git+https://github.com/danielmtzbarba/carlabev-env.git"
```

For development, use a checkout and [uv](https://docs.astral.sh/uv/):

```bash
git clone https://github.com/danielmtzbarba/carlabev-env.git
cd carlabev-env
uv sync
bash scripts/setup-hooks.sh
```

The pre-push hook checks Ruff lint, Ruff formatting, and pytest using the
locked development dependencies. GitHub Actions repeats those checks on pull
requests and pushes to `main`.

Drive with the arrow keys and press **Q** to quit. For a smoother display:

```bash
carlabev run sim --size 512 --display-fps 60
```

Run headless episodes or change traffic difficulty:

```bash
carlabev run sim --control random --episodes 5
carlabev run sim --size 512 --difficulty-preset-id hard --seed 1
```

## Settings

| Option | Purpose |
| --- | --- |
| `--size 256` or `--size 512` | Native raster resolution; the physical field of view stays the same. |
| `--control manual\|random\|idle\|forward` | Select keyboard or automatic actions. |
| `--difficulty-preset-id easy\|medium\|hard` | Choose random-scene traffic difficulty. |
| `--physics-dt 0.05` | Set physics time per substep, in seconds; default is `0.1`. |
| `--action-repeat 2` | Hold each action for two physics substeps. |
| `--seed 5` | Set the base scene seed. |
| `--record-video runs/videos` | Record episode videos. |

`--display-fps` changes presentation, and `--physics-dt` changes simulation time. Use `carlabev run sim --help` for all options. See the [configuration reference](https://github.com/danielmtzbarba/carlabev-env/blob/main/CarlaBEV/docs/config_reference.md) for Python configuration. In a development checkout, prefix CLI commands with `uv run`.

## Features

- Gymnasium environments with discrete or continuous ego actions.
- RGB and semantic BEV observations, frame stacking, and direct vector observations.
- Random traffic with car following, signals, junction yielding, and vehicle recycling.
- Authored scenes and `lead_brake`, `jaywalk`, and `red_light_runner` scenarios.
- Metric actor footprints, collision detection, and curvature-aware NPC speed control.
- Seeded scene generation, cached scene libraries, and replay validation.

## Train a DRL agent

Use CarlaBEV through Gymnasium’s `reset()` and `step()` API. The environment factory adds observation resizing, semantic masks, frame stacking, and episode statistics:

```python
from CarlaBEV.config import EnvConfig, RunConfig
from CarlaBEV.envs import make_env

envs = make_env(RunConfig(
    num_envs=8,
    env=EnvConfig(render_mode="rgb_array", obs_mode="bev_semantic"),
))
observations, info = envs.reset(seed=42)
try:
    for _ in range(1_000):
        actions = envs.action_space.sample()  # Replace with policy(observations).
        next_observations, rewards, terminated, truncated, info = envs.step(actions)
        # Store the transition and update your DRL algorithm here, before resets.
        observations = next_observations
        done = terminated | truncated
        if done.any():
            observations, info = envs.reset(options={"reset_mask": done})
finally:
    envs.close()
```

The example samples random actions; replace that line with your policy. Actions and transitions are batched across environments. Autoreset is disabled, so reset completed environments using `reset_mask`. Keep `terminated` and `truncated` separate when computing learning targets. See the [training integration contract](https://github.com/danielmtzbarba/carlabev-env/blob/main/CarlaBEV/docs/downstream_integration_api.md) for details.

## Architecture

![CarlaBEV systems and DRL interaction](https://raw.githubusercontent.com/danielmtzbarba/carlabev-env/main/CarlaBEV/assets/images/carlabev-architecture.png)

The simulation advances on an explicit clock. Rendering observes its state and does not control physics timing.

[Documentation](https://github.com/danielmtzbarba/carlabev-env/tree/main/CarlaBEV/docs) · [Python integration](https://github.com/danielmtzbarba/carlabev-env/blob/main/CarlaBEV/docs/downstream_integration_api.md) · [Scenarios](https://github.com/danielmtzbarba/carlabev-env/blob/main/CarlaBEV/docs/scenario_specifications.md) · [Diagnostics and validation](https://github.com/danielmtzbarba/carlabev-env/blob/main/CarlaBEV/docs/debugging_and_diagnostics.md)

Original software and documentation are licensed under [Apache-2.0](https://github.com/danielmtzbarba/carlabev-env/blob/main/LICENSE.md). Planning and control code adapted from [PythonRobotics](https://github.com/AtsushiSakai/PythonRobotics) retains its [MIT notice](https://github.com/danielmtzbarba/carlabev-env/blob/main/LICENSES/PythonRobotics-MIT.txt). CARLA-derived Town01 maps retain their [asset attribution and upstream terms](https://github.com/danielmtzbarba/carlabev-env/blob/main/CarlaBEV/assets/Town01/NOTICE).
