Proportional, integral, derivative (PID) position servo-loop tuning can be daunting. However, one simple technique works well for most systems.
Chuck Lewin • Founder and CEO | Performance Motion Devices Inc.
There are two types of servomotors commonly used for positioning motion control applications — the dc brush motor (which uses mechanical brushes to commutate the motor) and the brushless dc motor. The latter is also known as the BLDC motor or ac synchronous motor and is electronically commutated by external circuitry.

Unlike stepper motors that move in discrete position steps, servomotors don’t have a built-in sense of where they are so need feedback (as from an encoder) to control position. A position servo loop drives the motor to a given position. It does this by comparing the target position from the trajectory generator at any given moment with the actual motor position and applying a continuous correcting motor command.

Consider the control-flow diagram for a general-purpose positioning servomotor controller. A host specifies high-level commands such as move from point A to point B using this set of trajectory parameters … then the motion controller’s profile generator continuously generates a commanded position input to the position control loop, followed by a current control loop and amplifier.
Theorists and engineers have developed various servo-position control schemes, but the most common for motor positioning is the PID loop. Digital PID loop variations abound but are based on the simplified PID position loop.

A PID position loop is tuned by setting values for the proportional gain Kp, integral gain Ki, and derivative gain Kd which in turn determine their relative influence on the controller’s final output. In its basic form, the PID position loop only requires settings for these three parameters. That said, other commonly used settings are the integral limit, the derivative sample time, and feedforward gains.
PID filter essentials
In the PID position loop diagram the ‘loop’ part of the controller is the summing junction at which actual position is subtracted from commanded position to generate a position-error value. The PID part of the controller is actually a type of filter known (not surprisingly) as a PID filter. The PID filter takes as input a stream of position error values and generates as output a stream of commands to a current loop, or for some systems a velocity loop.

Tuning a position PID loop doesn’t require knowledge of how a PID filter is calculated, but the basic equation is shown below. This PID filter value (as well as its inputs) are updated and calculated at each servo loop update. Modern motion controllers operate with servo loop update rates anywhere from 1 to 80 kHz with 10 to 20 kHz typical for general-purpose small-motor controllers sized NEMA 17 through NEMA 34.
Outputn = Kp × En + Ki × sum(En) + Kd × (En – En – 1)
Where En = Current position error value; En-1 = Previous position error value; and Sum(En) is the sum of En values past and present.
A key reason that the PID position control loop is so widespread is that the effect of its constituent P, I, and D can be easily described and understood.
The P term is called the proportional term because it provides a proportional restoring correction to the amplifier output command. When presented with the position error the P term functions such as a spring. The larger the servo’s position error, the larger the corrective restoring motor command.
The I term is the integral (or integration) term because it integrates (over time) the servo position error. This is useful as a proportional term alone can’t arrive at the exact commanded position when subject to forces or mechanical issues such as gravity, stiction, and motor detents. The I term crescendos over time and can get the servo surmount to the final target position.
The contribution of the D term is calculated by subtracting the previous position error from the current position error. It provides a feedforward boost whenever the profile velocity increases or decreases, and it provides a general purpose drag term to damp oscillations.

Industry staple: Step-response tuning
The most common manual-tuning method to determine PID gain values is the step-response method or step response tuning. This approach leverages the reaction of the motor to an instantaneous (step) change in commanded position.
Manual tuning is relevant because many motion control vendors, in addition to auto-tuning tools, supply tools that help with manual tuning. After all, auto-tuners don’t always devise the best tuning values, and many auto-tuners don’t determine all the settings offered by a position loop. Of course, manually tuning a motor-driven axis is also a great way to get an intuitive feel for how changes to the P, I, and D gain values affect axis behavior.
To make step response tuning work, or for that matter any manual tuning method, we need a position trace facility to display the results of the moves. At a minimum we need to display a stream of captured values of the target position (commanded by the trajectory generator) and the actual position (as the motor’s measured location).
Consider the screencapture of such a facility — motion scope and trace software from one motion supplier. In fact, design engineers can use this software, similar products from other motion-control vendors, or even systems developed in-house.

Start with just the motor and go from there
Once the motion controller as well as the motion trace and display software tools are in place, the actual mechanical system that will be tuned should be added. For most engineers the goal is to determine PID gain parameters that will smoothly and accurately operate the machine with significant stability margin.

