Control Systems

Servo Motor Control

A motor, an encoder, and three nested feedback loops — the architecture that hits micron positioning on a CNC, repeatable robot trajectories on a factory floor, and silky-smooth gimbal stabilisation in your camera.

A servo motor is a motor plus a position sensor plus a drive that closes nested loops on position, velocity, and current. Each loop runs at 5-10x the bandwidth of the loop outside it — position at 50-500 Hz, velocity at 1-3 kHz, current at 5-20 kHz. Field-Oriented Control with Clarke and Park transforms reduces a three-phase brushless motor to a decoupled torque source, exactly like a brushed DC motor was a century ago — but without the brushes.

  • Loop structurePosition → Velocity → Current
  • Bandwidth rule5-10x per layer
  • Position loop50-500 Hz
  • Current loop5-20 kHz
  • Standard controlFOC (Clarke + Park)

Interactive visualization

Press play, or step through manually. The visualization is yours to drive — try it before reading on.

Open visualization fullscreen ↗

Watch the 60-second explainer

A condensed visual walkthrough — narrated, captioned, under a minute.

What turns a motor into a servo

"Servo motor" is one of those phrases the marketing department mangled. The motor in a servo system is rarely special — it is a brushless permanent-magnet machine that, on its own, would be perfectly happy in a drone or an electric scooter. What makes the whole thing a servo is the rest of the package: a position sensor rigidly coupled to the shaft, a drive that switches power to the windings, and software running inside the drive that takes the difference between commanded position and measured position and corrects the output thousands of times per second.

An open-loop motor obeys a command. A servo obeys a specification. You tell it "be at angle 1.5708 radians" and it gets there and stays there, against gravity, against cutting forces, against an arm wrestling it. The cost of that obedience is the entire control architecture below.

The cascade — three loops, not one

The standard servo controller has the same shape in every brand, every industry, every decade since the 1970s: three nested PI (or PID) regulators arranged so that the output of each one becomes the setpoint of the next.

position cmd → [ Pos Ctrl ] → velocity cmd → [ Vel Ctrl ] → torque cmd → [ Cur Ctrl ] → PWM → motor
                     ↑                              ↑                          ↑
              position fb                      velocity fb                  current fb
              (encoder)                       (diff encoder)             (shunt / hall)

Why this shape? Because you can tune it. A single monolithic controller that takes position error and produces PWM duty cycle would have to compensate for electrical dynamics (the R/L time constant of the windings), mechanical dynamics (the J/B time constant of the rotor and load), nonlinearities (back-EMF, magnetic saturation, friction), and disturbances (cutting forces, gravity, payload changes) all in one pile of gains. It is a control engineer's nightmare.

The cascade splits the problem into three tractable pieces. The innermost current loop hides the electrical time constant — once it is closed, the motor looks like a pure torque-producing actuator. The middle velocity loop sees an integrator (torque integrates to velocity through inertia) and is easy to tune. The outer position loop sees another integrator and ends up as essentially a proportional gain with feed-forward. Each layer has one well-understood plant to compensate, and disturbances inside an inner loop get rejected long before they propagate outward.

Why each loop must be 5-10x faster than the one above

An outer loop is designed under the assumption that the loop nested inside it responds instantly. This is a lie — every closed loop has finite bandwidth — but it is a useful lie if the inner-loop bandwidth is high enough that the outer-loop designer can ignore its dynamics. The rule of thumb is that the inner-loop bandwidth should be 5-10 times the outer-loop bandwidth. Below 5x and the inner loop's phase lag eats into the outer loop's stability margin; above 10x and you are throwing away CPU and PWM cycles you didn't need.

LoopBandwidth (typical)Update rateJob
Position50 – 500 Hz1 – 8 kHzTrack trajectory commands; reject low-frequency load disturbances
Velocity500 Hz – 3 kHz4 – 16 kHzReject torque disturbances; damp mechanical resonances
Current (torque)1 – 3 kHz10 – 32 kHz (PWM)Track torque setpoint; reject back-EMF; protect IGBTs

The numbers in the rightmost column also constrain the PWM frequency — the current loop usually updates once per PWM cycle, so you need 10-20 kHz switching to get a 1-3 kHz current bandwidth.

