ESP32 | Comprehensive Project 02 – P Line Following | Single Probe Line Following Method | Basics of Robot Competitions

01

Introduction

This article introduces the most basic line following method – P line following, explaining everything from the principle of line following to code implementation.

P inspection, known as proportional control, is a fundamental component of PID line following. The core idea is to adjust the robot’s steering actions proportionally by calculating the real-time deviation between the sensor’s detected value and the target value, achieving the purpose of line following.

ESP32 | Comprehensive Project 02 - P Line Following | Single Probe Line Following Method | Basics of Robot Competitions

02

Principle

The line following sensor above has 5 probes, but P line following only requires one probe, which is the middle one. First, we read the value detected by this probe on the black line, which is over 900; then we detect the value of the white background, which is about 300. At this point, we set the target value Mid to 800, where values greater than 800 indicate black.

We continuously detect the error E between the probe value and the target value. If E is greater than 0, the sensor is biased to the right, so we turn left; if E is less than 0, the sensor is biased to the left, so we turn right; this way, the car can wobble along a straight line.

How do we control the left and right turns? We use a steering variable Turn to calculate, setting the base speed as P: left wheel speed<strong><span><span>Left=P-Turn</span></span></strong>; right wheel speed<strong><span><span>Right=P+Turn</span></span></strong>.

How is the steering variable Turn obtained? It’s simple; it equals the error E multiplied by the proportional coefficient Kp:<strong><span><span>Turn = Kp × E</span></span></strong>.

How to set the coefficient Kp: if the line following oscillates greatly → decrease<span><span>Kp</span></span>; if the correction after deviation is slow → increase<span><span>Kp</span></span>.

The following diagram illustrates the process of the car following the line: the initial position of the probe is on the black line, with a detection value >800, so it turns left; after turning left, the probe value is less than 800, so it turns right; after turning right, the probe will encounter the black line again, so it turns left again; this control loops continuously, allowing the car to move along the line.

ESP32 | Comprehensive Project 02 - P Line Following | Single Probe Line Following Method | Basics of Robot Competitions

03

Wiring Diagram

ESP32 | Comprehensive Project 02 - P Line Following | Single Probe Line Following Method | Basics of Robot Competitions

04

Effect Demonstration

If you need a video explanation, please leave me a message. If many people have this need, I can consider making a session. Ps. Students who need components can go to my Taobao store with the same name to purchase.

ESP32 | Comprehensive Project 02 - P Line Following | Single Probe Line Following Method | Basics of Robot CompetitionsFollow me for more sharingWeilan Classroom

Leave a Comment