State-Space Models from Differential Equations
The speed loop of the small DC motor works in simulation, but on the bench the supply's current limit trips at every start. The transfer function from voltage to speed, , cannot warn you: the armature current is inside it, hidden. A second problem: a test rig has two heated zones on one aluminium plate, each with its own heater and sensor, and heating one zone warms the other. A single-input, single-output transfer function cannot describe two inputs that both move two outputs. Both problems are solved by the state-space model, which keeps every internal energy store visible and handles many inputs and outputs with the same matrix equations. It is also the starting point for the rest of this section: controllability and observability, pole placement, observers and LQR.
State, input, output
The state is the smallest set of variables whose present values, together with the future input, determine the future of the system. For physical systems a safe choice is one variable per independent energy store: capacitor voltages, inductor currents, positions and velocities of masses, temperatures of heat capacities, levels of tanks. A linear time-invariant system with states, inputs and outputs is
with (, the dynamics), (, how inputs push the states), (, what the sensors see) and (, direct feedthrough, usually zero for physical plants).
The link to the transfer function comes from the Laplace transform with zero initial state, :
(except for eigenvalues that cancel, which the next lesson explains). The free response is , the matrix exponential of Linear Algebra and Differential Equations; you will rarely compute it by hand, because simulation does it for you.
From differential equations to matrices
Physical states. Write one first-order equation per energy store and read off the matrices. The motor has two stores (armature inductance, rotor inertia), so two states, :
The derivation of these two equations is in Modelling a DC Motor.
Phase variables. An -th order ODE becomes a state model with , , …: the controllable canonical form, with ones on the superdiagonal of and the coefficients in its last row. ct.tf2ss produces a canonical form from a transfer function, but its states have no physical meaning, so prefer physical states whenever you can.
A state model is not unique: any invertible change of variables gives with the same transfer function and the same eigenvalues.
Worked example: the motor as a state model
Given: , , , , , a step.
Find: and , the poles, the final speed and the peak current.
Solve:
- (units mixed per entry), .
- Eigenvalues: , so and : a slow mechanical mode () and a fast electrical mode ().
- Steady state (): (), with .
- At the first instant the rotor is still, so there is no back-EMF: the current heads for and is only cut off by the rising speed. The simulation gives the peak.
Check: the transfer function from must have the DC gain .
import numpy as np
import control as ct
Ra, La, k, J, b = 2.0, 1e-3, 0.02, 2e-6, 1e-6
A = np.array([[-Ra / La, -k / La], [k / J, -b / J]])
B = np.array([[1 / La], [0.0]])
C = np.eye(2) # measure both states: current and speed
motor = ct.ss(A, B, C, 0)
print("eigenvalues of A (1/s):", np.round(np.linalg.eigvals(A).real, 1))
G = ct.ss2tf(ct.ss(A, B, [[0, 1]], 0)) # speed output only
num, den = G.num[0][0], G.den[0][0]
print("G(s) = " + f"{num[-1]:.4g} / (s^2 + {den[1]:.1f} s + {den[2]:.4g})")
print(f"DC gain {ct.dcgain(G):.2f} rad/s per V")
t = np.linspace(0, 0.1, 10001)
resp = ct.forced_response(motor, T=t, U=12.0 * np.ones_like(t))
i_a, w = resp.outputs
kpk = int(np.argmax(i_a))
print(f"12 V step: peak current {i_a[kpk]:.2f} A at {1e3 * t[kpk]:.2f} ms, "
f"final current {i_a[-1]:.3f} A, final speed {w[-1]:.1f} rad/s")eigenvalues of A (1/s): [-1894.4 -106.1]
G(s) = 1e+07 / (s^2 + 2000.5 s + 2.01e+05)
DC gain 49.75 rad/s per V
12 V step: peak current 5.34 A at 1.61 ms, final current 0.030 A, final speed 597.0 rad/s
The current peak of about is what tripped the supply. With the state model you can now put a limit on the current state itself: a current loop inside the speed loop (cascade control), or a state-feedback design that weighs current (LQR).
A multivariable system: two heated zones
The roadmap asks you to simulate a multivariable system. Take two zones on one plate, each with heat capacity , thermal resistance to the room and between them. With the temperature rises , as states and the heater powers , as inputs:
The steady-state gain matrix says how much each heater moves each temperature.
import numpy as np
import control as ct
Ch, R, R12 = 75.0, 8.0, 4.0
g, g12 = 1 / R, 1 / R12
A = np.array([[-(g + g12), g12], [g12, -(g + g12)]]) / Ch
B = np.eye(2) / Ch
plate = ct.ss(A, B, np.eye(2), 0)
K0 = -np.eye(2) @ np.linalg.solve(A, B)
print("DC gain matrix (K per W):")
print(np.round(K0, 3))
print("time constants (s):", np.round(np.sort(-1 / np.linalg.eigvals(A).real), 1))
t = np.linspace(0, 1800, 1801)
U = np.vstack([5.0 * np.ones_like(t), np.zeros_like(t)]) # 5 W in zone 1 only
y = ct.forced_response(plate, T=t, U=U).outputs
for ts in (60, 300, 1800):
print(f"t = {ts:4d} s: T1 = {y[0, ts]:5.2f} K, T2 = {y[1, ts]:5.2f} K")DC gain matrix (K per W):
[[4.8 3.2]
[3.2 4.8]]
time constants (s): [120. 600.]
t = 60 s: T1 = 3.48 K, T2 = 0.33 K
t = 300 s: T1 = 11.54 K, T2 = 4.20 K
t = 1800 s: T1 = 23.00 K, T2 = 15.00 K
Five watts in zone 1 alone lift zone 2 by more than half as much as zone 1 in the end: the off-diagonal gains are large, so two independent single-loop controllers will fight each other. The two time constants belong to two modes: both zones rising together (the slow mode, set by only) and the zones moving apart (the fast mode, which also uses the path ). Decoupling and multivariable design start from exactly this matrix picture.
Lab: a second-order circuit as a state model
A series RLC driven by a step has the states and . Its eigenvalues are with . With , , : , , , , overshoot . The lab shows exactly these: , , overshoot .
Raise to and the two complex eigenvalues meet on the real axis (); above that they split into two real modes, like the motor's.
Guided lab: measure the motor's two modes
Hand calculation. From the worked example: mechanical time constant , electrical , no-load speed at , start current peak . With a supply limited to , the start is current-limited: the speed ramps at about until the back-EMF takes over.
Simulation. Change U in the first program to a step (peak current ) and compare.
What you would measure. A small brushed motor (no load, shaft free) on a bench supply at , current limit ; a shunt in the return lead for the current, and an optical encoder or a second motor used as a tachogenerator for the speed. On a two-channel scope, the current jumps to roughly within a millisecond and decays with the mechanical time constant (expect for hobby motors: your and differ from the example); the speed rises with the same time constant. Brush noise adds ripple on the current trace, so fit the time constant to an averaged trace and expect uncertainty.
Hazards and safe setup. Clamp the motor; nothing on the shaft that can fly off; keep fingers and hair away; set the current limit before connecting; a stalled motor heats quickly, so keep stall tests to a second or two. Low voltage only.
Pitfalls
- Choosing derivatives of the input as states: if appears, rewrite the model (or use a canonical form) so that multiplies only.
- Forgetting that
ct.tf2ssgives a non-physical realisation; you cannot put a current limit on a state that is not a current. - Mixed units in : each entry has the unit of (row state per second) per (column state). Check them; a wrong power of ten in moves an eigenvalue by a factor of ten.
- Reading a MIMO plant as independent loops when the off-diagonal gains are large.
Practice
- A mass on a spring with damping is pushed by a force . Write , , for and output position , and give the eigenvalues.
- For the plate, what are the steady temperature rises with ?
- Why does the first column of the motor's step response (current) end near rather than zero?
Answer
- , , ; gives .
- Symmetric heating: the coupling carries no heat, each zone sees only : (the sum of the two columns of the gain matrix, , times ).
- Friction: at constant speed the motor still needs a torque , so .
Test yourself
Which variables make a good state vector for a physical system?
- the inputs and their derivatives
- one variable per independent energy store (capacitor voltage, inductor current, position, velocity, temperature)
- the outputs only
- the coefficients of the transfer function
The poles of are
- the eigenvalues of (apart from cancellations)
- the entries of
- the zeros of
- the eigenvalues of
Why does a 12 V step draw about 5 A from the small motor even though it runs at 0.03 A?
- the inductance stores energy
- at standstill there is no back-EMF, so only limits the current
- friction is highest at start
- the motor is unstable
In the two-zone plate, heating zone 1 alone with 5 W ends with
- only zone 1 warmer
- both zones warmer, zone 2 by a large fraction of zone 1's rise
- zone 2 cooler
- an unstable temperature