The control law itself — PI is enough most of the time

Inside each loop sits a PI or PID regulator. In its simplest discrete form, the PI computation is just two multiplies and an add per axis per cycle.

// Inside a PI current regulator — runs at the PWM rate (e.g. 16 kHz)
err   = Iq_ref - Iq_meas;        // error in q-axis current
integ = integ + err * dt;        // integrator accumulator (with anti-windup)
Vq    = Kp * err + Ki * integ;   // commanded q-axis voltage

Most servo loops are PI rather than PID — derivative is suppressed because it amplifies noise from the encoder and from current measurement shunts. Derivative is sometimes added on the position loop using a feed-forward velocity term, which gives the benefits of D-action without sampling-noise problems. Modern drives layer on notch filters (to suppress mechanical resonances), feed-forward terms (to anticipate trajectory acceleration), and gain scheduling (to change gains as a function of speed or load) — but the kernel is always the same nested PI structure.

Field-Oriented Control — making AC behave like DC

The hardest piece of the cascade is the current loop, because the motor it is talking to is a three-phase AC machine and the currents flowing in the windings are sinusoidal — phased 120° apart — at a frequency that depends on rotor speed. You can't regulate a moving sinusoid with a PI controller; PI is designed to drive DC errors to zero.

The trick, first developed by Felix Blaschke at Siemens in 1969 and now universal under the name Field-Oriented Control, is to mathematically rotate the reference frame so that what was three time-varying sinusoids becomes two DC quantities. Two transforms do the work.

// CLARKE — three-phase (a, b, c) → two-phase stationary (α, β)
I_α = I_a
I_β = (I_a + 2 I_b) / √3

// PARK — two-phase stationary (α, β) → two-phase rotating (d, q) at rotor angle θ
I_d =  I_α cos(θ) + I_β sin(θ)
I_q = -I_α sin(θ) + I_β cos(θ)

In the d-q frame, sinusoidal stator currents become two DC values: I_d aligned with the rotor magnetic field (flux-producing) and I_q perpendicular to it (torque-producing). They are decoupled — exactly like the field winding and armature winding of an old brushed DC motor. You then regulate each one with its own PI loop, run the answer back through inverse Park and inverse Clarke, and feed the result to space-vector PWM (SVPWM) to drive the inverter.

On a surface-mount PMSM you normally hold I_d = 0 (no flux weakening) and let I_q be your torque command. Above base speed you can drive I_d negative to weaken the magnetic flux and extend the speed range at constant power — this is how Tesla's traction inverters reach 18,000 rpm.

Trapezoidal versus sinusoidal commutation

Before FOC was cheap enough for every drive, brushless motors were commutated in a simpler way called trapezoidal or six-step. The drive watched three Hall sensors on the rotor and energised pairs of phases in one of six discrete patterns per electrical revolution. It's simple, requires almost no math, and is still common in low-cost BLDC ESCs for drones and e-bikes. The downside is torque ripple — you can hear and feel a slight cogging at low speed.

Sinusoidal commutation drives all three phases simultaneously with smooth, time-shifted sinusoidal currents, and FOC is the most sophisticated form: closed-loop in the d-q frame so the currents are clean sinusoids in the stator frame even under heavy load. Modern servo drives are almost exclusively FOC; trapezoidal commutation has been pushed down into low-cost speed-control applications where smoothness doesn't matter.

Motor types — which one ends up in which job

TypeConstructionProsConsWhere it ends up
BLDC / PMSMPermanent magnets on rotor, three-phase stator windingsHighest torque density, low rotor losses, smooth with FOCNeeds encoder + drive; magnets are expensiveCNC, robot arms, EV traction, drones, gimbals
AC inductionSquirrel-cage rotor, three-phase statorCheap, rugged, no magnets, fault tolerantSlip-based control is messier; lower torque densityIndustrial pumps, fans, some EV traction (early Teslas)
StepperHigh pole count, no encoder; driven open-loop in micro-stepsCheap, simple, positions without feedback for light loadsLoses steps under overload; constant power draw at standstill3D printers, low-cost positioning stages, CNC routers
Brushed DCCommutator + brushes on rotor, field on statorTrivially driven by linear amp or H-bridge; native decouplingBrush wear, commutator arcing, low lifeLegacy retrofits, very low-power motion (RC servos)
Switched reluctanceSalient pole stator + rotor, no magnets, no windings on rotorCheap, robust, no magnets, very wide speed rangeAcoustic noise, torque ripple, complex controlSome traction drives, white goods, niche aerospace

