Line Following Control
Closed-Loop Control Methods
1. Bang-Bang Control (On-Off Control)
-
Basic Idea: Robot makes discrete left/right decisions based on sensor input (e.g. if the line is on the left, turn left).
-
Use case: Very simple robots, works okay with sharp contrast and slow speeds.
-
Pros: Easy to implement.
-
Cons: Jerky motion, poor stability at higher speeds.
2. Proportional Control (P-Control)
-
Basic Idea: The correction (steering) is proportional to how far the robot is from the center of the line.
-
Implementation:
python error = desired_position - actual_position correction = Kp * error` -
Use case: Smooth steering with continuous feedback from multiple sensors (e.g., using weighted values from 4–8 sensors).
-
Pros: Smooth, real-time control.
-
Cons: May oscillate or overshoot.
3. Proportional-Derivative Control (PD-Control)
-
Basic Idea: Adds a damping effect by taking the derivative (rate of change) of the error.
-
Implementation:
python correction = Kp * error + Kd * (error - previous_error) -
Use case: Improves stability over just P-control, especially in fast-moving robots.
-
Pros: Reduces overshoot and oscillation.
-
Cons: Still no integral correction for persistent bias.
4. Proportional-Integral Control (PI-Control)
-
Basic Idea: Combines proportional control (reacts to current error) with integral control (reacts to accumulated past error).
-
Why use it: If your robot tends to drift consistently in one direction or has a bias (e.g., slightly uneven motors), PI helps correct that over time.
-
Implementation:
python integral += error correction = Kp * error + Ki * integral -
Use case: Good for systems where eliminating steady-state error is more important than quick correction (like slow-to-moderate line followers on smooth tracks).
-
Pros: Corrects long-term drift or steady-state errors.
- Cons: Slower to respond than PD; may overshoot without derivative damping.
5. PID Control (Proportional-Integral-Derivative)
-
Basic Idea: Combines proportional, integral (to remove long-term bias), and derivative (for stability).
-
Implementation:
python integral += error derivative = error - previous_error correction = Kp * error + Ki * integral + Kd * derivative -
Use case: High-performance line followers, especially if the line has curves or inconsistent lighting.
-
Pros: Accurate and stable.
-
Cons: Needs tuning (Kp, Ki, Kd), more computational load.
6. Fuzzy Logic Control
-
Basic Idea: Uses linguistic rules (like “if line is slightly left, turn a little right”) to compute steering.
-
Use case: Where sensor data is noisy or ambiguous.
-
Pros: Robust to sensor fuzziness.
-
Cons: Requires defining fuzzy sets and rules.
đź§ľ Bonus: Sensor Fusion or Kalman Filtering
-
Used when: Combining multiple sensor inputs (e.g., line sensors + IMU) for better state estimation.
-
Usually: More advanced robots.
Realistic Application to Your Robot
Since your robot has:
-
4 optosensors for line tracking,
-
Ultrasonic for object detection,
-
Wheels that can be driven independently,
A PD controller would likely give the best mix of performance and simplicity. You can later extend to PID if you find it's consistently drifting or lagging on corrections.
Summary Comparison
| Control Type | Corrects Current Error | Smooths Changes | Eliminates Drift/Bias | Notes |
|---|---|---|---|---|
| Bang-Bang | ❌ | ❌ | ❌ | On/Off only |
| P | ✅ | ❌ | ❌ | Simple and fast |
| PI | ✅ | ❌ | ✅ | Steady-state correction |
| PD | ✅ | ✅ | ❌ | Fast and stable |
| PID | âś… | âś… | âś… | Most accurate |
| Fuzzy Logic | đźš« (rule-based) | âś… | âś… | Flexible but complex |
What is it?
The numerator is the sum of each sensor's value multiplied by its position weight.
What it represents:
It gives you a kind of “center of gravity” of the detected line — but not averaged yet.
Think of it like this:
-
If only the far left sensor sees the line (1), and the others don’t (0), it contributes
1 Ă— -3 = -3. -
If both center sensors see the line (
[0, 1, 1, 0]), it contributes-1 + 1 = 0.
So the numerator tells you how far left or right the "center" of the detected line is, but not normalized yet.