1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166 | # Forest Navigating UAV
Safe UAV navigation in randomized forest environments using reinforcement learning.
This repository combines:
- A fast in-memory Gymnasium simulator for scalable SAC training
- A Gazebo + ROS2 backend for rollout/demo transfer
- A configurable forest world generator with reproducible seeds
## Highlights
- SAC training pipeline with Stable-Baselines3
- Built-in safety shield (command clamping near obstacles/boundaries)
- Offline metrics + plotting (single-run and multi-run reports)
- Trajectory visualization with per-episode diagnostics
- Reproducible world generation (`world.sdf`, `meta.json`, `preview.png`)
## Repository Structure
```text
.
├── configs/ # training/sim/eval/worldgen YAML configs
├── scripts/
│ ├── rl/ # train, Gazebo bridge, plotting wrappers
│ └── worldgen/ # world generation + UAV spawn scripts
├── src/
│ ├── fastsim_forest_nav/ # simulator envs + safety logic
│ └── forest_nav_rl/ # train/eval/visualization modules
├── worldgen/ # forest_worldgen package
├── models/drones/uav_simple/ # Gazebo UAV model
└── outputs/runs/ # checkpoints, logs, eval, reports
```
## Requirements
- Linux
- Python 3.10+
- Optional GPU for faster training (`DEVICE=cuda`)
- Gazebo (`gz sim`) + ROS2 (for Gazebo rollouts)
Python dependencies are in `requirements.txt`.
## Setup
### Recommended
```bash
make setup
```
### Manual
```bash
python3 -m venv .venv
./.venv/bin/python -m pip install --upgrade pip
./.venv/bin/pip install -r requirements.txt
./.venv/bin/pip install -e worldgen -e src/fastsim_forest_nav -e src/forest_nav_rl
```
### Verify
```bash
make verify
```
## Quickstart
Generate a world:
```bash
make worldgen
```
Generate + run world in Gazebo:
```bash
make gazebo-world WORLD_CONFIG=configs/worldgen/worldgen_run.yaml WORLD_SEED=42
```
Spawn UAV in the running world:
```bash
make gazebo-spawn-uav
```
## Training (FastSim)
Train with default config:
```bash
make rl-train
```
Train with explicit config/device:
```bash
make rl-train RL_CONFIG=configs/training/sac.yaml DEVICE=cuda
```
Resume a run:
```bash
make rl-resume RUN=outputs/runs/<run_name> RESUME_CONFIG=configs/training/sac_hybrid_stage1.yaml DEVICE=cuda
```
Important:
- Training is supported in `fastsim`
- Gazebo backend is for demo/rollout evaluation
## Evaluation
Evaluate a trained model:
```bash
make rl-eval MODEL=outputs/runs/<run_name>/best/best_model.zip NUM_EPISODES=20 DEVICE=cpu
```
Metrics are written to:
- `<model_dir>/eval/eval_summary.json`
## Visualization
Launch TensorBoard:
```bash
make rl-tensorboard TB_PORT=6006
```
Generate trajectory plots:
```bash
make rl-trajectories MODEL=outputs/runs/<run_name>/best/best_model.zip NUM_EPISODES=5 DEVICE=cpu
```
## Output Artifacts
Each run under `outputs/runs/<run_name>/` typically contains:
- `best/` -> best checkpoint (`best_model.zip`)
- `final/` -> final model + summary (`sac_final_model.zip`, `training_summary.yaml`)
- `eval/` -> periodic eval data (`evaluations.npz`) and eval JSON summaries
- `monitors/` -> per-episode monitor CSVs
- `tb/` -> TensorBoard event files
- `report/` -> generated plots and CSV summaries
## Useful Make Targets
```bash
make clean # remove generated caches/artifacts
```
## Troubleshooting
- Moved repo path / stale venv:
- Run `make venv-rebuild`
- `MODEL is required` errors:
- Pass `MODEL=outputs/runs/.../best/best_model.zip`
- Gazebo topics not flowing (`/model/uav1/odometry`, `/scan`):
- Ensure Gazebo world is running and UAV is spawned before `make gazebo-agent`
- Gazebo eval debugging data:
- Each `make gazebo-agent ...` run stores telemetry under `outputs/debug/gazebo_evals/<timestamp>/`
- UAV state stream: `uav_odom.yaml` (position, orientation, linear/angular velocity)
- Command stream: `uav_cmd_vel.yaml`
- Run metadata and paths: `run_meta.txt`
- CPU-only machine:
- Set `DEVICE=cpu` for `rl-train`, `rl-eval`, and `rl-trajectories`
|