Journal

The big idea: push harder the further you are

Watch: P, I and D in about a minute

Imagine a rover that must drive 5 m and stop exactly on a mark. A position sensor tells it where it is. How hard should the motors push?

The simplest sensible answer: push in proportion to how far away you are. Far from the mark, push hard. Nearly there, push gently. On the mark, stop pushing.

The distance still to go is called the error, written \(e\):

\[e = \text{setpoint} – \text{measurement}\]

The setpoint is where you want to be (5 m). The measurement is where the sensor says you are.

One number, one rule

Say the rover is at 3 m, so \(e = 5 – 3 = 2\ \text{m}\). With a gain of \(K_p = 60\ \text{N/m}\) the motor force is

\[u = K_p\, e = 60 \times 2 = 120\ \text{N}\]

At 4.5 m the error is 0.5 m and the force drops to 30 N. That is proportional control, the P in PID. It already works surprisingly well, but it has two problems you will see in the simulation:

  • The rover arrives with speed, overshoots the mark and swings back and forth.
  • On a ramp, gravity pulls it back. Near the mark the error is small, so the push is small, and the rover stops short: 17 cm short in our example.

Three questions, three terms

A PID controller fixes both problems by asking three questions every time step:

  1. P: how far off am I now? Push in proportion.
  2. I: how long have I been off? Add up the error over time and push harder if it will not go away. This removes the 17 cm.
  3. D: how fast am I closing in? If the error is shrinking quickly, ease off early. This stops the overshoot.
\[u = K_p\, e + K_i \textstyle\sum e\,\Delta t + K_d\, \frac{\Delta e}{\Delta t}\]

The loop

Every controller in this course runs the same feedback loop, many times a second:

  1. Measure where you are.
  2. Compare with the setpoint to get the error.
  3. Compute the command from P, I and D.
  4. Act: send it to the motor, then repeat.

Keep this picture in mind. Every equation in Lesson 4 is one line of step 3.

Log in or create a free account to save your progress.

Enjoyed the preview? Unlock the full course.

₹199 ₹599 67% off
Create free account to enrollLog in

Lifetime access to every lesson, the equations and the downloadable Python simulation. Your progress is saved to your account.

Pay securely with UPI, cards, netbanking or wallets through Razorpay. The course unlocks instantly.

By enrolling you agree to our Terms, Refund policy and Privacy policy.

All lessons
  1. The big idea: push harder the further you are▶ VideoFree preview
  2. How it was invented and its first uses▶ VideoLocked
  3. Where it is used today▶ VideoLocked
  4. The equations▶ VideoLocked
  5. Worked demo and tuning▶ VideoLocked
  6. Build your own, step by step▶ VideoLocked
  7. Python simulation labLocked
  8. Practice problems and quizLocked

We’ll drive a rover into your seminar hall. The demo is free.

A 45-minute session with a live rover drive and a drone flight in a netted cage, for any engineering college in Kerala or Tamil Nadu.