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

S12 · Lesson 51 · PM motor drive project

Writing a permanent-magnet synchronous motor's dq model in Python, closing current loops with PI regulators and decoupling so the q current follows a first-order lag at any speed, and closing a speed loop with a current limit, comparing its step response with and without anti-windup

Every servo drive, electric-vehicle inverter and drone controller runs the same structure: fast inner loops that make the motor's dq currents follow their commands, and an outer loop that turns a speed or position error into a current command, limited to what the motor and inverter can stand. In this project you'll build that structure for an 8-pole surface PM motor, see why the decoupling terms make the current response independent of speed, and find out what happens to a speed loop when its current command saturates.

Predict

The speed loop's PI controller asks for more current than the 100 A limit while the motor accelerates. What does its integrator do if nothing stops it?

Name it

The model

With ω=P2ωm:

Lddiddt=vd−Rid+ωLqiq,Lqdiqdt=vq−Riq−ω(Ldid+λm)
Jdωmdt=32P2[λmiq+(Ld−Lq)idiq]−TL−Bωm

Current control

PI regulators with Kp=ωcL and Ki=ωcR cancel each axis's electrical pole R/L, leaving a first-order closed loop of bandwidth ωc. Adding the decoupling terms −ωLqiq to vd and +ω(Ldid+λm) to vq cancels the speed voltages, so the two axes become independent and identical at any speed.

Speed control

With the current loop fast enough to treat as ideal, the mechanical plant is Kt/(Js+B) with Kt=32P2λm. A PI with Kp=ωbJ/Kt sets a bandwidth near ωb, and its zero at ωb/5 removes steady-state error under load. The current command is clipped to ±Imax⁡, and conditional integration freezes the integrator while it's clipped.

Worked example

What does the current step give, for a 50 A command with ωc = 2π × 500 rad/s?

Show the solution
  1. Controller gains. Kp=2π×500×0.5mH=1.571V/AKi=2π×500×0.05=157.1V/(A·s)
  2. q current. It rises as 50(1−e−ωct): 31.6 A at one time constant (0.318 ms), 49.91 A after 2 ms, identically at standstill and at 200 rad/s, with id staying at zero.
  3. Torque. The torque follows: 0.6 N·m per ampere, 30 N·m at 50 A.

Answer with Kp = 1.571 V/A and Ki = 157.1 V/(A·s), the q current rises to 50 A with a 0.318 ms time constant (31.6 A at one time constant, 49.91 A after 2 ms), making 30 N·m.

Worked example

What does the speed step to 1000 rpm look like with a 100 A limit?

Show the solution
  1. Torque and acceleration at the limit. Kt = 0.6 N·m/A, so 100 A gives 60 N·m and an acceleration of 6000 rad/s² on 0.01 kg·m².
  2. The ramp. The motor ramps at the limit to 90% of 104.7 rad/s in 19.4 ms (15.7 ms if it held full current all the way; the controller starts backing off as it nears the target).
  3. Overshoot and settling. With conditional integration it overshoots by 5.2% and settles to within 0.01% by 0.3 s.
  4. Without anti-windup. The overshoot is 16.9%.

Answer a current-limited ramp at 6000 rad/s² that reaches 90% of 1000 rpm in 19.4 ms, overshoots by 5.2% and settles within 0.01% by 0.3 s (16.9% overshoot without anti-windup).

Check

Step 1. Write derivs(x, vd, vq, TL): the motor in the rotor frame.

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 current_step(iq_ref, wm): PI current loops with decoupling.

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 speed_step(n_ref): a current-limited speed loop with anti-windup.

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

Explain why

Why do the decoupling terms make the current loop's response the same at every speed?

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.