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

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

SPIKE Prime
- Motors:
- Left Motor: Port C
- Right Motor: Port D
- Color Sensor: Port A
What Is PD Control?
PD = Proportional + Derivative
- P (Proportional): Steers based on how far the robot is from the line.
- 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

We use the same R-shaped line course as the previous P control test:
- Curved sections at the beginning
- Long straight section at the end
This layout helps highlight how the robot handles different motion dynamics at increasing speeds.
Program



Speed Tests
① Low Speed – Easy win for PD
- Speed: 400 deg/s
- 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
- Speed: 500 deg/s
- 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
- Speed: 600 deg/s
- 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
- With D: Smoother turns, minimal overshoot
- 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

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