Lesson 21

Vision Line Following (Hiwonder 7.6)

🎯 Learning Objectives

🧭 What Vision Line Following Does

Goal

In Hiwonder 7.6, the robot uses the ESP32-S3 vision module to detect a red wide line and moves along it.

Instead of using IR line sensors, the camera is doing the “line detection”, and the Arduino uses that detection output to steer.

Expected Outcome (Hiwonder 7.6.4)

  • Behavior: Once powered on, the car begins following the red line and moves along its path
  • Track: Use a red, wide, high-contrast line for best results

📐 Steering Correction Concept (PID-style)

Line Offset → Steering

The camera detects where the line is in the image. Your controller compares that position to the center. The difference (error) becomes a steering correction.

  • Error = desiredCenterX − detectedLineX
  • Correction = kP * error (plus optional I and D parts)

Pseudo-Logic

// Example structure (concept)
readLineData(buffer);

lineX = buffer[0];
targetX = IMAGE_WIDTH / 2;
error = targetX - lineX;

set_angle = kP * error;
set_speed = baseSpeed;

Velocity_Controller(set_angle, set_speed, 0, SIMULATE_PWM_CONTROL);

🔬 Hands-On Activity: Build a Vision Line Track

Materials Needed

  • miniAuto robot with Arduino
  • ESP32-S3 vision module installed
  • Red tape (wide) to make a line
  • Flat floor space with good lighting

Step-by-Step Setup

  1. Build the track: Lay down a wide red tape line with gentle curves
  2. Flash programs: Upload the ESP32-S3 vision line following program and the UNO program
  3. Test slowly: Start with low speed and keep your hands ready to stop the robot
  4. Adjust environment: Improve lighting and reduce glare/reflections
  5. Iterate: Try sharper turns and measure when/where it loses the line

Troubleshooting Tips

  • Loses the line: Use a wider line or simplify the path
  • Wobbly steering: Reduce speed and/or reduce the proportional gain
  • Bad detection: Reduce background clutter and improve lighting
  • Glare: Avoid shiny floors or direct reflections

📋 Assessment & Homework

Practice Exercises

  1. Get the robot to follow a straight red line for 2 meters without leaving the track
  2. Test a gentle curve and record success rate over 5 runs
  3. Lower speed until the robot can complete the track consistently
  4. Add a “stop if line lost” behavior (safety)

Challenge Projects

  • Speed Boost: Increase speed while keeping stable tracking
  • Track Design: Create an S-curve track and tune parameters to finish it
  • Line Switch: Add a marker section that triggers a different behavior

Reflection Questions

  1. Why does increasing speed make line following harder?
  2. What environmental factors (lighting, glare) affected detection?
  3. What does “PID” help you do in a control loop?
← Lesson 20: Color Tracking 📚 Semester Overview Next: Lesson 22 →