Lesson 20

Color Tracking (Hiwonder 7.5)

🎯 Learning Objectives

🎯 What Color Tracking Does

Goal

The robot uses the ESP32-S3 vision module to detect a red target and then adjusts its movement so it stays facing the target.

If you move a red ball or block left/right in front of the camera, the robot rotates in place to follow it.

Expected Outcome (Hiwonder 7.5.4)

Power on the robot. The buzzer beeps once and the RGB light turns white. When a red ball is placed in front of the ESP32-S3 vision module and moved, the robot rotates to follow the ball.

📐 The Tracking Idea (Centering)

Center Point Tracking

The vision module returns a detected block location (often something like x, y, and size). Your controller compares the detected center to the desired center of the image.

// Conceptual control loop
// error = targetCenterX - detectedCenterX
// angle = kP * error
// speed can be small or zero (rotate-in-place tracking)

errorX = targetX - detectedX;
set_angle = mapErrorToAngle(errorX);
set_speed = chooseSpeed();
Velocity_Controller(set_angle, set_speed, 0, SIMULATE_PWM_CONTROL);

Timing Matters

In the Hiwonder example, the control update runs on a timer (periodic callback) so the robot keeps adjusting smoothly.

🔬 Hands-On Activity: Track a Red Target

Materials Needed

  • miniAuto with ESP32-S3 vision module installed
  • Red ball or red block
  • Open floor space

Step-by-Step Instructions

  1. Upload programs: Flash the ESP32-S3 color tracking program, then upload the UNO tracking program
  2. Power on: Confirm the RGB is white and the buzzer beeps once
  3. Present target: Hold a red ball/block in front of the camera
  4. Move target: Move the target left/right and confirm robot rotates to follow
  5. Experiment: Try different distances and lighting; note stability changes

Testing and Troubleshooting

  • No tracking: Make sure the ESP32-S3 tracking firmware is flashed correctly
  • Wrong color: Use a solid red object; reduce background clutter
  • Jitter: Increase distance slightly and improve lighting
  • Too fast: Reduce speed in the controller code (safer for indoor testing)

📋 Assessment & Homework

Practice Exercises

  1. Demonstrate stable tracking at 3 different distances
  2. Record how lighting/background changes affect the tracking quality
  3. Add a “dead zone” so tiny errors don’t cause constant turning
  4. Try adding speed control based on target size (closer = larger)

Challenge Projects

  • Pan Follow: Make the robot steer so the target stays centered while driving forward slowly
  • Lost Target: If target disappears, rotate slowly until it is found again
  • Safety: Add a STOP button (or timeout) you can trigger instantly

Reflection Questions

  1. Why does a periodic update loop make tracking smoother?
  2. What happens if the background contains “red” too?
  3. How could you make tracking more stable without adding heavy computation?
← Lesson 19: Color Recognition 📚 Semester Overview Next: Lesson 21 →