PID Controller Tuning Simulator

Tune a filtered PID controller on process and DC motor models. Compare step response, actuator saturation, Bode margins and a root locus with SIMC or Ziegler–Nichols settings.

#anti-windup #Bode plot #DC motor #PID #root locus #SIMC #step response #Ziegler–Nichols

This PID tuning simulator helps engineers and students see how controller settings change a feedback loop. Use it for a first pass at process-control settings, a laboratory exercise, or a comparison between a process model and a DC motor speed model. The default example is a first-order plant with a one-second delay and a SIMC PI controller, so the response and stability margins can be compared with published results.

Choose first order plus dead time when a step test suggests one dominant lag. Enter the normalized process gain, time constant and transport delay. For an oscillatory plant, choose the second-order model and enter its natural angular frequency and damping ratio. The DC motor model uses rotor inertia, viscous friction, resistance, inductance, torque constant and back EMF constant. Its mechanical-unit selector accepts SI or US customary data. Voltage and speed bases define what one per-unit command and output mean.

For the first-order model, choose SIMC PI, Ziegler–Nichols reaction-curve PID, or manual parallel gains. SIMC uses a desired response time: increasing it usually trades speed for gentler action. Ziegler–Nichols requires a positive delay and can give aggressive settings. The other plant models use manual gains. The derivative acts on the measured output through a first-order filter, avoiding a derivative kick at the setpoint change.

Set the actuator limits and try a disturbance at the plant input. Compare the commanded actuator signal and the integral contribution with conditional anti-windup enabled and disabled. A warning identifies targets that the actuator cannot hold. Press play to move the schematic marker through the precomputed transient; playback does not rerun the simulation.

The response charts show setpoint tracking and the plant's separate open-loop response to the same numerical input step. Rise time uses the 10–90% thresholds, and settling time uses a 2% band around the requested target. When a disturbance is enabled, these two timing metrics and overshoot use only the interval before it; the absolute error integral uses the entire simulation.

Use the Bode plot calculator to inspect the continuous loop magnitude, phase and margins over the selected frequency range. These plots include exact transport delay and exclude saturation. Choose a phase-margin or gain-margin detail view for readable crossover markers, or select the full unwrapped range. The reported limiting margins include their frequencies and consider every odd-180° crossing in both directions within the search range. The root locus scales all three controller gains together; with delay it uses a first-order Padé approximation. It is a guide to pole movement, not an exact delay-system stability proof.

Before transferring PID controller calculator settings to equipment, check the model, controller convention, signal scaling and sample period. The interval count sets the simulated controller sample period, equal to duration divided by intervals. Doubling the count changes that controller period and checks convergence toward continuous control; it is not merely a finer plant integration mesh. The tool omits measurement noise, quantization, actuator rate limits, backlash, motor current limits and parameter changes.

How it is calculated

The process models use G(s)=ke−θs/(a2s2+a1s+1)G(s)=k e^{-\theta s}/(a_2s^2+a_1s+1). For first order, a2=0a_2=0 and a1=Ta_1=T. For second order, a2=1/ωn2a_2=1/\omega_n^2 and a1=2ζ/ωna_1=2\zeta/\omega_n. The DC motor follows Newton's and Kirchhoff's laws: GωV(s)=Kt/[(Js+b)(Ls+R)+KtKe]G_{\omega V}(s)=K_t/[(Js+b)(Ls+R)+K_tK_e]. The voltage and speed bases convert this to a normalized gain. The motor equations and sample constants follow CTMS; the equations are also derived directly here.

The parallel feedback controller is C(s)=Kp+Ki/s+Kds/(1+Tfs)C(s)=K_p+K_i/s+K_ds/(1+T_fs). In the time simulation, derivative acts on output, so u∗=Kp(r−y)+I−Kdy˙fu_*=K_p(r-y)+I-K_d\dot y_f. A backward-Euler derivative filter and trapezoidal error integration run once per controller sample. Saturation clips the command. Conditional anti-windup rejects an integral increment only when its error direction would push a saturated command farther into its limit. It resumes integration when the error reverses. The input disturbance is added after saturation and before the transport delay.

Plant state transitions under each held input are evaluated analytically. A fractional delay splits a sample into two exact held-input transitions. This treats the delay exactly for the simulated sampled command; controller sampling still requires a convergence check. Initial states are zero. The time normalization of 1 s keeps mixed numerical coefficient vectors dimensionless without concealing physical units.

