# MaUWB ESP32-S3 Positioning System

Ultra-wideband (UWB) positioning system using ESP32-S3 and Makerfabs UWB modules for indoor positioning and warehouse mapping applications.

![Working MaUWB Devices](docs/images/20250819_202527.jpg)

## Features
- ESP32-S3 based anchor and tag devices
- Real-time distance measurement with <10cm accuracy
- OLED display for status and measurements
- Multiple tag support (up to 64 tags)
- 6.8Mbps communication rate
- Complete AT command implementation
- Position calculation with trilateration
- Anchor auto-positioning system
- Real-time positioning with USB data logging

![MaUWB Modules](docs/images/20250819_202629.jpg)

**Hardware:** [Makerfabs MaUWB ESP32-S3 UWB Module](https://www.makerfabs.com/mauwb-esp32s3-uwb-module.html) with SSD1306 OLED displays

## Unified Architecture

**Single Firmware** - All devices use the same `main.cpp` with config-driven behavior:
- `anchor`: Base station with distributed positioning framework (default: ID=0, Network=1234)
- `tag`: Mobile tracker with coordinate collection (default: ID=1, Network=1234)
- `debug`: Development build with debug output enabled

## Build & Upload
```bash
# Build with default settings
pio run -e anchor    # Anchor ID=0, Network=1234
pio run -e tag       # Tag ID=1, Network=1234

# Build with custom device ID and network
set PLATFORMIO_BUILD_FLAGS=-DUWB_INDEX=5 -DNETWORK_ID=2000
pio run -e anchor    # Anchor ID=5, Network=2000

# Upload to device
pio run -e tag -t upload

# Monitor serial output
pio device monitor
```

## Project Structure

### Modular Configuration System
- `src/main.cpp` - Single unified firmware for all device types
- `src/config/` - Device behavior configuration
  - `config.h` - Hardware pins and system settings
  - `device_config.h` - Device role detection and unified behavior
  - `anchor_config.h` - Anchor-specific settings (positioning, inter-anchor communication)
  - `tag_config.h` - Tag-specific settings (USB streaming, coordinate collection)
  - `positioning_config.h` - Distributed positioning algorithm parameters
- `lib/UWBHelper/` - Complete UWB AT command library with positioning support
- `platformio.ini` - Simplified build environments (3 instead of 8+)

## AT Command Support

Complete implementation of all AT commands from the official manual:

### Basic Commands
- `AT?` - Test connection
- `AT+GETVER?` - Get firmware version
- `AT+RESTART` - Restart module
- `AT+RESTORE` - Factory reset
- `AT+SAVE` - Save configuration

### Configuration
- `AT+SETCFG` / `AT+GETCFG?` - Device configuration
- `AT+SETANT` / `AT+GETANT?` - Antenna delay calibration
- `AT+SETCAP` / `AT+GETCAP?` - System capacity settings
- `AT+SETRPT` / `AT+GETRPT?` - Auto-reporting control

### Network & Power
- `AT+SETPAN` / `AT+GETPAN?` - Network ID configuration
- `AT+SETPOW` / `AT+GETPOW?` - Transmission power control
- `AT+SLEEP` - Sleep mode for battery conservation

### Data Communication
- `AT+DATA` / `AT+RDATA` - Custom data transmission
- Real-time range reporting via `AT+RANGE` parsing

## Library Features

The enhanced UWBHelper library provides:
- **Complete AT command coverage**
- **Advanced range data parsing** for multiple anchors
- **Position calculation algorithms** (trilateration, multilateration)
- **Anchor position management** for auto-positioning
- **Distance filtering** for improved accuracy
- **Backward compatibility** with existing code

## Configuration
- **Network ID**: 1234 (configurable via AT+SETPAN)
- **Baud Rate**: 115200
- **Communication**: 6.8Mbps (AT+SETCFG parameter)
- **Range filtering**: Enabled for accuracy
- **Refresh Rate**: 10Hz (configurable via AT+SETCAP)
- **Max Anchors**: Unlimited (tags connect to 8 closest)
- **Max Tags**: 64 per network


## Documentation

- [AT Command Manual](docs/manuals/Makerfabs%20UWB%20AT%20Module%20AT%20Command%20Manual(v1.1.1).pdf) - Complete AT command reference
- [Hardware Product Page](https://www.makerfabs.com/mauwb-esp32s3-uwb-module.html) - Official hardware documentation
- [Project Roadmap](docs/ROADMAP.md) - Development plan for indoor positioning system

## Applications

This system is designed for:
- **Indoor positioning** in warehouses and large buildings
- **Asset tracking** and inventory management
- **Navigation assistance** in GPS-denied environments
- **WiFi signal mapping** and coverage analysis
- **Research and development** in UWB positioning
