Toolvito

Calculates on this device. File exports run online.

PID Calculator

Type the gains of your PID controller (Kp, Ki, Kd, or Kc, Ti, Td) and the sample time. You get the controller output for a run of errors with its P, I and D parts at each step, the coefficients and difference equation to put in code, or the closed loop with your plant G(s) and its step response. To choose the gains for a process, use the PID tuning calculator.

Enter your values

Your values

In 1/s (Kp ÷ Ti). 0 for no integral action.

In s (Kp × Td). 0 for no derivative action.

How often the controller runs: the time between two steps.

Errors, the first step first

One error for each sample time, from rest (all earlier errors and outputs 0).

One number per line, or numbers with commas, semicolons or spaces between them.

More options

The D part is Kd s ÷ (Tf s + 1). Empty: Tf = Td ÷ 10 (filter factor N = 10). 0: no filter.

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose Calculate.

PID checked on the server

PID checked on the server

Uses the controller of the result above. For the first two modes the server puts the discretisation into C(s) with SymPy in exact fractions, runs the difference equation on your errors and compares python-control's sample_system; for the closed loop it works the step response out again with SciPy and draws it.

The calculator above works on your device. When you run a task in this section, Toolvito receives the values and result you submit to make the file or run the check. Download the result within one hour after the job finishes. Choose Delete files now to request earlier removal. The hourly cleanup normally removes files within one to two hours after completion.

How to use the PID calculator

  1. Choose the form of your gains: parallel (Kp, Ki in 1/s, Kd in s) or standard (Kc, Ti and Td in seconds).
  2. For The output for a run of errors type the sample time and the errors e = set point − measurement, one for each step (or paste a column of numbers).
  3. For Discrete coefficients and code you get b0, b1, b2, a1, a2 and lines of code to copy.
  4. For The closed loop with a plant G(s) type the plant as a numerator and a denominator, such as 1 and (s + 1)(s + 2).
  5. The box under the result works the coefficients and the output (or the closed-loop figures) out again on the server.

The PID formulas

  • Parallel form: u = Kp e + Ki ∫e dt + Kd de/dt. Standard form: u = Kc (e + (1/Ti) ∫e dt + Td de/dt), so Kp = Kc, Ki = Kc ÷ Ti and Kd = Kc × Td.
  • The D part is filtered: Kd s ÷ (Tf s + 1), with Tf = Td ÷ 10 unless you type it.
  • Backward Euler (the usual code): P = Kp e[k]; I = I + Ki Ts e[k]; D = (Tf D + Kd (e[k] − e[k−1])) ÷ (Tf + Ts).
  • Tustin: the integral adds Ki Ts (e[k] + e[k−1]) ÷ 2 and the filter uses (2Tf − Ts) and (2Tf + Ts).
  • Difference equation: u[k] = b0 e[k] + b1 e[k−1] + b2 e[k−2] − a1 u[k−1] − a2 u[k−2].

Worked example

Kp = 2, Ki = 1 per s, Kd = 0.5 s, Ts = 0.1 s, Tf = 0.025 s, backward Euler: b0 = 6.1, b1 = −10.42, b2 = 4.4, a1 = −1.2, a2 = 0.2. For the errors 1, 0.8, 0.5, 0.3, 0.1, 0 the first output is 6.1 (P 2 + I 0.1 + D 4) and the last is −0.3316.

The same gains on G(s) = 1 ÷ ((s + 1)(s + 2)) give a closed loop that rises from 10 % to 90 % in 4.81 s without overshoot and settles in 9.71 s.

Limits you should know

  • The controller starts from rest and has no output limits: a real controller clamps its output and stops integrating while clamped (anti-windup).
  • The closed loop is continuous and linear: the sample time, valve limits and noise are left out.

Related tools