project overview - MrTibbz2/CaveBot GitHub Wiki
This robotics project implements an autonomous navigation system using multiple components working together to provide real-time sensor data collection, processing, and robot control. The system combines embedded firmware, serial communication, web-based visualization, and robot movement control.
- Real-time sensor data collection using 8 HC-SR04 ultrasonic sensors
- Dual-core processing on Raspberry Pi Pico for concurrent operations
- Web-based simulation and mapping interface with live data visualization
- Robot movement control via LEGO Spike Prime with PyBricks
- Structured communication protocols for reliable data exchange
- Comprehensive testing framework for all system components
- Raspberry Pi Pico (RP2040): Dual-core ARM Cortex-M0+ microcontroller
- C++: Firmware development with Pico SDK
- CMake + Ninja: Build system for cross-compilation
- ARM GNU Toolchain: Cross-compiler for ARM architecture
- Python: Serial interface and system integration
- PySerial: USB serial communication library
- JSON: Structured message format for data exchange
- WebSockets: Real-time web communication
- FastAPI: Modern Python web framework
- HTMX: Dynamic web interactions
- Tailwind CSS: Utility-first CSS framework
- JavaScript Canvas: 2D graphics and mapping
- Turtle Graphics: Robot simulation
- PyBricks: Python framework for LEGO robotics
- Bluetooth LE: Wireless communication to robot
- LEGO Spike Prime: Educational robotics platform
Purpose: Sensor data collection and real-time processing
Key Features:
- Dual-core architecture (Core0: commands, Core1: sensors)
- 8-sensor HC-SR04 ultrasonic distance measurement
- Structured JSON output format
- Command-based operation (START/STOP/STATUS)
- Thread management and error handling
Communication Protocol:
Format: <IDENTIFIER>: { "type": "<TYPE>", "status": "<STATUS>", "payload": {<DATA>} }
Commands: CMD_START_SENSORREAD, CMD_STOP, CMD_STATUS
Purpose: Bridge between Pico and web interface
Key Features:
- Automatic Pico device detection
- Threaded serial data reading
- JSON message parsing and validation
- WebSocket data forwarding
- Connection management and error recovery
Data Flow:
Pico (USB Serial) → RPI (Parser) → Web UI (WebSocket)
Purpose: Visualization, simulation, and system control
Key Features:
- Real-time sensor data visualization
- Robot simulation with turtle graphics
- 2D mapping interface
- WebSocket communication
- Interactive controls for robot movement
Technologies:
- FastAPI backend with WebSocket support
- HTML/CSS/JavaScript frontend
- Canvas-based mapping and visualization
Purpose: Physical robot movement and motor control
Key Features:
- Bluetooth LE communication
- PyBricks-based motor control
- Movement commands (forward, backward, turn)
- Status monitoring and error handling
API:
prime = Prime("HUB_NAME")
prime.moveForward(100) # Move 100cm forward
prime.turnLeft(90) # Turn 90 degrees left
- Windows 10/11 development environment
- Python 3.8+ with pip
- CMake and Ninja build tools
- ARM GNU Toolchain for cross-compilation
- Visual Studio Code with extensions
- Pico Firmware: CMake build system with Pico SDK
- Python Components: Direct execution with dependency management
- Web UI: FastAPI development server
- Spike Prime: PyBricks code upload via web interface
# Pico toolchain
choco install ninja cmake
# Download ARM GNU Toolchain from ARM Developer
# Python dependencies
pip install fastapi uvicorn jinja2 websockets pyserial bleak
# Build Pico firmware
cd microcontrollers && mkdir build && cd build
cmake .. && make
{
"identifier": "Core1|Command|INFO|ERROR",
"type": "data_stream|thread_status|system_status",
"status": "active|success|ready|failure",
"payload": { "sensor_data": [...] }
}
{
"type": "data_stream|log",
"subtype": "distance_read|pico_info",
"timestamp": "2025-01-01T12:00:00Z",
"payload": { "sensor_leftfront": 150.2 }
}
Front
↑
[FL] [FR] ← frontleft, frontright (0° from heading)
[LF] [RF] ← leftfront, rightfront (90°, 270°)
[LB] [RB] ← leftback, rightback (90°, 270°)
[BL] [BR] ← backleft, backright (180°)
↓
Back
- GP2-GP3: Front Left sensor (Trigger/Echo)
- GP4-GP5: Front Right sensor
- GP6-GP7: Left Front sensor
- GP8-GP9: Left Back sensor
- GP10-GP11: Right Front sensor
- GP12-GP13: Right Back sensor
- GP14-GP15: Back Left sensor
- GP16-GP17: Back Right sensor
tests/
├── test_ui_simulation.py # UI and simulation tests
├── test_rpi_serial.py # Serial communication tests
├── test_spikeprime_commands.py # Robot control tests
├── test_integration.py # End-to-end system tests
└── run_tests.py # Test runner
- Unit Tests: Individual component functionality
- Integration Tests: Inter-component communication
- Mock Tests: Hardware simulation for CI/CD
- Hardware-in-Loop: Real hardware validation
- ✅ Pico firmware with sensor reading
- ✅ RPI serial interface
- ✅ Web UI with simulation
- ✅ Spike Prime control API
- ✅ Communication protocols
- ✅ Testing framework
- ✅ Documentation
- System Integration: End-to-end testing with all components
- Mapping Algorithm: 2D SLAM implementation
- Navigation Logic: Path planning and obstacle avoidance
- Performance Optimization: Real-time processing improvements
- Error Recovery: Robust failure handling
- Machine learning for improved navigation
- Multi-robot coordination
- Advanced mapping algorithms (occupancy grids)
- Mobile app interface
- Cloud data logging and analysis
- Hardware Setup: Follow Hardware Guide
- Software Installation: Follow Setup Guide
- System Testing: Use Testing Guide
- API Integration: Reference API Documentation
- Architecture Understanding: Review System Architecture
- Check individual component documentation for specific issues
- Use test framework to isolate problems
- Monitor serial output for debugging information
- Verify hardware connections and power supply
- Ensure all dependencies are properly installed