SIMC PI for a first-order model uses Kp=T/[k(λ+θ)]K_p=T/[k(\lambda+\theta)], Ti=min⁡[T,4(λ+θ)]T_i=\min[T,4(\lambda+\theta)], Ki=Kp/TiK_i=K_p/T_i, Kd=0K_d=0 (Skogestad 2003, Eqs. 23–24, attached PDF p. 6). Ziegler–Nichols reaction-curve PID uses Kp=1.2T/(kθ)K_p=1.2T/(k\theta), Ti=2θT_i=2\theta, Td=θ/2T_d=\theta/2, with Ki=Kp/TiK_i=K_p/T_i and Kd=KpTdK_d=K_pT_d (Åström–Murray, Table 11.1a). Filtering changes the ideal Ziegler–Nichols response.

The continuous frequency response includes exact transport delay. Phase is calculated as the controller's analytic atan2 phase minus the stable plant-denominator phase and ωθ\omega\theta, anchored to the model's low-frequency branch. It therefore does not depend on the sweep's starting frequency. The unity-gain frequencies come from the real polynomial in ω2\omega^2 obtained from ∣C(jω)G(jω)∣2=1|C(j\omega)G(j\omega)|^2=1.

For gain margin, zeros of the analytic phase derivative partition frequency into monotonic intervals. Every negative-real-axis level −180∘+360∘m-180^\circ+360^\circ m is checked in both directions within the selected range. Each crossing is refined by 34 log-frequency bisections. The signed gain margin closest to 0 dB and signed phase margin closest to 0° are returned with their crossover frequencies, following the MathWorks margin definition. Phase margin is the signed angular distance to the nearest odd-180° branch. These scalar margins do not establish internal stability. An absent crossing is reported as unavailable in the selected range. A range containing 1000 or more phase-crossing candidates is rejected rather than reporting a partial search. Peak sensitivity still uses the 601-point frequency grid.

The phase-view selector provides phase-crossover detail, gain-crossover detail, and the full unwrapped range. Focused views restrict the neighborhood of the selected crossover, including no more than roughly 180° of transport-delay phase variation, and draw the crossover markers and phase-margin arrow against the appropriate odd-180° guide. A crossover outside the displayed neighborhood remains reported in the header.

The simulated controller sample period is h=Tspan/Nh=T_\mathrm{span}/N. Changing the interval count or duration changes the actual sampled-controller model, not just a plant integration mesh. The plant transition between commands is analytical. Resolution warnings check plant poles, the derivative filter, and hωcontrol>0.2h\omega_\mathrm{control}>0.2, where the control frequency scale is the largest unity-gain crossover (including outside the plot) or largest rational closed-loop pole magnitude. This last threshold is a conservative numerical-resolution guideline for comparison with a continuous design, not a sampled-loop stability theorem.

Root locus solves D(s)+αN(s)=0D(s)+\alpha N(s)=0 for 61 multipliers from 0 to 10, keeping the filter time fixed and scaling every gain. A first-order Padé factor (1−θs/2)/(1+θs/2)(1-\theta s/2)/(1+\theta s/2) approximates delay only for this pole analysis. Uncancelled modes are retained. Dots show all sampled roots without implying branch connectivity; rings mark the current gain, and grey rings mark open-loop poles. Roots outside the chosen square are omitted.

Assumptions

Signals are deviations from a zero operating point. Plant gains and setpoints are positive; feedback is unity and negative. All process signals use per-unit scaling. For the motor, actual voltage equals command × voltage base, and actual speed equals output × speed base. Motor back EMF and torque constants are independently entered in SI units. Radians are dimensionless in the mechanical equations.

The models are linear and time invariant. The only actuator nonlinearity included is command saturation. The disturbance has the same units as normalized command and represents an additive plant-input load, not a motor shaft-torque load. There is no derivative action on setpoint. Anti-windup is conditional integration, with no hidden back-calculation gain.

Only first-order plants receive automatic tuning. Second-order and DC motor choices use the visible manual gains. The controller is parallel; SIMC is PI here, so no series-to-parallel PID conversion is needed. Time is always in seconds, angular frequency in rad/s; the motor mechanical-unit selector converts compound SI and US units explicitly. Other compatible fields use the catalog's normal unit display.

