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?
While the output is clipped, the error stays large and the integrator keeps growing, though none of it reaches the motor. When the speed finally approaches the target, the stored integral holds the current high and the speed overshoots: 16.9% here, against 5.2% with conditional integration, which simply stops integrating while the output is clipped.
Name it
The model
With :
Current control
PI regulators with and cancel each axis's electrical pole , leaving a first-order closed loop of bandwidth . Adding the decoupling terms to and to 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 with . A PI with sets a bandwidth near , and its zero at removes steady-state error under load. The current command is clipped to , and conditional integration freezes the integrator while it's clipped.
Worked example
What does the current step give, for a 50 A command with = 2π × 500 rad/s?
Show the solution
- Controller gains.
- q current. It rises as : 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 staying at zero.
- Torque. The torque follows: 0.6 N·m per ampere, 30 N·m at 50 A.
Answer with = 1.571 V/A and = 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
- Torque and acceleration at the limit. = 0.6 N·m/A, so 100 A gives 60 N·m and an acceleration of 6000 rad/s² on 0.01 kg·m².
- 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).
- Overshoot and settling. With conditional integration it overshoots by 5.2% and settles to within 0.01% by 0.3 s.
- 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?
In the rotor frame each axis's voltage equation contains a term from the other axis: the d equation has and the q equation has . These speed voltages grow with speed and couple the axes, so without help a change in disturbs and the back-EMF acts as a disturbance the q-axis PI must fight. The decoupling terms add exactly the opposite voltages to the controller's outputs, computed from the measured currents and speed. They cancel the coupling and the back-EMF inside the motor, leaving each axis as a plain R–L circuit driven by its own PI controller. Since that circuit doesn't depend on speed, neither does the closed-loop response.
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.