CivilKit Calcs

PID controller design calculator

This sheet works through one classic control problem: a DC motor with a PID controller. It builds the closed-loop polynomial, tests it with the Routh-Hurwitz rule, finds the poles and plots the step response. In Input mode the gains are sliders.

Open this sheet in Calcs Open a blank sheet

What it computes

The motor is normalised, with time in seconds and no other units, so poles come out in 1/s. It has an inertia J, a damping b and a gain K, and the controller adds Kp, Ki and Kd. With unity feedback the poles are the roots of a cubic. The sheet then:

  1. It forms the monic cubic s^3 + a2 s^2 + a1 s + a0 from the gains and the motor values.
  2. It applies the Routh-Hurwitz test and prints a PASS or FAIL line for each condition, then a verdict.
  3. It solves the cubic in closed form and prints the three poles, then substitutes them back to check the residual.
  4. It writes the step response as a sum of exponential terms, checks that it starts at zero, and plots it against the target of 1.

It ends with the discrete update equation, a sample-time check and a short C function.

Video: Templates with inputs (about 85 seconds). Read the chapter Templates with inputs.

Try it

Open the sheet in Calcs or embed it.

The formulas

Worked example

Base case: Kp = 5, Ki = 2, Kd = 0.5, with J = 1, b = 10 and K = 20. Results from the engine:

QuantityResult
Coefficient a220
Coefficient a1100
Coefficient a040
Third Routh entry98
First pole-0.43743
Second pole-7.7244
Third pole-11.8382
Largest sample time (rule of ten)0.0084472 s

All three Routh conditions pass, so the sheet prints "VERDICT: the closed loop is stable." The three poles are real and negative, which agrees with the Routh result. The integral term makes the response settle to 1 with no steady-state error, and the slowest pole, -0.43743, sets the length of its tail.

Change the gains and watch the verdict flip

Set Kp to 0.5 and Ki to 15. Now a2 a1 is 10 times 20, which does not exceed a0 = 300, so the third Routh entry is -5 and the sheet prints FAIL. The poles confirm it: one real pole at -20.2383 and a complex pair with real part 0.11916 and imaginary part plus or minus 3.8483. A positive real part means growing oscillation.

Now remove the derivative term with Kd = 0 and Kp = 15. The coefficients become a2 = 10, a1 = 300 and a0 = 40. The loop is stable, but two poles are now a complex pair with real part -4.933 and imaginary part plus or minus 16.5633, so the response rings. Raising Kd adds damping.

The slider panel needs Python

Lower in the sheet is a separate interactive panel, written in Python. It has its own sliders for the fixed motor, integrates the closed-loop equations on every move, and prints a Routh verdict with the peak and overshoot. No numbers from it are quoted here. It needs Python, which the app asks permission to run once per tab. The rest of the sheet works without it.

What this is, and is not

This is a worked, self-checking example. It prints PASS and FAIL lines for the Routh conditions, pole residuals, the response start and the sample time. It is not a design tool, a certified program, or a model of your actual hardware: the plant is a normalised textbook motor with no actuator limits, delay or noise.

It is for learning and checking ideas, not for safety-critical use. The problems follow the cookbook of the symplex library (MIT or Apache-2.0), rewritten for Calcs; the public repository is github.com/cgorski/symplex.

How to use it

  1. Open the sheet. Choose Open this template on this page. It opens in a new tab with the base gains.
  2. Switch to Input mode. In the results bar choose Input. The gains and motor values become sliders.
  3. Move the gains. Drag Kp, Ki and Kd. The coefficients, the Routh lines, the poles and the step response plot all recalculate.
  4. Read the verdicts. Read the PASS and FAIL lines. Python, needed only for the separate slider panel lower in the sheet, is asked for once per tab.

Questions

How does the sheet check stability?

It uses the Routh-Hurwitz test on the closed-loop cubic: a2 and a0 must be positive and a2 a1 must exceed a0. It also finds the poles and checks that they agree.

Can I use my own motor?

Yes. J, b and K are inputs. The formulas fit this plant shape, a motor with an integrator and a first-order lag; another plant needs other equations.

Why does the loop go unstable with a high Ki and a low Kp?

The constant term a0 grows with Ki while a1 grows with Kp. When a2 a1 no longer exceeds a0, a pair of poles crosses into the right half plane.

Does the whole sheet need Python?

No. The polynomial, Routh lines, poles, step response plot and sample-time check are ordinary sheet maths. Only the slider panel is Python, and the app asks permission once per tab.

Can I use it to tune a real controller?

It is for learning and checking ideas, not for safety-critical use. Test on the real system with proper limits.

Open this sheet in Calcs Open a blank sheet