This document provides a comprehensive technical overview of the Autonomous Delivery Robot (R.D) project. It covers the architecture, communication protocols, algorithms, hardware specifications, and software logic.
- System Architecture
- Communication Protocols (UART Binary)
- Navigation & Pathfinding (A*)
- Positioning & ArUco Recalibration
- Hardware Specification & Pinout
- Software State Machine
- Web Interface & API Reference
- Safety & Fail-safes
The robot operates on a Distributed Control System (DCS) using two microcontrollers:
- Networking: Hosts the Web Dashboard and WebSocket server.
- Pathfinding: Runs the A* algorithm on a RAM-allocated grid map.
- Vision Interface: Receives ArUco detections from an external mobile device via HTTP API.
- User Interface: Manages the 4x4 Keypad and generates delivery security codes.
- Mission Orchestration: Maintains the global state machine and handles the delivery queue.
- Motion Control: Manages DC motors with differential drive and speed ramping.
- Sensor Fusion: Reads 4 ultrasonic sensors and an MPU6050 IMU.
- Local Safety: Implements autonomous obstacle avoidance and wall centering.
- Peripheral Interface: Controls the MG90S locking servo and I2C LCD status display.
Communication between the ESP32 and Arduino is handled via Serial2 (115200 baud) using structured binary packets to minimize overhead and latency.
Header: 0xAA | Size: 6 bytes
| Byte | Field | Description |
|---|---|---|
| 0 | Header | Constant 0xAA. |
| 1 | Action | 1:FWD, 2:BACK, 3:LEFT, 4:RIGHT, 5:STOP, 6:UNLOCK, 7:OPEN_SERVO, 8:CLOSE_SERVO, 9:LCD_MSG. |
| 2-5 | Argument | 32-bit integer (e.g., specific LCD message ID or target angle). |
Header: 0xBB | Size: 12 bytes
| Byte | Field | Description |
|---|---|---|
| 0 | Header | Constant 0xBB. |
| 1-4 | Distances | Left, Right, Front, Back (0-255 cm). |
| 5-6 | IMU Angle | 16-bit signed integer (degrees). |
| 7 | Button | Push-button state (0/1). |
| 8 | Event | 0:None, 1:Obstacle, 2:HatchOpened. |
| 9 | Delta Dist | Signed 8-bit integer (cm since last update) for odometry. |
The robot uses a modified A Algorithm* (AStarPathfinder.h) optimized for ESP32 memory constraints.
-
Cell Size:
$20 \text{cm} \times 20 \text{cm}$ ($0.20$m). -
Map Source:
map.binon SD card (bit-packed grid). - RAM Cache: Downsampled "coarse map" stored in RAM (max 50,000 cells / ~50KB).
- Connectivity: 8-direction movement (Octile distance heuristic).
- Corner Safety: Prevents diagonal movement if adjacent cardinal cells are occupied.
- Robustness: If a destination is inside a wall, the algorithm automatically searches for the nearest free cell within a 5-cell radius.
- Path Memory: Supports paths up to 300 steps (
MAX_PATH).
To combat wheel slip and odometry drift, the robot uses ArUco Markers as absolute global anchor points.
When a marker is detected (via the mobile phone camera API), the robot:
- Lookup marker ID in the
balises[]registry. - Overrides current
$(X, Y)$ coordinates and orientation$(\theta)$ with the marker's calibrated world position. - Notifies the Dashboard via WebSocket for real-time map visualization update.
- Marker 29: Kitchen / Home Base.
- Markers 24-42: Individual Patient Rooms.
- Markers 201-213: Corridor intersections and technical waypoints.
| Peripheral | Pin | Responsibility |
|---|---|---|
| SD Card (SPI) | CS:4, MOSI:23, SCK:18, MISO:19 | Map & Site hosting. |
| UART Serial2 | TX:17, RX:16 | Inter-MCU link. |
| Keypad Rows | 32, 33, 15, 26 | Input. |
| Keypad Cols | 27, 14, 12, 13 | Input. |
| Peripheral | Pin | Responsibility |
|---|---|---|
| Motors (A/B) | Dir:12/13, PWM:3/11, Fren:9/8 | Movement. |
| Ultrasonic | L:4, R:5, F:6, B:7 | Obstacle detection. |
| Servo | 10 | Hatch Lock. |
| Button | A0 | Delivery confirmation. |
| I2C LCD/IMU | SDA/SCL | Display & Gyro. |
The robot operates on 7 core states (MissionState):
-
MISSION_IDLE: Awaiting command from Dashboard. -
GOING_TO_KITCHEN: Moving to pick-up point (Marker 29). -
WAITING_LOADING: Stopped at base; waits for staff confirmation via WebSocket. -
GOING_TO_ROOM: Navigating to the patient's room marker. -
WAITING_DELIVERY: Stopped at room; checks for Keypad code entry. -
RETURNING_HOME: Mission success; returning to base. -
NEEDS_CHARGE: Battery$< 20%$ ; status locked until charged.
The ESP32 hosts a Full-stack Single Page Application (index.html) with dual-role authentication.
- Staff:
admin/robot2024orinfirmier/soins123. - Patient: Authenticated via Room Number + PIN (last 4 digits of room).
GET /aruco?id=<id>: Triggers ArUco marker detection logic.GET /status: Returns JSON of current position, state, and sensors.POST /auth?role=<role>: Authenticates user credentials.
Triggered when Front sensor
- Emergency Stop + Notify Dashboard.
- Wait 5s for obstacle to move.
-
Active Evasion: If blocked, detects freer side (Left vs Right), pivots
$90^\circ$ , advances, and re-routes.
- ESP32 Watchdog (30s): Panic reset if mission logic hangs.
- Arduino Watchdog (3s): Performs emergency stop if UART heartbeat (
0xAApacket) from ESP32 is lost. - Mission Timeout (10m): Automatically cancels mission and returns home if target is not reached within 10 minutes.