For modern precision motion the answer is almost always a permanent-magnet brushless motor with absolute encoder and FOC. Steppers survive because they are unbelievably cheap and "good enough" for 3D printers; induction survives because some applications (heavy traction, hot environments, no-magnet supply constraints) reward its ruggedness more than its torque density.

Encoders and resolvers — telling the drive where the shaft is

FOC needs an accurate, fast rotor angle to do its Park transform. The position loop needs a long-term-stable absolute angle so the robot wakes up knowing where its joints are. The velocity loop wants smooth differentiation of position — which is hard if the position signal is noisy or coarsely quantised.

  • Incremental optical encoder. A glass disk with thousands of radial lines, two photo-detectors offset by a quarter pitch produce quadrature square waves (A and B). Counting transitions gives position to 4× the line count per revolution. An index pulse Z fires once per rev for homing. Resolution from 1024 to 5,000,000 counts/rev. Cheap (a few dollars) at low resolution; expensive at high resolution.
  • Absolute optical encoder. Multiple coded tracks (Gray code or pseudo-random) produce a digital word that uniquely identifies the shaft angle without needing a power-on home routine. Multi-turn variants count revolutions either with a geared mechanical counter (always works) or a battery-backed cycle counter (cheaper, lasts ~10 years). Serial protocols: SSI, BiSS-C, EnDat 2.2.
  • Magnetic encoder. Hall-effect or magnetoresistive sensors read a multipole magnet on the shaft. Cheaper than optical, more robust to oil and dust, but lower resolution (~12-14 bit per revolution).
  • Resolver. An analog rotary transformer. The drive excites a primary winding on the rotor with a high-frequency carrier; two secondary stator windings 90° apart return sine and cosine envelopes of the shaft angle. Resolver-to-digital converter chips extract the angle. Resolvers are temperature-stable, EMI-tolerant, oil-tolerant, and have no rotating electronics — which is why Tesla, military aircraft, and traction inverters use them.
  • Capacitive / inductive encoders. Newer technology that hits 22-26 bits of absolute resolution without optics, popular on premium collaborative robots.

How a quadrature signal actually works

The two-channel A/B output of an incremental encoder is the smallest unit of position sensing in the entire field, and it is worth a paragraph.

A: ¯¯|__|¯¯|__|¯¯|__|¯¯|__
B: ___|¯¯|__|¯¯|__|¯¯|__|¯       (B lags A by 90° → forward rotation)

A: ¯¯|__|¯¯|__|¯¯|__|¯¯|__
B: ¯¯|__|¯¯|__|¯¯|__|¯¯|__       (B leads A by 90° → reverse rotation)

A simple state machine watches the four possible (A, B) combinations as the disk rotates: 00 → 10 → 11 → 01 → 00 for one direction; 00 → 01 → 11 → 10 → 00 for the other. Each transition increments or decrements a counter. With 4× counting you get four position counts per encoder line — a 2,500-line encoder becomes a 10,000-count-per-revolution position reference. Add an index pulse Z and you can absolutely locate the shaft after one revolution post power-on.

