PRE-SAFE is an advanced autonomous vehicle system designed for precise self-localization and obstacle detection using multiple sensor fusion techniques. The system combines computer vision, inertial measurement, wheel odometry, and landmark-based navigation to achieve robust autonomous navigation.
PRE-SAFE implements a multi-layered localization approach that prioritizes accuracy through sensor fusion:
- AprilTag Localization (Highest Priority) - Visual marker-based positioning
- Landmark-based Localization - Eiffel Tower model detection and ranging
- Sensor-based Localization - IMU and wheel odometry fusion
The system features a full-stack architecture with a Raspberry Pi backend for sensor processing and vehicle control, paired with a modern React frontend for real-time monitoring and control.
Located in /backend/src/:
- Main Controller (
main.py) - Multi-threaded system orchestrator - Navigation System (
navigation.py) - Path planning and execution - Localization Engine (
localisation.py) - Multi-sensor position estimation - Motor Controller (
motor_controller.py) - 4-wheel drive control system - Flask API (
web.py) - RESTful API for frontend communication
Located in /frontend/src/:
- Vehicle Control Interface - Real-time vehicle operation dashboard
- 3D Visualization (
VehicleTracking3D.jsx) - Three.js-based real-time tracking - Live Camera Feed (
Camera.jsx) - Streaming video display - Position Monitoring (
Locations.jsx) - Multi-sensor position display - Authentication System (
LoginPage.jsx) - Secure access control
- AprilTag Detection (
apriltag_detection.py) - Fiducial marker recognition - Stereo Vision (
stereo_distance.py) - Dual-camera distance measurement - Monocular Distance (
mono_distance.py) - Single-camera ranging - Landmark Detection (
detect_and_crop.py) - Eiffel Tower identification
- IMU Integration (
gyroscope.py,mpu6050.py) - MPU6050-based orientation tracking - Wheel Sensors (
wheel_sensor.py) - Encoder-based odometry
- Manhattan Navigation (
manhattan_navigation.py) - Grid-based path planning - Road Network Simulation (
simulate_road_network.py) - Virtual road generation
- AprilTag System: 8cm fiducial markers with known world coordinates
- Visual Landmarks: Eiffel Tower model detection with angle classification
- Sensor Fusion: IMU + wheel odometry with drift correction
- Hierarchical Estimation: Automatic fallback between localization methods
- Manhattan Grid Navigation: Structured path planning on virtual road networks
- Real-time Path Planning: Dynamic destination setting and route calculation
- Precision Turning: IMU-guided angular control with tolerance-based stopping
- RESTful API: Flask-based backend serving sensor data and control endpoints
- Live Video Streaming: Real-time camera feed at
/video_feed - Position Tracking: JSON API for all sensor data at
/positions - Multi-threaded Architecture: Concurrent sensor processing and control
- Secure Login System: Username/password authentication for system access
- Real-time Control Panel: Intuitive directional control buttons (Forward/Backward/Left/Right)
- Live Camera Integration: Streaming video feed from vehicle cameras
- Multi-sensor Position Display: Real-time coordinates from AprilTag and wheel sensors
- Three.js Integration: Real-time 3D scene rendering with vehicle tracking
- Dual Vehicle Representation:
- Red car for AprilTag-based positioning
- Blue car for wheel sensor-based positioning
- Interactive 3D Environment: Grid-based coordinate system with landmark models
- AprilTag Visualization: Green cubes representing detected AprilTag positions
- Data Logging: CSV export functionality for position and sensor data
- Material-UI Components: Professional interface with consistent design
- Responsive Layout: Optimized for various screen sizes
- Real-time Updates: Live position updates every second
- Visual Feedback: Color-coded position indicators and status displays
- Raspberry Pi 4B (recommended) or compatible SBC
- MicroSD card (32GB+, Class 10)
- Cameras: Dual Raspberry Pi Camera modules (stereo configuration)
- IMU: MPU6050 6-axis accelerometer/gyroscope
- Wheel Encoders: Optical/magnetic encoders (20 pulses/revolution)
- Motors: 4x DC motors with H-bridge drivers
- GPIO: Motor control pins configured for 4-wheel drive
- Camera Baseline: 51mm stereo separation
- Wheel Diameter: 65mm
- AprilTag Size: 8cm (tag25h9 family)
- Test Environment: Indoor with known AprilTag positions
# Update system
sudo apt update && sudo apt upgrade -y
# Install Python dependencies
sudo apt install python3-pip python3-opencv python3-flask python3-numpy
# Install specialized libraries
pip3 install picamera2 apriltag RPi.GPIO flask-cors pillow# Enable camera interface
sudo raspi-config
# Navigate to Interface Options > Camera > Enable
# Enable I2C for IMU
sudo raspi-config
# Navigate to Interface Options > I2C > Enable
# Reboot system
sudo reboot- Camera Calibration: Run scripts in
backend/src/cam_calibration/ - IMU Calibration: System auto-calibrates on startup (2000 samples)
- AprilTag Placement: Position tags according to coordinates in
backend/src/variables.py
- Node.js 16+ and npm
- Modern web browser with WebGL support
cd frontend
npm install- React 19: Modern UI framework
- Material-UI: Professional component library
- Three.js: 3D visualization and rendering
- React Router: Client-side routing
- React Icons: Icon components
Update the Raspberry Pi IP address in:
frontend/package.json- proxy settingfrontend/src/components/- API endpoint URLs
cd backend
python3 src/main.pyThe main script launches multiple concurrent threads:
- Camera Capture: Dual camera frame acquisition
- Flask API Server: RESTful API on
http://[PI_IP]:5000 - Navigation: Autonomous path planning and execution
- Sensor Processing: IMU, encoders, and visual localization
- Output Management: Data logging and status reporting
Configure in backend/src/variables.py:
nav_mode = 0: Straight line navigationnav_mode = 1: Manhattan grid navigation (default)nav_mode = 2: AprilTag-based navigationnav_mode = 3: Landmark-based navigation
cd frontend
npm startAccess the dashboard at http://localhost:3000
cd frontend
npm run build
# Deploy the build/ folder to your web server- Start Backend: Launch the Python backend on Raspberry Pi
- Start Frontend: Run the React development server or deploy production build
- Access Dashboard: Navigate to the frontend URL
- Login: Use credentials (default:
sinan/1234oradmin/admin123) - Control Vehicle: Use the intuitive control interface
- Frontend Dashboard:
http://localhost:3000(development) - Backend API:
http://[RASPBERRY_PI_IP]:5000 - Live Camera Feed:
http://[RASPBERRY_PI_IP]:5000/video_feed - Position Data API:
http://[RASPBERRY_PI_IP]:5000/positions
Default login credentials:
- Username:
sinan| Password:1234 - Username:
admin| Password:admin123
Update credentials in frontend/src/components/LoginPage.jsx
The system implements a three-tier localization hierarchy:
- Accuracy: Highest precision (Β±2cm typical)
- Method: PnP pose estimation from known fiducial markers
- Coverage: Limited to marker visibility range
- Fallback: When no tags detected
- Target: Eiffel Tower scale model
- Method: Object detection + stereo/mono distance measurement
- Angle Classification: Neural network-based orientation estimation
- Range: Medium-distance landmark navigation
- Components: MPU6050 IMU + wheel encoders
- Method: Dead reckoning with drift correction
- Reliability: Continuous availability, accumulates error over time
- Correction: Reset by higher-priority localization methods
# AprilTag world coordinates (meters)
APRILTAG_COORDS = {
0: [0, 0.0, 2.2], # Origin tag
2: [-0.6, 0.0, 2.2], # Left reference
3: [1.2, 0.0, 1.32], # Right reference
# ... additional tags
}
# Navigation settings
nav_mode = 1 # Manhattan navigation
roadnet_height, roadnet_width = 20, 20 # Grid dimensions
# Camera parameters
resolution = (1280, 960)
stereo_baseline = 51 # mm# Front motors
FRONT_LEFT_PIN1, FRONT_LEFT_PIN2 = 26, 21
FRONT_RIGHT_PIN1, FRONT_RIGHT_PIN2 = 20, 16
# Rear motors
BACK_LEFT_PIN1, BACK_LEFT_PIN2 = 5, 6
BACK_RIGHT_PIN1, BACK_RIGHT_PIN2 = 1, 7Update Raspberry Pi IP addresses in:
{
"proxy": "http://192.168.6.62:5000"
}// Camera feed
const imageSrc = "http://raspberrypi.local:5000/video_feed";
// Position data
const response = await fetch("http://raspberrypi.local:5000/positions");
// Control commands
const BASE_URL = "http://raspberrypi.local:5000";Pi5bitirme/
βββ backend/ # Raspberry Pi Backend
β βββ src/ # Core system modules
β β βββ main.py # System orchestrator
β β βββ navigation.py # Path planning & execution
β β βββ localisation.py # Multi-sensor position estimation
β β βββ motor_controller.py # 4WD motor control
β β βββ web.py # Flask API server
β β βββ apriltag_detection.py # Fiducial marker processing
β β βββ stereo_distance.py # Dual-camera ranging
β β βββ mono_distance.py # Single-camera distance
β β βββ gyroscope.py # IMU orientation tracking
β β βββ wheel_sensor.py # Encoder odometry
β β βββ detect_and_crop.py # Landmark detection
β β βββ manhattan_navigation.py # Grid path planning
β β βββ variables.py # Global configuration
β β βββ cam_calibration/ # Camera calibration tools
β β βββ camera_calibration.py
β β βββ capture_dual_cam.py
β βββ scripts/ # Testing & calibration utilities
β βββ tagtest_localization.py
β βββ dual_camera_capture.py
β βββ distance_test.py
βββ frontend/ # React Frontend Application
β βββ public/ # Static assets
β β βββ index.html # Main HTML template
β β βββ eyfelkulesi.stl # 3D Eiffel Tower model
β β βββ truck.stl # 3D vehicle model
β βββ src/ # React source code
β β βββ components/ # React components
β β β βββ HomePage.jsx # Main dashboard
β β β βββ LoginPage.jsx # Authentication
β β β βββ VehicleTracking3D.jsx # 3D visualization
β β β βββ Camera.jsx # Live video feed
β β β βββ Buttons.jsx # Control interface
β β β βββ Locations.jsx # Position display
β β β βββ Header.jsx # Navigation header
β β βββ css/ # Component styles
β β βββ assets/ # Images and resources
β β βββ App.jsx # Main App component
β β βββ index.jsx # Entry point
β βββ package.json # Dependencies & scripts
β βββ README.md # Frontend documentation
βββ README.md # Main project documentation
cd backend
# AprilTag precision test
python3 scripts/tagtest_localization.py
# Distance measurement validation
python3 scripts/distance_test.py
# Dual camera stereo verification
python3 scripts/dual_camera_capture.py
# Manual control testing
python3 scripts/manual_stop.pycd frontend
# Run test suite
npm test
# Component testing
npm run test -- --coverage
# Build verification
npm run build- Backend-Frontend Communication: Verify API endpoints respond correctly
- Real-time Data Flow: Ensure position updates appear in 3D visualization
- Control Responsiveness: Test vehicle commands through web interface
- Camera Streaming: Validate live video feed integration
- Data Logging: Confirm CSV export functionality works properly
- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement) - Commit changes (
git commit -am 'Add new localization method') - Push to branch (
git push origin feature/improvement) - Create Pull Request
This project is part of academic research. Please refer to the accompanying thesis document (PRE-SAFE_Thesis.pdf) for detailed technical information and research methodology.
PRE-SAFE represents a comprehensive approach to autonomous vehicle localization, combining multiple sensor modalities for robust navigation in structured environments. The system demonstrates practical implementation of:
- Computer Vision: AprilTag detection and landmark recognition
- Sensor Fusion: Multi-modal localization with hierarchical estimation
- Real-time Systems: Concurrent processing and control
- Full-stack Development: Modern web technologies integrated with embedded systems
- 3D Visualization: Interactive real-time vehicle tracking and monitoring
- Multi-tier Localization Hierarchy: Intelligent fallback between localization methods
- Real-time 3D Visualization: Three.js integration for live vehicle tracking
- Modern Web Interface: React-based dashboard with Material-UI components
- Comprehensive Data Logging: CSV export for research and analysis
For detailed technical analysis, experimental results, and theoretical background, please refer to the complete thesis documentation (PRE-SAFE_Thesis.pdf).
For technical questions or implementation assistance:
- Contact us directly or through our advisor, Assoc. Prof. MΓΌjdat SoytΓΌrk, if you aren't able to find contact information
- Create an issue in the project repository for bug reports or feature requests
- Backend: Raspberry Pi 5, Python 3.8+, dual cameras, IMU, motor controllers
- Frontend: Node.js 16+, modern browser with WebGL support
- Network: Local network connectivity between frontend and Raspberry Pi
PRE-SAFE - Advancing autonomous vehicle technology through precise localization, intelligent sensor fusion, and modern web-based interfaces.