Where it applies

Use positive, stable first- or second-order self-regulating plants and the stated rigid-rotor DC motor model. This does not model integrating plants, unstable plants, inverse response, current-limited drives or cascaded control loops.

Continuous Bode margins and Padé poles describe the unsaturated continuous controller. The sampled, saturated transient can behave differently. Positive displayed margins alone do not certify stability or robustness to unmodeled dynamics. First-order Padé poles can be inaccurate near delay-dominated instability; use exact-delay frequency analysis and the sampled response together. No-crossing messages apply only to the chosen frequency range. Peak sensitivity may miss a very narrow peak.

Resolve the fastest plant, controller and closed-loop time scales, as well as the derivative filter. Warnings request a smaller controller sample period. Increasing the interval count or shortening the duration changes that sample period and therefore changes the simulated controller. Repeat with twice as many intervals when checking convergence toward the continuous design. A sample-and-hold command is assumed, with zero-order-hold plant evolution; continuous-controller reference values differ slightly at finite sampling. The simulation stops filling new dynamic states if the output exceeds 10⁸ p.u., and explicitly warns before that display limit.

Overshoot, rise and settling are measured relative to the requested step, not the observed final value. A −1 s timing value in the calculation details means the threshold or settling criterion was not achieved within the observation interval. Metrics before a disturbance cannot show later disturbance rejection. The final error and IAE cover the whole run.

The CTMS university mirror labels inertia with an erroneous /s² in one list. This tool uses kg·m², consistent with inertia dimensions and the source's MATLAB model. Settings are starting points for model studies and commissioning analysis; validate against the actual plant and controller implementation.

The exact-model scalar margin search is limited to 999 phase-crossing candidates per selected frequency range; narrow the range if prompted. Positive scalar margins may coexist with an unstable feedback loop, especially with multiple crossings. No Nyquist winding count or disk-margin analysis is performed. The full phase plot can span many delay rotations; choose a crossover-detail view to inspect a particular margin.

References

  • Skogestad, S. (2003), Simple analytic rules for model reduction and PID controller tuning, Journal of Process Control 13, 291–309. DOI: https://doi.org/10.1016/S0959-1524(02)00062-8. Author manuscript: https://skoge.folk.ntnu.no/publications/2003/tuningPID/finalpaper.pdf
  • Åström, K. J. and Murray, R. M., Feedback Systems, PID Control chapter, Table 11.1 (author-hosted 2019 chapter): https://www.cds.caltech.edu/~murray/books/AM05/pdf/fbs-pid_01Jan19.pdf
  • Control Tutorials for MATLAB and Simulink, DC Motor Speed Modeling, university mirror: https://www.ece.ualberta.ca/~tchen/ctm/examples/motor/motor.html ; current tutorial: https://ctms.engin.umich.edu/CTMS/index.php?example=MotorSpeed&section=SystemModeling
  • MathWorks, margin: negative-real-axis crossings modulo 360° and selection of gain and phase margins closest to zero. https://www.mathworks.com/help/control/ref/dynamicsystem.margin.html

Inputs

