A comprehensive web-based demonstration of Crazyflie swarm control capabilities, designed to showcase first-week responsibilities for IMRCLab. Features a mock simulator with a clean migration path to production Crazyswarm2/ROS 2 integration.
# Backend (Mock Simulator) - Easy startup
cd backend
./start.sh
# Frontend (in new terminal)
cd frontend
python3 -m http.server 3000
# Open http://localhost:3000Alternative Backend Setup:
# Manual setup if start.sh doesn't work
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port 8000# Build and run backend
docker build -t crazyflie-demo .
docker run -p 8000:8000 -e BACKEND=mock crazyflie-demo
# Serve frontend
cd frontend && python3 -m http.server 3000- Backend: https://crazyflie-demo.railway.app
- Frontend: https://your-username.github.io/crazyflie-demo
Modern Color Scheme:
- Primary: Teal/Cyan gradient (#0ea5e9 to #06b6d4)
- Accent: Complementary blues and greens
- Background: Light sky blue (#f0f9ff)
- UI Elements: Consistent teal theming throughout
Visual Design:
- Clean, modern interface inspired by current design trends
- Responsive layout that works on desktop and mobile
- Smooth animations and hover effects
- Professional color palette suitable for technical demonstrations
- Multi-drone Management: Create, control, and monitor drone swarms
- Real-time Physics: 20Hz simulation with battery drain and sensor noise
- Formation Control: Line, circle, grid, and V-shape formations
- Collision Avoidance: Path planning with obstacle detection
- Emergency Systems: Immediate stop and safety protocols
- Circular Formation: Coordinated circular flight patterns
- Figure-8 Trajectory: Complex path following
- Takeoff-Hover-Land: Basic flight sequence automation
- Custom Scenarios: Extensible experiment framework
- Data Logging: Complete trajectory and telemetry capture
- ARM Toolchain Setup: Automated GCC installation
- Firmware Building: Custom PID configurations
- Flashing Tools: USB and radio deployment
- Configuration Management: Aggressive vs. smooth flight modes
- Troubleshooting Guides: Comprehensive debugging support
- Path Planning: Collision avoidance algorithm testing
- State Machine: Drone behavior validation
- Performance Metrics: Path length, separation, timing analysis
- Unit Tests: Comprehensive test coverage
- Integration Testing: End-to-end system validation
All write operations require a Bearer token:
Authorization: Bearer demo-tokenPOST /drones/create
Content-Type: application/json
{
"count": 4
}
Response:
{
"runId": "run_20231201_143022",
"drones": ["d1", "d2", "d3", "d4"]
}# Takeoff
POST /drones/d1/takeoff
{
"height": 0.6,
"duration": 2.0
}
# Move to Position
POST /drones/d1/goto
{
"x": 1.0,
"y": 0.0,
"z": 0.6,
"speed": 0.5
}
# Land
POST /drones/d1/land
# Get State
GET /drones/d1/state# Set Formation
POST /swarm/formation
{
"formation": "circle",
"parameters": {"radius": 1.0, "height": 0.6}
}
# Emergency Stop
POST /emergency/stop
# Reset Simulation
DELETE /dronesPOST /experiments/run
{
"scenario": "circular_formation",
"numDrones": 4,
"duration": 30,
"parameters": {"radius": 1.0, "height": 0.5}
}# Get Logs (JSON)
GET /logs?runId=run_20231201_143022&format=json
# Get Logs (CSV)
GET /logs?runId=run_20231201_143022&format=csv┌─────────────────────────────────────────────────────────────┐
│ Frontend (Web UI) │
│ Three.js Visualization │ Control Panel │ Charts & Results │
└─────────────────────────────────────────────────────────────┘
│
│ HTTP/REST API
│
┌─────────────────────────────────────────────────────────────┐
│ Backend (FastAPI) │
│ REST API │ Simulator Layer │ Algorithm Layer │ Database │
└─────────────────────────────────────────────────────────────┘
│
│ Configuration Switch
│
┌─────────────────────────────────────────────────────────────┐
│ Simulator Backends │
│ Phase 1: Mock Simulator │ Phase 2: ROS 2 Integration │
│ • Pure Python │ • Crazyswarm2 Adapter │
│ • 20Hz Physics Loop │ • ROS 2 Services/Actions │
│ • SQLite Logging │ • Real Hardware Control │
└─────────────────────────────────────────────────────────────┘
- Backend: FastAPI with pure Python physics simulation
- Frontend: Three.js 3D visualization with real-time updates
- Database: SQLite for trajectory logging
- Deployment: Railway + GitHub Pages
- Backend: Same FastAPI with ROS 2 adapter
- Hardware: Real Crazyflie drones via Crazyswarm2
- Simulation: Optional Gazebo integration
- Migration: Single environment variable switch
# Set environment variable
export BACKEND=crazyswarm2
# Install ROS 2 dependencies
sudo apt install ros-humble-desktop
pip install cflib crazyflie-lib-python
# Deploy with same API
uvicorn main:app --host 0.0.0.0 --port 8000See docs/MIGRATION_TO_ROS2.md for:
- Complete ROS 2 Humble installation
- Crazyswarm2 setup and configuration
- Hardware preparation and firmware flashing
- Production deployment strategies
- Workspace Bounds: 2×2×1 meter safe zone
- Speed Limits: 1.0 m/s maximum velocity
- Emergency Stop: Immediate motion cancellation
- Rate Limiting: Prevents command flooding
- Battery Monitoring: Automatic low-battery handling
- Input Validation: All parameters bounds-checked
- Error Handling: Graceful failure modes
- State Management: Consistent drone state tracking
- Collision Detection: Maintains safe separation distances
- Tick Rate: 20Hz (50ms intervals)
- Update Rate: 10Hz client polling
- Memory Usage: ~50MB for 10 drones
- CPU Usage: ~10% on modern hardware
- API Response Time: <100ms typical
- Concurrent Users: 100+ (stateless design)
- Data Export: CSV/JSON generation <1s
- Max Drones: 10 (configurable)
- Database Size: ~1MB per hour of simulation
- Horizontal Scaling: Load balancer ready
cd backend
python -m pytest tests/ -v# Test complete system
python -m pytest tests/test_system.py::TestIntegration -v# Test API endpoints
curl -H "Authorization: Bearer demo-token" \
http://localhost:8000/health
# Test frontend
open http://localhost:3000- Backend: Railway (containerized)
- Frontend: GitHub Pages (static)
- Database: SQLite (embedded)
- Monitoring: Health check endpoints
# Backend
cd backend
uvicorn main:app --reload
# Frontend
cd frontend
python3 -m http.server 3000# Build image
docker build -t crazyflie-demo .
# Run container
docker run -p 8000:8000 \
-e BACKEND=mock \
-e BEARER_TOKEN=your-token \
crazyflie-democrazyflie-swarm-demo/
├── backend/ # FastAPI backend
│ ├── main.py # Main application
│ ├── simulators/ # Simulator implementations
│ │ ├── mock_simulator.py # Pure Python simulator
│ │ └── ros2_simulator.py # ROS 2 adapter
│ ├── algorithms/ # Path planning algorithms
│ │ └── trajectory_planner.py
│ ├── tests/ # Unit tests
│ └── requirements.txt # Python dependencies
├── frontend/ # Web frontend
│ ├── index.html # Main HTML page
│ ├── js/ # JavaScript modules
│ │ ├── api.js # API client
│ │ ├── visualization.js # Three.js visualization
│ │ ├── experiments.js # Experiment management
│ │ └── app.js # Main application
│ └── css/
│ └── style.css # Styling
├── firmware/ # Firmware build tools
│ ├── setup.sh # ARM toolchain setup
│ ├── build.sh # Firmware build
│ ├── flash.sh # Firmware flashing
│ └── configs/ # PID configurations
├── docs/ # Documentation
│ ├── ARCHITECTURE.md # System architecture
│ ├── DEPLOYMENT.md # Deployment guide
│ └── MIGRATION_TO_ROS2.md # ROS 2 migration
├── Dockerfile # Container configuration
└── README.md # This file
BACKEND=mock # Simulator backend
LOG_LEVEL=info # Logging level
MAX_DRONES=10 # Maximum drone count
SIMULATION_SPEED=1.0 # Simulation speed multiplier
BEARER_TOKEN=demo-token # API authentication token// frontend/js/api.js
const API_BASE_URL = location.hostname === 'localhost'
? 'http://localhost:8000'
: 'https://your-app.railway.app';-
Connection Problems
# Check backend health curl http://localhost:8000/health # Check CORS settings curl -H "Origin: http://localhost:3000" \ -H "Access-Control-Request-Method: POST" \ -X OPTIONS http://localhost:8000/drones/create
-
Performance Issues
# Reduce simulation load export MAX_DRONES=5 export SIMULATION_SPEED=0.5
-
Memory Issues
# Monitor memory usage docker stats # Clear old data curl -X DELETE http://localhost:8000/drones
- Backend Logs: FastAPI automatic logging
- Browser Console: JavaScript error tracking
- Network Tab: API request/response inspection
- Database: SQLite browser for data inspection
- Machine Learning: Neural network path planning
- Computer Vision: Obstacle detection and avoidance
- Advanced Formations: Dynamic formations, leader-follower
- Multi-Agent: Distributed decision making
- Microservices: Split into specialized services
- Message Queues: Redis/RabbitMQ for async processing
- Distributed Simulation: Multiple simulation nodes
- Real-time Analytics: Stream processing with Apache Kafka
This is a demonstration project showcasing first-week capabilities for IMRCLab. The architecture is designed to be easily extensible for production use with real Crazyflie drones.
- Follow PEP 8 for Python code
- Use meaningful commit messages
- Add tests for new features
- Update documentation for API changes
- Python: Black formatter, type hints
- JavaScript: ESLint, Prettier
- Documentation: Markdown, clear examples
This project is designed as a demonstration for IMRCLab interview purposes. Please refer to individual component licenses for production use.
- Bitcraze: Crazyflie hardware and firmware
- USC ACTLab: Crazyswarm2 framework
- FastAPI: Modern Python web framework
- Three.js: 3D visualization library
- Railway: Deployment platform
Built overnight to demonstrate understanding and initiative
Architecture mirrors Crazyswarm2 and ROS 2 patterns
Backend swap is a config flip; UI and contract remain stable
Covers 60-20-10-10 responsibilities end-to-end
Clear week-one plan to extend to real drones