Where servos live in the real world

  • CNC machine tools. Three to five axes of high-resolution servo-positioned ballscrews carry a spinning cutting tool through metal. Tolerances of 5-10 microns on a Haas mill; sub-micron on a precision grinder. Each axis is a closed-loop servo following an interpolated trajectory generated by the CNC controller.
  • Industrial robot arms. Universal Robots, KUKA, Fanuc, ABB, Yaskawa — every joint is a brushless servo with absolute multi-turn encoder, harmonic drive or cycloidal reducer, and FOC-based torque control. Six axes coordinate to follow Cartesian trajectories with repeatability under 0.1 mm.
  • Collaborative robots (cobots). UR-style cobots add joint-torque sensing so the arm can detect collisions and back off, plus impedance control that makes the arm feel compliant. The underlying servo architecture is unchanged; the outer behaviour layer is what changes.
  • EV traction. A Tesla Model 3 motor is a three-phase permanent-magnet brushless machine (PMSM) driven by a silicon-carbide inverter running FOC at ~20 kHz, with a resolver providing rotor angle. The drive's torque command comes from the accelerator pedal via the vehicle dynamics controller. Same architecture as a servo amplifier, just at 400 kW instead of 400 W.
  • Camera gimbals. DJI Ronin and Zhiyun stabilisers use three brushless gimbal motors with low cogging torque and high-resolution magnetic encoders. Outer loops take orientation from an IMU and command angular position; inner FOC loops produce the smooth torque that keeps the camera level to fractions of a degree as the operator runs over uneven ground.
  • 3D printer steppers. The exception. Steppers position open-loop because cost matters more than precision and the loads are light. Higher-end machines (Voron, Prusa MK4) add closed-loop encoder pairs to upgrade steppers into "closed-loop servos" without changing the motor itself.
  • Aerospace flight controls. Fly-by-wire actuators use redundant servo channels with resolver feedback and triple-modular voting. The same cascaded position-velocity-torque architecture; just hardened for vibration, temperature, and single-point-failure tolerance.

Tuning a real servo loop — what auto-tune does for you

Manual tuning a servo is straightforward but tedious. You usually start at the innermost loop and work outward.

  1. Current loop. Apply a step torque command with the motor mechanically locked. Adjust Kp and Ki until the current step response settles in roughly 1-2 ms with under 10% overshoot. Most drives compute Kp, Ki from measured winding inductance L and resistance R: Kp = L ωBW, Ki = R ωBW, where ωBW is the target current-loop bandwidth in rad/s.
  2. Velocity loop. Free the shaft. Step the velocity setpoint and increase the proportional gain until the response is fast without ringing. Add integral until steady-state error vanishes. If the mechanical resonance starts to whistle, drop in a notch filter at the resonance frequency.
  3. Position loop. Run a step or trapezoidal-velocity move. Tune Kp for fast settling without overshoot. Velocity feed-forward (commanded velocity injected as a setpoint into the velocity loop) drastically reduces following error on smooth trajectories.

Most modern drives include an auto-tune routine that injects a frequency sweep into the motor, measures the closed-loop response, identifies the inertia and resonance frequencies, and computes gains automatically. Yaskawa, ABB, Beckhoff, Allen-Bradley, and others all ship competent auto-tune for off-the-shelf motor + load combinations.

Common pitfalls

  • Forgetting the 5-10x bandwidth rule. Tuning the position loop fast and leaving the velocity loop slow guarantees oscillation. The cascade is only stable when each inner loop is decisively faster than the loop outside it.
  • Integral windup on the velocity loop. When the position loop demands a large velocity and the velocity-loop integrator builds up bias against a current limit, the system overshoots wildly when the limit clears. Anti-windup (clamp integrator when actuator saturates) is mandatory.
  • Encoder mounting flex. A high-resolution encoder bolted to a flexible coupling between motor and load reports phantom oscillations as the load winds the coupling up and down. Either rigid coupling, or two encoders (motor-side for the velocity loop, load-side for the position loop) — that latter trick is called "full closed-loop" in CNC.
  • FOC angle error. Park transform with the wrong rotor angle quietly destroys torque output. A 30° angle error costs roughly 13% of torque (cos 30° = 0.866); 60° costs half. Index alignment, encoder offset calibration, and rotor magnetic pole position detection are pre-flight checklist items.
  • Cable-induced quadrature errors. Long encoder cables pick up noise and cause spurious A/B transitions that look like motion in both directions. Differential RS-422 line drivers and twisted-pair-shielded cabling prevent this; single-ended TTL over 5 metres of motor cable does not.
  • Treating a stepper as a servo. Steppers without encoders lose steps under overload and silently mis-position. They are not closed-loop. Adding an encoder converts them into a kind of servo, but the cogging torque ripple of a stepper is enormous compared to a PMSM, so the resulting "servo" is still no match for a real one.

Frequently asked questions

What makes a motor a servo motor?

