From Beginner to Winner: a LEGO SPIKE Prime Guide to Line Following Excellence

by AfrelEdTech in Circuits > Robots

43 Views, 0 Favorites, 0 Comments

From Beginner to Winner: a LEGO SPIKE Prime Guide to Line Following Excellence

サムネイル.png

Are you looking to boost your line-following robot’s speed without losing stability?

While P control helps you get started with smooth movement, adding D control (Derivative) opens up new possibilities—especially at high speeds.

In this article, we explore how PD (Proportional + Derivative) control improves performance on an R-shaped course using SPIKE Prime and C programming.

We'll test it under different speeds, compare it to P-only control, and show how small tuning makes a big difference.

Supplies

スクリーンショット 2025-06-20 084444.png

SPIKE Prime

  1. Motors:
  2. Left Motor: Port C
  3. Right Motor: Port D
  4. Color Sensor: Port A

What Is PD Control?

PD = Proportional + Derivative

  1. P (Proportional): Steers based on how far the robot is from the line.
  2. D (Derivative): Reacts to how quickly the error is changing.

"It predicts changes and smooths the motion."

By combining the two, PD control smooths out overshooting and reduces zigzagging—especially on curves and at higher speeds.

Course

Rcourse.png

We use the same R-shaped line course as the previous P control test:

  1. Curved sections at the beginning
  2. Long straight section at the end

This layout helps highlight how the robot handles different motion dynamics at increasing speeds.

Program

speed400.png
speed500.png
speed600.png

Speed Tests

① Low Speed – Easy win for PD

  1. Speed: 400 deg/s
  2. Kp: 1.0 Kd: 0.7

Smooth and stable

PD control keeps the robot gently following the line with minimal correction needed.

② Medium Speed – Still stable

  1. Speed: 500 deg/s
  2. Kp: 1.0 Kd: 0.8

PD handles curves with confidence

Even with faster turns, the robot does not overshoot.

③ High Speed – Where PD shines

  1. Speed: 600 deg/s
  2. Kp: 0.9 Kd: 0.8

P alone would fail

PD keeps control even at speeds where P control would zigzag or go off course.


P Vs PD Comparison

  1. With D: Smoother turns, minimal overshoot
  2. Without D: Zigzag motion, unstable in curves

You’ll see this clearly in the video demo—PD’s advantage becomes obvious as speed increases.

Summary of PD Control

🌀 Reduces zigzag motion

🚀 Enables higher speeds

⚙️ Balances speed and stability

【Free Trial】Start C Language Programming With Afrel's Educational Materials

Guide to running SPIKE Prime in C language

Are you intrigued by the idea of programming your SPIKE™ Prime with C? Did you know that Afrel is a key information provider for SPIKE™ Prime?


To meet the demand of those who want to "learn more about SPIKE™ Prime " and "try programming in C," Afrel has developed and sells educational materials for learning C language programming with SPIKE™ Prime.


Stepping up from Python to C is an excellent opportunity to further enhance your programming skills. Learning C will give you a deeper understanding of how computers work and enable more advanced control.


Afrel's C language materials are designed for beginners, ensuring a smooth learning experience. Why not take this chance to discover the joy of controlling SPIKE™ Prime with C and expand your programming horizons?


If you're ready to tackle C language programming, click the link below for more details.


Learn more about SPIKE™ Prime C Language Programming Materials here