S950 of 55
0 XP
  1. Hook
  2. Predict
  3. Name it
  4. Check
  5. Explain

S9 · Lesson 50 · Control lab

Writing three tools every control engineer uses, a step-response simulator for any proper transfer function, a calculator for crossover frequencies and stability margins, and Ackermann's pole-placement formula, each checked against results from the lessons

Control toolboxes hide three routines that you've used by hand all course: simulate a transfer function's step response, find a loop's crossovers and margins, and compute the state-feedback gain that puts the poles where you want them. In this lab you'll write all three in NumPy and test them against numbers you already know: the 16.3% overshoot of ζ = 0.5, the 3× gain margin of 10/(s(s+1)(s+5)), and the servo gains of lesson 34.

Predict

Your margin calculator scans the phase of L(jω) for −180°. Why must it unwrap the phase first?

Name it

Simulating a transfer function

For b0sn+…+bnsn+a1sn−1+…+an, the controllable canonical form has x˙1=−a1x1−…−anxn+u and x˙i=xi−1, with output y=∑i(bi−b0ai)xi+b0u. A fixed-step RK4 integrator is accurate to about (ωΔt)4 per step, plenty for step responses with Δt a hundredth of the fastest time constant.

Margins

Evaluate L(jω) on a dense logarithmic grid, unwrap the phase, find the first sign change of |L|−1 and of ∠L+180°, and refine each by bisection. Report None when a crossing doesn't exist in the range.

Ackermann's formula

K=(0⋯01)Wr−1pd(A),Wr=(BAB⋯An−1B)

where pd(A) is the desired characteristic polynomial evaluated at the matrix A. np.poly(poles) gives the polynomial's coefficients from its roots.

Worked example

What should margins([10], [0.1, 1, 0]) return?

Show the solution
  1. Recognize the loop. That's 10/(s(0.1s+1)) from lesson 23.
  2. Gain crossover. It crosses over at 7.8615 rad/s with 51.83° of phase margin.
  3. Phase crossover. Its phase only approaches −180° as ω → ∞, so there's no phase crossover and no finite gain margin.

Answer (7.8615, 51.83, None, None).

Worked example

What does place return for the double integrator with poles at −2 and −3?

Show the solution
  1. Companion form. The desired polynomial is s2+5s+6 and the double integrator's is s2, so K=(6,5)
  2. Check with Ackermann's formula. Wr=(0110)pd(A)=A2+5A+6I=(6506)
  3. Read off K. The last row after Wr−1 is (6, 5), the same gain.

Answer K = (6, 5).

Check

Step 1. Write step_response(num, den, T, dt): the controllable canonical form integrated with RK4.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Step 2. Write margins(num, den): gain and phase crossovers, phase margin and gain margin.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Step 3. Write place(A, B, poles): Ackermann's formula.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does Ackermann's formula need the controllability matrix to be invertible?

Practice

Keep practicing

3 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.