# khazit/crazyslam architecture

> Architecture diagram of the GitHub repository khazit/crazyslam, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/khazit/crazyslam
- Repository: https://github.com/khazit/crazyslam

## Overview

CrazySLAM is a Python SLAM library and Crazyflie support package. Its core workflow takes range readings and a motion update, updates an occupancy grid from the current pose, then refines the pose with a particle filter scoring sensor targets against that grid. The package also exposes keyboard control, Crazyflie discovery, and flight-data logging. The README documents the sensor and firmware context; examples are not inspected, so links from external callers into the SLAM API are left unverified.

Main entry points: [`crazyslam/slam.py`](https://github.com/khazit/crazyslam/blob/master/crazyslam/slam.py) (SLAM agent), [`crazyslam/localization.py`](https://github.com/khazit/crazyslam/blob/master/crazyslam/localization.py) (Particle filter), [`crazyslam/mapping.py`](https://github.com/khazit/crazyslam/blob/master/crazyslam/mapping.py) (Ray map update), [`crazyslam/control.py`](https://github.com/khazit/crazyslam/blob/master/crazyslam/control.py) (Keyboard control)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_slam["SLAM Core"]
  node_slam_agent["SLAM agent<br/>[slam.py]"]
  node_occupancy_grid[("Occupancy grid<br/>[mapping.py]")]
  node_ray_update["Ray map update<br/>[mapping.py]"]
  node_particle_filter["Particle filter<br/>[localization.py]"]
  node_grid_scoring["Grid scoring helpers<br/>[mapping.py]"]
end

subgraph group_integration["Flight Integration"]
  node_keyboard_control["Keyboard control<br/>[control.py]"]
  node_device_discovery["Device discovery<br/>[utils.py]"]
end

subgraph group_records["Flight Records"]
  node_flight_logger["Flight logger<br/>[logging.py]"]
  node_log_files[("Flight log files")]
end

node_operator(("Operator"))
node_crazyflie["Crazyflie"]
node_range["Range readings"]
node_motion["Motion update"]

node_operator -->|"issues commands"| node_keyboard_control
node_keyboard_control -->|"commands motion"| node_crazyflie
node_device_discovery -->|"scans interfaces"| node_crazyflie
node_crazyflie -->|"streams telemetry"| node_flight_logger
node_flight_logger -->|"writes records"| node_log_files
node_range -.->|"supplies readings"| node_slam_agent
node_motion -.->|"supplies update"| node_slam_agent
node_slam_agent -->|"updates map"| node_ray_update
node_ray_update -->|"updates cells"| node_occupancy_grid
node_slam_agent -->|"estimates state"| node_particle_filter
node_particle_filter -->|"discretizes targets"| node_grid_scoring
node_particle_filter -->|"scores particles"| node_occupancy_grid

click node_slam_agent "https://github.com/khazit/crazyslam/blob/master/crazyslam/slam.py"
click node_occupancy_grid "https://github.com/khazit/crazyslam/blob/master/crazyslam/mapping.py"
click node_ray_update "https://github.com/khazit/crazyslam/blob/master/crazyslam/mapping.py"
click node_particle_filter "https://github.com/khazit/crazyslam/blob/master/crazyslam/localization.py"
click node_grid_scoring "https://github.com/khazit/crazyslam/blob/master/crazyslam/mapping.py"
click node_keyboard_control "https://github.com/khazit/crazyslam/blob/master/crazyslam/control.py"
click node_device_discovery "https://github.com/khazit/crazyslam/blob/master/crazyslam/utils.py"
click node_flight_logger "https://github.com/khazit/crazyslam/blob/master/crazyslam/logging.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_slam_agent,node_occupancy_grid,node_ray_update,node_particle_filter,node_grid_scoring toneBlue
class node_keyboard_control,node_device_discovery toneAmber
class node_flight_logger,node_log_files toneMint
class node_operator,node_crazyflie,node_range,node_motion toneIndigo
```

## Components

### SLAM Core

- [SLAM agent](https://github.com/khazit/crazyslam/blob/master/crazyslam/slam.py): `crazyslam/slam.py`
- [Occupancy grid](https://github.com/khazit/crazyslam/blob/master/crazyslam/mapping.py): `crazyslam/mapping.py`
- [Ray map update](https://github.com/khazit/crazyslam/blob/master/crazyslam/mapping.py): `crazyslam/mapping.py`
- [Particle filter](https://github.com/khazit/crazyslam/blob/master/crazyslam/localization.py): `crazyslam/localization.py`
- [Grid scoring helpers](https://github.com/khazit/crazyslam/blob/master/crazyslam/mapping.py): `crazyslam/mapping.py`

### Flight Integration

- [Keyboard control](https://github.com/khazit/crazyslam/blob/master/crazyslam/control.py): `crazyslam/control.py`
- [Device discovery](https://github.com/khazit/crazyslam/blob/master/crazyslam/utils.py): `crazyslam/utils.py`

### Flight Records

- [Flight logger](https://github.com/khazit/crazyslam/blob/master/crazyslam/logging.py): `crazyslam/logging.py`
- **Flight log files**

### Other components

- **Operator**
- **Crazyflie**
- **Range readings**
- **Motion update**

## Connections

- Operator → Keyboard control: issues commands (evidence: `crazyslam/control.py`)
- Keyboard control → Crazyflie: commands motion (evidence: `crazyslam/control.py`)
- Device discovery → Crazyflie: scans interfaces (evidence: `crazyslam/utils.py`)
- Crazyflie → Flight logger: streams telemetry (evidence: `crazyslam/logging.py`)
- Flight logger → Flight log files: writes records (evidence: `crazyslam/logging.py`)
- Range readings → SLAM agent: supplies readings
- Motion update → SLAM agent: supplies update
- SLAM agent → Ray map update: updates map (evidence: `crazyslam/slam.py`)
- Ray map update → Occupancy grid: updates cells (evidence: `crazyslam/mapping.py`)
- SLAM agent → Particle filter: estimates state (evidence: `crazyslam/slam.py`)
- Particle filter → Grid scoring helpers: discretizes targets (evidence: `crazyslam/localization.py`)
- Particle filter → Occupancy grid: scores particles (evidence: `crazyslam/localization.py`)