InputSymbolUnitDefault
Plant modelmodelFirst order plus dead time
Process DC gain
Output per input, both normalized.
K_proc1
Process time constantT_procs4
Natural angular frequencyw_nrad/s2
Damping ratiozeta_p0.5
Transport delay
Use zero for a delay-free model. Applied to the plant input.
theta_ds1
Motor mechanical unitsmotor_unitsSI: kg·m² and N·m·s
Rotor inertiaJ_rotkg*m^20.01
Viscous frictionb_rotN*m*s0.1
Rotor inertia (US)J_uslbm*ft^20.237304
Viscous friction (US)b_uslbf*ft*s0.07375621493
Torque constantK_tN*m/A0.01
Back EMF constantK_eV*s0.01
Armature resistanceR_armohm1
Armature inductanceL_armH0.5
Voltage for 1 p.u. command
Actuator limits multiply this voltage.
V_baseV12
Speed for 1 p.u. output
Setpoint and output multiply this speed.
W_baserad/s1
Tuning methodtuningSIMC PI (Skogestad 2003)
SIMC response time
Larger values give gentler control; start at the transport delay.
lambda_cs1
Proportional gain
Parallel form: u = Kp e + Ki integral(e) − Kd filtered dy/dt.
Kp_manual2
Integral gain
Parallel form: u = Kp e + Ki integral(e) − Kd filtered dy/dt.
Ki_manual1/s0.5
Derivative gain
Parallel form: u = Kp e + Ki integral(e) − Kd filtered dy/dt.
Kd_manuals0.1
Derivative filter time
First-order filter; derivative acts on measurement, avoiding setpoint kick.
T_filters0.1
Conditional integral anti-windup
Freeze integration only when saturation and error would drive it farther into saturation.
antiwinduptrue
Minimum commandu_minp.u.-3
Maximum commandu_maxp.u.3
Setpoint step
Applied at t = 0; initial plant and controller states are zero.
r_stepp.u.1
Plant-input disturbance step
Added after actuator saturation, before transport delay.
d_stepp.u.0
Disturbance timet_loads15
Simulation duration
At a fixed interval count, changing duration also changes the controller sample period.
T_spans30
Phase view
Detail views keep the delay phase readable near a selected crossover. The full view retains every delay rotation.
phase_viewPhase-margin crossover detail
Controller sample intervals
Sample period = duration / intervals. Changing this count changes the simulated controller sample period. Double it to check convergence toward the continuous design.
N_samples1500
Bode start frequencyw_lowrad/s0.001
Bode end frequencyw_highrad/s100
Root locus axis half-span
Poles outside this square are omitted; enlarge to inspect fast modes.
pole_span1/s4
Playback through response
Play moves the marker over the precomputed response.
playhead0.12

Results

With the default inputs above, the calc gives:

ResultValue
Proportional gain2
Integral gain0.5 1/s
Derivative gain0 s
Setpoint overshoot4.235 %
10–90% rise time1.9 s
2% settling time6.08 s
Full-window absolute error integral2.1736 s
Final tracking error0 p.u.
Continuous phase margin61.35° at 0.5 rad/s
Continuous gain margin9.943 dB at 1.571 rad/s
Peak sensitivity in frequency range1.59
Rightmost pole: Padé if delayed-0.25 1/s
Current poles outside locus display0

Checked against sources

Each case below was calculated by this calc and agrees with the value from its source (within the tolerance where one is shown).

Skogestad Table 2: FOPDT robustness

Source: Skogestad (2003), Table 2, journal p. 297 (attached PDF p. 7), first-order column with integral time equal to the plant lag. Values are published rounded margins for exact delay and PI, not Padé pole predictions. DOI:10.1016/S0959-1524(02)00062-8.

Inputs: the default inputs above.

ResultSourceThis calc
Linear gain margin3.14 ± 0.0153.142
Limiting signed phase margin closest to zero61.4 ± 0.12 deg61.352 deg
Peak sensitivity in frequency range1.59 ± 0.0151.59
Frequency of limiting phase margin; zero if unavailable0.5 ± 0.002 rad/s0.5 rad/s

Skogestad Table 3 case 5: setpoint IAE

Source: Skogestad (2003), Table 3 case 5, journal p. 298 (attached PDF p. 8): G(s)=exp(−s)/(4s+1), SIMC gain 2, integral time 4, setpoint IAE=2.17. Only the setpoint experiment is compared; the paper's separate load step at t=20 is disabled here. Finite sampling and a finite 30 s horizon explain the small difference.

Inputs: Minimum command = -100 p.u.; Maximum command = 100 p.u.; the others as above.

ResultSourceThis calc
Proportional gain22
Equivalent integral time; minus one means disabled4 s4 s
Full-window absolute error integral2.17 ± 0.025 s2.174 s

CTMS motor: unit-voltage steady speed

Source: CTMS, DC Motor Speed Modeling, university mirror: https://www.ece.ualberta.ca/~tchen/ctm/examples/motor/motor.html, open-loop example reports about 0.1 rad/s for 1 V. Its inertia list incorrectly prints kg·m²/s²; inertia must be kg·m², consistent with J=0.01 in its MATLAB code. Exact DC gain is 0.0999001, so tolerance allows the source rounding. Controller saturation in this case does not affect the separate open-loop curve.

Inputs: Plant model = DC motor speed; Transport delay = 0 s; Voltage for 1 p.u. command = 1 V; Simulation duration = 10 s; Controller sample intervals = 1,000; the others as above.