In fact, this can be more complicated than it sounds because the axis and attached mechanisms being tuned may involve variable loads and operating modes.
So engineers should consider the specific operating condition of for which the controlled mechanism will be tuned. Often servomotor-system tuning starts sans load or load mechanism. Tuning just the motor is a good first approach because from that baseline one can progressively add more realistic conditions. For example, after tuning just the motor one can connect the mechanism with no load, then one can add the minimum expected load to the mechanism, followed by the maximum expected load.
Having multiple PID settings for various mechanism configurations can also be useful in its own right. Many control systems apply different gain settings depending on the load or performance goal for a given operating mode. As we’ll explore, the PID gain settings that reach the highest end point positioning accuracy may be different than for those used to rapidly slew from one machine operating area to another.
Step-by-step PID-loop tuning procedure
With capture and display software in place with the mechanism to be optimized, tuning can happen in five steps.
Step 1 is to setup the motion-trace capture facility. Different terminology may apply according to the vendor but in PMD’s system one will set the trace capture system to trace Active Motor Command as the first variable, Commanded Position as the second variable, and actual position as the third variable. An optional fourth variable is position error, but defining this isn’t necessary for the procedure described here.
Step 2 is to setup the motion controller to make an ‘instantaneous’ step move from the current to a programmed destination position. Motion controllers from certain suppliers have a direct step-response mode that lets engineers simply enter the step distance. One caveat: The engineer may need to select a profiling mode (such as trapezoidal point-to-point) and program it with extremely large velocity and acceleration values, so the effective profile move time is close to zero.
One note when setting the step distance: During the step response move, the amplifier command shouldn’t go to 100%. Say the current limit for a given motor is 5.0 A and the controller is properly set so it doesn’t exceed that amplifier command value. Well, if the traced motor-current command reaches 5.0 A, the step distance should be lowered to prevent the servo output from being saturated.
Step 3 (for controllers with certain PID control settings) is to set the integral gain Ki, integral limit Ilim, acceleration feedforward gain Kaff, and velocity feedforward gain Kvff to zero. Proportional gain Kp is then set to a small value — perhaps 10 to 50 for motors with quadrature encoders. Then Kd (derivative gain) is set to a value fivefold the specified Kp value. Finally, for small motors such as NEMA-17 motors, set the initial derivative time to 0.25 mSec; for NEMA-23 motors, set to 1.0 mSec; and for NEMA 34 or larger set to 2.5 mSec.
Note that initial gain settings are controller-specific, engineers new to the controller will need to experiment. When in doubt, use lower values of Kp.
Step 4 is to execute the step move. This should quickly spur the trajectory generator (in a single instantaneous step) to command a move having the programmed step distance. Assuming the trace function has been synched to the move start, a trace scope window will then display data. Adjustments to the data capture and scope display may be needed to get the full trace of interest on a single screen.
Uncontrolled motor oscillations mean Kp should be set to a lower value and Step 4 repeated. If at any point there’s concern that the motor or power supply is over-stressed, the controller should be disabled. If the motor produces a high-pitched chatter or whine, KD derivative gain can be lowered or derivative time increased.
Step 5 is next once the position loop is at least somewhat stable. Then comes this repeating sequence:
- View the scope display to determine whether the response is underdamped, critically damped, or overdamped (as described below).
- Adjust the gain settings accordingly.
- Make another step move (as in Step 4).
The next three sections will show one how to characterize the step move response and how gain settings should be adjusted.
Underdamped servo response curve: Refer to the screencapture showing a typical underdamped response. The yellow trace shows that the commanded position instantly changes from a position of 0 to 100. With the software being used in this situation, this jump equals whatever the engineer entered into the step-response dialog box. The green trace shows the resultant motor location.
Though actual position does eventually settle to the commanded 100, it overshoots and oscillates several times. A system behaving this way is underdamped. To correct it, the design engineer should increase the derivative gain Kd.

Critically damped servo response curve: Now consider the screencapture of a plot of a critically damped response. In this trace the actual position doesn’t overshoot the commanded position, and it settles quickly (in 10 msec) to the commanded position of 100. Note that in these given trace displays, the unit of time is set to servo cycles. For the controller used in this setup, that’s 50 µsec per servo cycle.
It’s worth noting that many Kp and Kd combinations may spur a response that appears critically damped. In this manual tuning process, the distinction between critically damped and overdamped is somewhat subjective.

Overdamped servo response curve: Lastly consider a screencapture showing an overdamped response and compare it with the critically damped response. An overdamped system is stable but needlessly slow in its response to changes in the position command.
If the response is overdamped one should reduce Kd to the smallest value that still yields a critically damped response.

Following are links to videos that show simple underdamped, overdamped, and critically-damped motion for a no-load single motion axis responding to a step response command.
Video: Underdamped single motion axis
Video: Overdamped single-motion axis
Video: Critically damped single-motion axis
Setting the PID derivative sample time
The derivative time setting is powerful. Derivative time is the period over which the PID loop derivative contribution is calculated in units of servo cycles or in milliseconds depending on how the controller is programmed.
Increasing the derivative time can be useful for reducing axis ‘chatter’ by effectively introducing a low-pass filter on the PID loop’s control response. This in turn allows the effective Kd damping contribution to be increased. Again, depending on how the controller functions the impact of the Kd on the PID loop command output is a direct multiple of the derivative time. For example, if the derivative time is set to 10 and the Kd value is 100 this would be an equivalent derivative term impact as a derivative time of 5 and a Kd of 200.
Larger motors with larger loads will generally use higher derivative time settings and vice versa for smaller motors with smaller loads. Experimentation is the best way to determine what values of derivative time and Kd gain give the quietest critically damped response.
Arriving at the final gain settings of Kp and Kd
The main position-loop tuning goal is to set Kp as high as possible while still finding an associated Kd value capable of yielding a critically damped response. Higher Kp values will spur more accurate tracking and faster responses to command position changes.
Trying higher and higher Kp values makes it clear at a certain point there’s no value of Kd and derivative sample time that yields a stable and critically damped response. At this point one should reduce Kp by 35 to 50%, determine the associated Kd for critically damping, and use those settings as the final values for Kp, Kd, and derivative sampling time. Backing down from the ‘borderline’ Kp is key to stability, accommodating small controller and motor differences, allowing for attached hardware behavior, and handling system changes over time.
Setting the PID Ki gain and limit
Once Kp, Kd, and derivative time have been set, one can enter a value of Ki (integral gain) to improve tracking accuracy. It depends on the controller scaling but typically Ki settings are a tenth to half the Kp value. Smaller motors typically use relatively larger ratios, and larger motors with larger loads typically use smaller Ki ratios. Higher Ki settings increase tracking accuracy during and after the motor move is complete but can also reduce system stability. So, one should set Ki to the smallest value that can reach goals for tracking accuracy while not distorting the critically damped response the Kp and Kd settings created.
For most controllers the integral limit Ilim setting can be left at a very large value to effectively disable it as an integration-value limit. Most controllers including many position and velocity motion controllers have built-in anti-windup logic so it’s unlikely this integration limit will ever be reached.

Leave a Reply
You must be logged in to post a comment.