A backend service for spatial path planning and optimization, designed to compute efficient traversal trajectories over 2D surfaces with obstacle constraints. The system applies coverage planning, A* search, and genetic optimization techniques to generate optimized paths, exposed via APIs for interactive and programmatic clients.
- Features
- Technology Stack
- System Architecture
- Quick Start
- Detailed Setup
- API Documentation
- Algorithm Overview
- Usage Examples
- Development
- Testing
- Troubleshooting
-
Multiple Path Planning Algorithms
- Boustrophedon Coverage (lawn-mower pattern)
- A* Pathfinding (shortest path)
- Genetic Algorithm (optimization)
- Hybrid approach (combines all three)
-
Complex Obstacle Support
- Rectangles (windows, doors, panels)
- Circles (outlets, pipes)
- Polygons (custom shapes)
-
Real-time Visualization
- HTML5 Canvas-based 2D trajectory viewer
- Interactive obstacle editor
- Live path visualization
-
Performance Optimization
- Redis caching for path results
- PostgreSQL for persistent storage
-
RESTful API
- Auto-generated Swagger documentation
- WebSocket support for real-time updates
- Comprehensive metrics and analytics
| Component | Technology | Purpose |
|---|---|---|
| Backend | FastAPI + Python 3.11 | High-performance async API |
| Database | PostgreSQL 15 | Relational data storage |
| Cache | Redis 7 | Path caching & pub/sub |
| Frontend | Vanilla JS + HTML5 Canvas | Interactive UI |
| Algorithms | NumPy + SciPy + Shapely | Path planning logic |
| Deployment | Docker + Docker Compose | Containerized services |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER INTERFACE β
β (HTML5 Canvas + JavaScript) β
β http://localhost:3000 β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β HTTP/REST + WebSocket
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BACKEND API (FastAPI) β
β http://localhost:8000/docs β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β API Endpoints: /walls, /obstacles, /paths, /metrics β
β Services: Wall, Path Planning, Metrics β
β Algorithms: Coverage, A*, Genetic, Hybrid β
βββββ¬ββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββ ββββββββββββ
βPostgreSQLβ β Redis β
β Port:5432β β Port:6379β
ββββββββββββ ββββββββββββ
- Docker Desktop installed
- At least 4GB RAM available
- Ports 3000, 5432, 6379, 8000 available
# Clone the repository
cd wall-finishing-rcs
# Start all services
make up- Frontend UI: http://localhost:3000
- API Documentation: http://localhost:8000/docs
make seedThis creates:
- 2 sample walls
- 5 obstacles
- 1 sample trajectory
- Open http://localhost:3000
- Create a new wall or select an existing one
- Add obstacles (windows, outlets, etc.)
- Click "Plan Path" to generate trajectory
- View the optimized path on the canvas
# Build all Docker images
make build
# Start services
make up
# View logs
make logs
# Stop services
make down
# Clean everything (including volumes)
make cleancd backend
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Start PostgreSQL and Redis locally (on default ports)
# Run migrations
alembic upgrade head
# Start server
uvicorn app.main:app --reloadcd frontend
# Install dependencies
npm install
# Start dev server
npm run devOnce the backend is running, visit http://localhost:8000/docs for interactive API documentation.
# Create wall
POST /walls/
{
"name": "Living Room Wall",
"width": 5.0,
"height": 3.0,
"surface_type": "drywall"
}
# Get all walls
GET /walls/
# Get specific wall
GET /walls/{wall_id}# Add rectangle obstacle
POST /walls/{wall_id}/obstacles
{
"obstacle_type": "rectangle",
"x": 1.0,
"y": 1.0,
"width": 1.2,
"height": 0.8,
"name": "Window"
}
# Add circle obstacle
POST /walls/{wall_id}/obstacles
{
"obstacle_type": "circle",
"x": 4.0,
"y": 1.5,
"radius": 0.15,
"name": "Outlet"
}# Plan path
POST /paths/plan
{
"wall_id": 1,
"algorithm_type": "hybrid",
"parameters": {
"grid_resolution": 0.1,
"population_size": 50,
"generations": 30
}
}
# Get trajectory
GET /paths/trajectories/{trajectory_id}Simple lawn-mower pattern that guarantees full coverage.
Pros: Fast, predictable, guaranteed coverage Cons: May not be the most efficient
Finds shortest path between two points while avoiding obstacles.
Pros: Optimal shortest path, very fast Cons: Doesn't ensure full coverage
Evolutionary optimization to find the best path order.
Pros: Can find very optimal solutions Cons: Slower, results may vary
Combines all three:
- Coverage planner generates full coverage
- A* connects disconnected sections
- Genetic algorithm optimizes the order
Best for: Most real-world scenarios
import requests
API = "http://localhost:8000"
# Create wall
wall = requests.post(f"{API}/walls/", json={
"name": "Bedroom Wall",
"width": 4.0,
"height": 2.8
}).json()
# Add window obstacle
obstacle = requests.post(f"{API}/walls/{wall['id']}/obstacles", json={
"obstacle_type": "rectangle",
"x": 1.5,
"y": 1.0,
"width": 1.2,
"height": 1.0,
"name": "Window"
}).json()
# Plan path
trajectory = requests.post(f"{API}/paths/plan", json={
"wall_id": wall['id'],
"algorithm_type": "hybrid"
}).json()
print(f"Path planned with {len(trajectory['waypoints'])} waypoints")
print(f"Total distance: {trajectory['total_distance']:.2f} meters")
print(f"Coverage: {trajectory['coverage_percentage']:.1f}%")See scripts/seed_data.py for a complete example.
wall-finishing-rcs/
βββ backend/
β βββ app/
β β βββ algorithms/ # Path planning algorithms
β β βββ api/ # API endpoints
β β βββ models/ # Database models
β β βββ schemas/ # Pydantic schemas
β β βββ services/ # Business logic
β β βββ cache/ # Redis client
β βββ tests/ # Unit & integration tests
βββ frontend/
β βββ src/
β βββ components/ # UI components
β βββ styles/ # CSS styles
βββ scripts/ # Utility scripts
βββ docker-compose.yml # Service orchestration
# Run all tests
make test
# Run specific test file
docker-compose exec backend pytest tests/test_algorithms.py -v
# Run with coverage
docker-compose exec backend pytest --cov=app --cov-report=html- Create
backend/app/algorithms/my_algorithm.py - Implement the algorithm class
- Register in
backend/app/algorithms/__init__.py - Add to
AlgorithmTypeenum inmodels/trajectory.py - Update
path_service.pyto handle the new type
curl -X POST http://localhost:8000/walls/ \
-H "Content-Type: application/json" \
-d '{
"name": "Test Wall",
"width": 5.0,
"height": 3.0
}'curl -X POST http://localhost:8000/paths/plan \
-H "Content-Type: application/json" \
-d '{
"wall_id": 1,
"algorithm_type": "hybrid"
}'# Find and kill process using port 8000
lsof -ti:8000 | xargs kill -9
# Or change port in docker-compose.yml# Restart PostgreSQL container
docker-compose restart postgres
# Check if database is ready
docker-compose exec postgres pg_isready -U robot# Restart Redis container
docker-compose restart redis
# Test Redis connection
docker-compose exec redis redis-cli ping# Rebuild frontend
cd frontend
npm install
npm run devmake clean
make build
make up
make seed-
Adjust Grid Resolution: Lower resolution = faster planning but less precision
{ "parameters": { "grid_resolution": 0.05 // 5cm (default: 0.1m) } } -
Tune Genetic Algorithm: Reduce population/generations for faster results
{ "parameters": { "population_size": 30, // default: 50 "generations": 20 // default: 30 } } -
Use Coverage for Simple Walls: Fastest algorithm for walls without obstacles
{ "algorithm_type": "coverage" }