This project implements a real-world autonomous driving simulation on a 30 × 20 cm robot. A Raspberry Pi with a single camera processes visual input from a printed road banner and controls steering using Ackermann geometry.
The system performs lane-keeping without external sensors such as LiDAR, ultrasonic, or infrared. All processing and decision-making are done onboard in real time.
- Processor: Raspberry Pi (Raspbian OS)
- Microcontroller: Arduino (connected via serial
/dev/ttyUSB0, 9600 baud) - Camera: Picamera2 (30 FPS)
- Steering: Servo motor (Ackermann steering)
- Drive: DC motor controlled via Arduino
- Communication: Serial commands (e.g.,
A[angle],F,S)
- Vision layer: OpenCV processing on Raspberry Pi
- Control layer: PID-based steering control
- Hardware layer: Arduino executes motor and servo commands
To achieve stable performance at 30 FPS:
- Region of Interest (ROI): Hardware cropping focuses only on the lower road area
- Brightness correction: Gamma correction (1.5) reduces glare and improves edge detection stability
- Masking: A polygonal mask isolates the road and removes irrelevant regions
Lane detection is based on:
- Canny edge detection
- Probabilistic Hough Line Transform (HoughLinesP)
Lines are classified as left or right based on position and slope threshold (|slope| > 2).
To improve robustness:
- Previous detected lines are stored
- If detection fails, last valid lines are reused to maintain direction
The blue and red lines represent the most probable left and right lane boundaries detected from the set of lines, and the green middle point is the target position that the steering system tries to align with.
Steering is controlled using a PID controller.
- Lane center is computed as the midpoint between left and right lanes
- Error is the offset between lane center and image center
- PID output is scaled and limited to match physical steering constraints
Ackermann steering geometry is used to convert control output into realistic wheel angles.
The Raspberry Pi sends serial commands to Arduino:
A[angle]for steering controlFfor forward movementSfor stop
- Line_Detection: main processing loop for vision and lane detection
- pid_control(error): computes steering correction
- reduce_local_brightness: applies gamma correction and lighting normalization
- send_command: sends serial instructions to Arduino
- average_line: merges multiple detected line segments into stable lane estimates