ResultSourceThis calc
Normalized plant DC gain0.1 ± 2 × 10⁻⁴0.0999
Open-loop response to the same input step [1001]0.1 ± 2 × 10⁻⁴ p.u.0.0999 p.u.

CTMS motor: same case in US mechanical units

Source: Same CTMS unit-voltage example as ctms_motor, with 0.01 kg·m² and 0.1 N·m·s converted to lbm·ft² and lbf·ft·s. https://www.ece.ualberta.ca/~tchen/ctm/examples/motor/motor.html. This checks that mechanical unit selection preserves the published response.

Inputs: Plant model = DC motor speed; Motor mechanical units = US: lbm·ft² and lbf·ft·s; Transport delay = 0 s; Voltage for 1 p.u. command = 1 V; Simulation duration = 10 s; Controller sample intervals = 1,000; the others as above.

ResultSourceThis calc
Normalized plant DC gain0.1 ± 2 × 10⁻⁴0.0999
Open-loop response to the same input step [1001]0.1 ± 2 × 10⁻⁴ p.u.0.0999 p.u.

Regression: phase branch with sweep starting above resonance

Source: Independent reviewer supplied −73.87° for this pure-integral second-order loop. Independently confirmed using SciPy brentq on |L(jw)|−1 and NumPy phase unwrapping anchored at 10⁻⁸ rad/s: PM=−73.8727503829°, w=7.45347656066 rad/s. Same benchmark as phase_anchor_low; frequency bounds must not shift the phase branch by 360°. Margin convention: https://www.mathworks.com/help/control/ref/dynamicsystem.margin.html.

Inputs: Plant model = Second order; Transport delay = 0 s; Proportional gain = 0; Integral gain = 100 1/s; Derivative gain = 0 s; Bode start frequency = 3 rad/s; the others as above.

ResultSourceThis calc
Limiting signed phase margin closest to zero-73.873 deg-73.873 deg
Frequency of limiting phase margin; zero if unavailable7.453 rad/s7.453 rad/s

Regression: same phase branch with sweep starting below resonance

Source: Independent review benchmark and independent SciPy/NumPy check, as phase_anchor_high. The only changed input is the lower Bode bound. Expected PM=−73.8727503829° and crossover=7.45347656066 rad/s. https://www.mathworks.com/help/control/ref/dynamicsystem.margin.html.

Inputs: Plant model = Second order; Transport delay = 0 s; Proportional gain = 0; Integral gain = 100 1/s; Derivative gain = 0 s; the others as above.

ResultSourceThis calc
Limiting signed phase margin closest to zero-73.873 deg-73.873 deg
Frequency of limiting phase margin; zero if unavailable7.453 rad/s7.453 rad/s

Regression: limiting gain margin at −540° crossing

Source: Independent reviewer supplied GM=5.731 dB at 1.06761 rad/s for this model. Independently confirmed with SciPy brentq on Im L(jw)=0, retaining Re L<0 and selecting the margin closest to 0 dB: 5.73114950606 dB at 1.06761069219 rad/s. The crossing has phase −540°; using only the first −180° crossing incorrectly gives 13.733 dB. Definition: https://www.mathworks.com/help/control/ref/dynamicsystem.margin.html.

Inputs: Plant model = Second order; Natural angular frequency = 1 rad/s; Damping ratio = 0.05; Transport delay = 7.5 s; Proportional gain = 0.03; Integral gain = 0.05 1/s; Derivative gain = 0.12 s; the others as above.

ResultSourceThis calc
Limiting signed gain margin closest to zero dB5.731 dB5.731 dB
Frequency of limiting gain margin; zero if unavailable1.068 rad/s1.068 rad/s

Regression: fast SIMC controller requests sample-period refinement

Source: Independent review, 2026-10-25: with theta=0, SIMC lambda=0.01 s, 30 s duration and 1500 intervals (sample period 0.02 s), the response alternates near 0.012 and 1.988; 3000 intervals settles. The required behavior is to request refinement, coded as 1. This checks the review's explicit warning requirement, not an independent physical reference value.

Inputs: Transport delay = 0 s; SIMC response time = 0.01 s; Minimum command = -1,000 p.u.; Maximum command = 1,000 p.u.; Bode end frequency = 10,000 rad/s; the others as above.

ResultSourceThis calc
Controller sample-period refinement requested11

Related Resources

Responses

Your email address will not be published. Required fields are marked *

L ading...