A Python-based autonomous robot that follows a line through turns up to 90° using three grayscale sensors. Built on the PicarX platform. Includes a project documentation website deployed on Netlify.
| Robot navigating a straight line | Handling a sharp 90° turn |
|---|---|
The robot uses three grayscale sensors (left, center, right) that measure reflected light intensity:
Value > 1400 → White (background)
Value < 1400 → Black (line)
Each sensor reading is converted into a binary state (1 = line, 0 = background), and the combination of all three determines the robot's next action:
Sensor State [L, C, R] |
Detected Situation | Action |
|---|---|---|
[_, 1, _] |
Center on line | Go straight |
[1, 0, 0] |
Drifted right | Steer left |
[0, 0, 1] |
Drifted left | Steer right |
[0, 0, 0] |
Line lost | Recovery maneuver |
When all sensors read white (line lost), the robot uses last_state to remember which direction it was turning before losing the line, then steers back in that direction to re-acquire it — rather than stopping blindly.
def outHandle():
if last_state == 'left':
px.set_dir_servo_angle(-offset)
px.forward(px_power)
elif last_state == 'right':
px.set_dir_servo_angle(offset)
px.forward(px_power)The project was structured as a series of progressive tasks:
- Line-Following — Follow a line through turns up to 90°
- Intersection-Finding — Detect and stop at line intersections
- Intersection-Choosing — Exit intersections by selecting the nth spoke clockwise
- Intersection-Traversing — Execute a sequence of intersection exits (n1, n2, n3…)
- Search & Traverse — Given a graph topology and goal, generate and execute a movement sequence
- Localization — Determine current position/heading without prior knowledge, then navigate
- Exploration — Autonomously map the environment and find the most central node
| Layer | Technology |
|---|---|
| Robot hardware | PicarX (Raspberry Pi-based) |
| Robot software | Python |
| Grayscale sensing | px.get_grayscale_data() / px.get_line_status() |
| Documentation site | HTML, CSS, JavaScript |
| Deployment | Netlify |
robot-path/
├── myLine-following.py # Main robot control script
├── line-following/ # Additional line-following experiments
├── index.html # Documentation site home
├── Code.html # Code walkthrough page
├── Journal.html # Development journal
├── Problem.html # Task descriptions
├── Pictures.html # Robot photos
├── Clips.html # Demo video clips
└── style.css # Site styling
- Sensor threshold tuning — small changes to the 1400 threshold value significantly affected detection accuracy depending on floor color and lighting conditions
- State machine design — tracking
last_statewas essential for smooth recovery; without it, the robot would freeze whenever it lost the line on a sharp turn - Control loop timing —
sleep(0.001)between sensor reads prevented servo jitter and gave the hardware time to respond to direction changes - Iterative hardware debugging — unlike software, hardware bugs required physical observation; watching the robot overshoot turns led directly to tuning the
offsetangle value