Three ingredients in one package: an electric motor, a position sensor mounted on its shaft (encoder, resolver, or Hall set), and a drive that closes feedback loops on position, velocity, and current. A motor on its own is open-loop — you give it voltage and it spins. A servo system measures where the shaft actually is, computes the error against where you wanted it, and corrects the drive output thousands of times per second. The same physical motor can be a servo or not depending entirely on whether the loops are closed around it.

Why is the control structure cascaded — three loops instead of one?

A direct position-to-voltage controller would have to compensate for the motor's electrical dynamics, mechanical dynamics, and load dynamics all in one tuning. Cascade splits the problem. The innermost current loop hides the electrical time constant (R/L) and turns the motor into a pure torque source. The velocity loop then sees an integrator (acceleration to speed) and is easy to tune. The outermost position loop sees another integrator (speed to position) and becomes essentially a proportional gain plus feed-forward. Each layer handles a slower dynamic, and disturbances inside an inner loop get rejected long before they reach the outer one.

Why does each loop need to be 5 to 10x faster than the one outside it?

An outer loop treats the closed inner loop as if it were instantaneous. That approximation only holds when the inner loop's bandwidth is much higher than the outer loop's, otherwise the outer controller starts fighting the inner one's lag and the cascade oscillates. The 5-10x rule of thumb keeps the phase contribution of the inner loop below about 10 degrees inside the outer crossover, which is enough margin for robust tuning. Typical numbers: 100 Hz position, 1 kHz velocity, 10 kHz current — exactly one decade between each.

What does Field-Oriented Control actually do?

FOC projects the three-phase stator currents into a rotating frame fixed to the rotor. The Clarke transform first collapses three phase currents into two equivalent stationary-frame currents (α, β). The Park transform then rotates that into the rotor-aligned d-q frame using the measured rotor angle. In the d-q frame the d component sets magnetic flux and the q component sets torque — they're decoupled, just like the field and armature of a brushed DC motor. Two PI regulators on Id and Iq, then inverse Park and inverse Clarke, then space-vector PWM — and you get smooth, full-torque control at any speed.

Why use a brushless motor instead of stepper or induction?

Stepper motors are open-loop and position themselves by counting commanded steps; they're cheap and simple but lose steps under load and dissipate heat even at rest. Induction motors are robust and cheap but need sophisticated slip-compensation algorithms and don't reach the same torque density. Permanent-magnet brushless machines (BLDC and PMSM are the same hardware in practice, differing only in commutation strategy) give the highest torque per amp, the lowest rotor losses, and smooth low-speed behaviour when driven with FOC. That's why CNCs, robots, and EVs converged on them.

What is the difference between incremental and absolute encoders?

Incremental encoders output two square waves (A and B channels) in quadrature so the drive can count edges and infer direction. Position is relative — the count resets at power-on unless an index pulse and a homing routine establish a reference. Absolute encoders output the unique position of the shaft as a digital word, transmitted over a serial protocol like SSI, BiSS-C, or EnDat. Multi-turn absolute encoders also remember how many revolutions have happened, using a geared mechanical counter or a battery-backed cycle counter. Robot joints almost always use absolute multi-turn encoders so the arm wakes up knowing exactly where it is.

What is a resolver and why do EVs and aerospace use them?

A resolver is essentially a rotary transformer. It has a primary winding on the rotor and two secondary windings on the stator wound 90° apart. Excite the rotor with a high-frequency carrier and the two stator windings return sine and cosine envelopes of the shaft angle. Resolvers are entirely analog, tolerate enormous temperature swings, vibration, oil, and EMI, and have no electronics on the rotating part to fail. Tesla, military aircraft, and traction inverters on heavy industrial machines use resolvers for that ruggedness, paying for it in dedicated resolver-to-digital converter hardware on the drive side.

How fast does a servo drive actually have to run its current loop?

The current loop bandwidth has to be high enough that the closed-loop electrical dynamics look fast compared to the mechanical bandwidth you want. Typical PWM switching frequencies are 10-20 kHz, and the current control loop runs at the PWM rate (one regulator update per PWM cycle). That gives a closed-current-loop bandwidth of roughly 1-2 kHz for the actual torque response — about one decade below the sampling rate. Inverter-fed traction drives push toward 20 kHz PWM and several-kHz current bandwidth; precision motion stages can run 32 kHz PWM and beyond.