Chuck Lewin
Founder and CEO
Performance Motion Devices, Inc.
In this paper we provide an overview of PID (proportional, integral, derivative) based position servo loop tuning. Tuning a servo can be a daunting process but we show you a simple technique that will work well for a large majority of systems.
Introduction
There are two types of servo motors commonly used for positioning motion control applications; the DC Brush motor, which uses mechanical brushes to commutate the motor, and the Brushless DC motor, aka the BLDC motor, aka the AC synchronous motor, which is commutated electronically by external circuitry.
Unlike stepper motors which move in discrete position steps, servo motors have no built in sense of where they are and require a feedback device such as an encoder to control their position. A position servo loop has the job of driving the motor to a particular position. It does this by comparing the desired position from the trajectory generator at any given moment with the actual motor position and applying a continuous correcting motor command.
Figure 1 shows a control flow diagram for a general purpose positioning servo motor controller. A host specifies high level commands such as “move from point A to point B using this set of trajectory parameters”, the motion controller’s profile generator then continuously generates a commanded position which is input to the position control loop, followed by a current control loop and amplifier.
Figure 1: General Purpose Positioning Servo Motor Controller Flow Diagram
The PID Position Control Loop
Theorists and engineers have developed a number of servo position control schemes, but the overwhelming favorite for motor positioning is the PID (Proportional, Integral, Derivative) loop. As implemented by various motion control vendors many variations of the digital PID loop exist. But we will start the discussion by focusing on the simplified PID Position loop shown in Figure 2.
The PID position loop is tuned by specifying a gain parameter setting for each term. These gain values are notated Kp, Ki, and Kd (proportional gain, integral gain, derivative gain) and the values they are set to determine the relative influence of each term on the PID controller’s final output.
In its basic form the PID position loop only requires us to determine settings for these three parameters, however as we will see later there are other commonly used settings including the integral limit, the derivative sample time, and feedforward gains.
Figure 2: Simplified PID Position Loop
In the PID position loop diagram above we should be aware that the ‘loop’ part of the controller is the summing junction in the diagram to the left, where we subtract the actual position from the 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.
To tune a position PID loop it is not important to know how the PID filter is calculated, but for reference below is the basic equation. 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 kHz to as high as 80 kHz, with 10-20 kHz perhaps being 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 is the current position error value
En-1 is the previous position error value
Sum(En) is the sum of En values past and present
Understanding PID Filters
A key reason that the PID position control loop is so popular is that the effect of its constituent pieces, the P, the I, and the D, can be described and understood intuitively.
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 like 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. Why would this be useful? Because if only a P (proportional) term is available it may be difficult to arrive at the exact commanded position due to forces or mechanical issues such as gravity, stiction, motor detents, or other factors. The I term builds up over time and can get the servo 'over the hump' to the final desired position.
The contribution of the D term is calculated by subtracting the previous position error from the current position error. It has two main practical effects; it provides a feedforward boost whenever the profile velocity increases or decreases, and it provides a general purpose drag term, thereby dampening oscillations.
Step Response Tuning
The method that we will use to determine the PID gain values, known as the step response method or step response tuning, is hands down the most common approach for manual tuning a position PID loop. This approach centers around the reaction of the motor to an instantaneous change in commanded position (the step).
Note that we used the term ‘manual tuning’ above because many motion control vendors, in addition to tools that help with manual tuning, provide an auto-tuning function. While very useful, auto-tuners don’t always come up with the best tuning values and many auto-tuners don’t determine all the settings offered by the position loop. In addition, manually tuning the motor is a great way to gain an intuitive feel for how changes to the P, I, and D gain values affect the behavior of the motor axis.
What tools do we need for step response tuning? 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 our moves. At a minimum we need to display a stream of captured values of the desired position (the position commanded by the trajectory generator) and the actual position (the actual measured location of the motor).
Figure 3 shows an example screen capture of such a facility, in this case the motion scope/trace system provided by PMD’s ProMotion Windows-based software. In your own tuning session you can use the Pro-Motion software tool, similar products from other motion control vendors, or you can use a system that you developed yourself.
Figure 3: Example Screen from PMD’s Pro-Motion Sample Capture and Display Software
The Mechanism To Be Tuned
Once we have our motion controller and motion trace & display tools in place, the last element is the actual mechanical system that will be tuned. For most engineers the goal is to determine PID gain parameters that will operate the machine smoothly, accurately, and with significant stability margin. This can be more complicated than it seems however because the axis and attached mechanisms being tuned may carry variable loads and may have different operating modes.
So it is important to give consideration to what specific operating condition of the controlled mechanism you will tune for. From a practical standpoint, many engineers will start tuning the servo motor with no load mechanism or load attached. Tuning just the motor is a good place to start because from that baseline you can progressively add more realistic conditions. For example, after tuning just the motor you can connect the mechanism with no load, then you can add the minimum expected load to the mechanism, followed by the the maximum expected load.
Having multiple PID settings for different mechanism configurations can actually be useful in its own right. Many control systems switch in different gain settings depending on the load, or depending on the performance goal for a particular operating mode. For example the PID gain settings that achieve the highest end point positioning accuracy may be different than for those used to rapidly slew from one machine operating area to another. We’ll talk more about this a bit later.
Step by Step PID Loop Tuning Procedure
With our capture and display system in place and the mechanism to be optimized set up, here is a step by step description of the recommended tuning procedure:
Step 1 is to set up your motion trace capture facility. Different terminology may apply according to the vendor but in PMD’s system you 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 this isn’t necessary for the procedure described here.
Step 2. Set up the motion controller to make an ‘instantaneous’ move from the current position to a programmed destination position. This move is the step referred to in the term ‘Step Response Tuning’. Some motion controllers including PMD’s support a direct step response mode where you just enter the step distance. You may need to select a profiling mode such as trapezoidal point-to-point and program it with extremely large velocity and acceleration values so that the effective profile move time is close to zero.
One important detail connected with setting the step distance is that during the step response move the amplifier command should not go to 100%. For example if the current limit for a particular motor is 5.0 amps and you have set (as you should) the controller to not exceed that amplifier command value, if you observe that the traced motor current command reaches 5.0 amps you should lower the step distance to avoid the servo output being saturated.
Step 3. Depending on the PID control settings provided by your controller, set the Ki (Integral gain), Ilim (Integral limit), Kaff (Acceleration feedforward gain), and Kvff (Velocity feedforward gain) to zero. Set Kp (Proportional gain) to a small value, perhaps 10 to 50 for motors with quadrature encoders. Set the Kd (Derivative gain) to a value 5 times the specified Kp value. For small motors such as Nema 17 sized motors set the initial derivative time to .25 mSec, for NEMA 23 size motors set to 1.0 mSec, and for NEMA 34 or larger set to 2.5 mSec.
Note that these initial gain settings are controller-specific, and especially if you are new to the controller you will need to experiment. When in doubt use lower values of Kp.
Step 4. Execute the step move. This should result in the trajectory generator quickly (in a single instantaneous step) commanding a move by the programmed step distance. Assuming the trace function has been synched to the start of the move you should shortly thereafter see the trace scope window display data. Upon viewing this first trace you may find it necessary to make some adjustments to the data capture and display system to arrive at scope settings that let you see what you want in a single screen.
If the motor oscillates in an uncontrolled manner set Kp to a lower value and repeat from step 4. If at any point you are concerned that the motor or power supply may be over-stressed disable the controller. If the motor produces a high pitched chatter or whine you can lower the KD derivative gain or alternatively increase the derivative time. We will talk more about setting the derivative time a bit later.
Step 5. Once the position loop is at least somewhat stable, you will begin a repeating sequence:
- View the scope display to determine whether the response is underdamped, critically damped, or overdamped (see below for instructions on how to do this)
- Adjust the gain settings accordingly
- Make another step move (go back to step 4)
The next three sections will show you how to characterize the step move response and how gain settings should be adjusted.
Underdamped Servo Response Curve
The screen capture below shows a typical underdamped response.
Figure 3: Example Screen from PMD’s Pro-Motion Sample Capture and Display Software
The yellow trace shows that the commanded position instantly changes from a position of 0 to a position of 100 (in your setup this jump will equal whatever you entered into the step response dialog box). The green trace shows the resultant actual motor location.
From this trace, although the actual position does eventually settle to a position value of 100, it overshoots significantly and oscillates several times. Whenever the actual axis position significantly overshoots the commanded position the system is considered underdamped, and to correct for this you should increase the derivative gain (Kd).
Critically Damped Servo Response Curve
The screen capture below shows a critically damped response.
In this trace the actual position does not overshoot the commanded position, and it settles quickly (in 10 mSec) to the commanded position of 100. Note that in these particular trace displays the unit of time was set to be servo cycles, which for this PMD controller is 50 uSec per servo cycle.
It's worth noting that many combinations of Kp and Kd settings may result in 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
The screen capture below shows an overdamped response.
This can be seen by comparing with the critically damped response in the previous section. An overdamped system will be stable but needlessly slow in its response to changes in the position command.
If the response is overdamped you should reduce Kd, trying to find the smallest value of Kd that still gives a critically damped response.
Setting the PID Derivative Sample Time
The derivative time setting which we referenced earlier is an important and useful setting. Derivative time is the period at which the PID loop derivative contribution is calculated in units of servo cycles or in milliseconds depending on how your 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 your 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.
Generally speaking larger motors with larger loads will 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 & Kd
Your overall position loop tuning goal is to set the Kp to as high a value as possible while still finding an associated Kd value that can create a critically damped response. Higher Kp values will result in more accurate tracking and faster responses to command position changes.
As you try higher and higher Kp values, at some value of Kp you will find that there is no value of Kd and Derivative Sample time that can create a stable and critically damped response. At this point you should reduce the Kp setting by 35-50%, determine the associated critically damped Kd setting, and use those settings as the final values for Kp, Kd, and Derivative Sampling Time. Backing down from the ‘borderline’ Kp value is important for improving stability, accommodating small differences in controller, motor, and attached hardware behavior, and for handling changes that may occur to the system over time.
Setting the PID Ki Gain and Limit
Once Kp, Kd, and Derivative time have been set, you can enter a value of Ki (Integral gain) to improve tracking accuracy. Typically (but depending on the scaling of your controller), Ki settings are 1/10 to 1/2 of the Kp value. Smaller motors typically use relatively larger ratios, and larger motors with larger loads typically use smaller Ki ratios. Higher Ki settings will increase tracking accuracy during and after the motor move is complete but can also reduce system stability. So you should set Ki to the smallest value that can achieve your 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 which effectively disables use of this term as a limit to the integration value. Most controllers including all of PMD’s position and velocity motion controllers have built in anti-windup logic so it is very unlikely this integration limit will ever be reached.
Congratulations! You have completed your step response tuning session and have (hopefully) developed PID gain settings that provide smooth, quiet, and accurate position control. With this tuning session behind us, we will close with some additional general-purpose information on methods to further improve system performance.
Verifying PID Settings With Real Trajectory Profiles
Instantaneous step profiles simplify analyzing the servo loop behavior but they almost never represent the profiles that the controller machine will use in the actual production application. On the contrary, as much as possible, the actual profiles should try to avoid instantaneous changes of position (or velocity, or even acceleration) to minimize resonant vibration being injected into the machine mechanics. This article on S-Curve Profiles tells you more about this important subject.
Whether trapezoidal, s-curve, or some other trajectory profile shape it is important to confirm the stability of the step-response-determined PID loop settings with the actual trajectories used to operate the machine. While doing so here are some things to watch out for:
Acceleration Setting - As stated earlier, if the current command to the amplifier reaches 100% of the programmed current limit the motor actual position will rapidly fall behind the commanded position leading to an excessive position error value. Related to this, high accelerations may exceed the current output capacity of the power supply being used, potentially resulting in a drop in the supply voltage. The remedy for both conditions is to lower the trajectory acceleration.
Deceleration Setting - Similar phenomena can occur during deceleration. The amplifier command can saturate with a negative value and depending on the design of the power supply the supply voltage can increase to a dangerous level. The later occurs when the motor acts as a generator. Many controllers provide a feature called shunt regulation to address this. Shunt regulation uses a special circuit that ‘shunts’ current through a resistor to absorb the excessive supply voltage.
Maximum Velocity Setting – As a motor rotates faster it generates an increasing voltage in opposition to the drive voltage known as back EMF. Back EMF limits the top speed at which a particular motor driven at a particular voltage can rotate. Trajectories that approach or exceed this top speed will not be able to keep up with the commanded position, causing an excessive position error. The remedy is to lower the trajectory velocity, or to make system changes such as increasing the supply voltage or using motors with lower back-EMF per RPM.
Acceleration and Velocity Feedforward
Feedforward is an important technique for improving real world performance of servo controller systems, especially if positioning accuracy during the move is important (for example in machine tools, 3D printing, and tracking applications). An expanded PID control flow diagram which includes feedforward terms is shown below.
Figure 4: Position PID Loop with Feedforward
Feedforward has no effect on system stability and is therefore a sort of ‘free lunch’ for improving axis performance. While beyond the scope of this article, refer to Feedforward in Motion Control - Vital for Improving Positioning Accuracy for information on a variety of traditional and advanced feedforward techniques.
Frequency-Based Motion Analysis Tools and Filters
The above step by step tuning process represents a popular and straightforward approach toward tuning a PID loop. There are more quantitative approaches however, particularly for verifying the behavior of a specific position loop controller and load. Many controls vendors including PMD provide frequency-based tools such as Bode plots to support these approaches.
Bode plots can help characterize your mechanical system as well as determine characteristics of the control loop such as the bandwidth and phase margin. One output of a Bode plot may be the identification of natural resonances in the mechanical system. While a properly tuned PID can help reduce the impact of this, active filtering within the servo loop, often in the form of biquad filters are the compensating mechanism of choice. Many controllers including all of PMD’s positioning control products provide general purpose biquad filters inside the position loop.
A treatise on characterizing system mechanics and compensating for resonances is beyond the scope of this article but for users who want to take this on there are a number of good reference volumes including George Ellis’ excellent “Control System Design Guide.”
Figure 5: Control Flow Diagram of Biquad Filter
Position Loop Gain Scheduling
As mentioned earlier, for many machines it is unlikely one set of PID gain parameters will be optimal for all operations of the machine. Some modes may require very stable and smooth operation, others may prioritize endpoint accuracy, and others may emphasize high speed moves optimizing pointtopoint transfer times.
To handle different operating priorities even within the same mechanism a technique called gain scheduling may be used. While the term ‘gain scheduling’ has specific connotations in the field of non-linear system control, for our purposes gain scheduling means switching-in different sets of gain parameters while the machine is operating in different modes, or carrying different loads.
It’s easy to get carried away with gain scheduling, but at a minimum you may find it useful to develop a more aggressive 'moving’ set of servo gains and quieter, less aggressive ‘at settle’ gains used to hold the axis in place. Many controllers provide a software accessible ‘in motion’ flag, making it easy to automatically change gain values triggered on this condition, or on other conditions such as the axis achieving specific values of position, velocity, acceleration, or time.
Summary
In this article we have presented a simple technique called step response tuning for determining PID gain settings in motor positioning applications. This manual tuning method uses iterative characterization of the response to an instantaneous ‘step’ move as being either under damped, critically damped, or over damped to arrive at optimum or near-optimum PID loop settings.
Beyond PID gain settings, modern motion controllers provide other important control features including adjustable derivative sampling time, feedforward compensation, and frequency based analysis and filtering to help create robust and high performance machine controllers.
Below are links to a couple of videos that show simple underdamped, overdamped, and critically damped motion for a noload single motion axis responding to a step response command.
PMD Products That Control Servo Motors
PMD has been producing ICs that provide advanced motion control of DC Brush and Brushless DC motors for more than twenty-five years. Since that time, we have also embedded these ICs into plug and play modules and motion control boards. While different in packaging, all of these products are controlled by C-Motion, PMD's easy to use motion control language and are ideal for use in medical, laboratory, semiconductor, robotic, and industrial motion control applications.
ION/CME N-Series Drives
ION®/CME N-Series Drives are high performance intelligent drives in an ultra-compact PCB-mountable package. In addition to advanced servo and stepper motor control, N-Series IONs provide s-curve point to point profiling, field oriented control, downloadable user code, general purpose digital and analog I/O, and much more. These all-in-one devices make building your next machine controller a snap.
Learn more >>
MC58113 Series ICs
The MC58113 series of ICs are part of PMD's popular Magellan Motion Control IC Family and provide advanced position control for stepper, Brushless DC, and DC Brush motors alike. Standard features include FOC (Field Oriented Control), trapezoidal & s-curve profiling, direct encoder and pulse & direction input, and much more. The MC58113 family of ICs are an ideal solution for your next machine design project.
Learn more >>
ION 500 & 3000 Drives
ION 500 and 3000 Drives are high performance intelligent drives in a compact cable-connected package. In addition to advanced servo motor control, IONs provide s-curve point to point moves, i2T power management, downloadable user code, and a range of safety functions including over current, over voltage, and over temperature detect. IONs are easy to use plug and play devices that will get your application up and running in a snap.
Learn more >>
Prodigy/CME Machine Controller
Prodigy®/CME Machine Controller boards provide high-performance motion control for medical, scientific, automation, industrial, and robotic applications. Available in 1, 2, 3, and 4-axis configurations, these boards support DC Brush, Brushless DC, and stepper motors and allow user-written C-language code to be downloaded and run directly on the board. The Prodigy/CME Machine-Controller has on-board Atlas amplifiers that eliminate the need for external amplifiers.
Learn more >>
Pro-Motion Analysis Software
Pro-Motion is PMD's easy-to-use Windows-based exerciser and motion analysis program. It offers capabilities including a step-by-step motor setup axis wizard, auto-tuning, configuration storage, and sophisticated motion data trace and display. Advanced users can access a complete motion analysis package with Bode plot generation.
Learn more >>
You may also be interested in:
- Mobile and Portable Automation Demands Light, Efficient, and Cool Operation (Article)
- Motors and Motion for Medical Devices (Webinar)
- Motion Techniques for Improved Liquid Handling (Article)
- Field Oriented Control (FOC) - A Deep Dive (Article)