Motion Control Resources
Name that Tune
by Kristin Lewotsky, Contributing Editor
Motion Control & Motor Association Posted 05/11/2011
Adjusting PID loop gains can remove overshoots, decrease settling time, and enhance stability in machines of all types.
Servo motors provide precise, accurate, repeatable motion, courtesy of closed-loop feedback. Motion control is a systems-level solution, however. No matter how high quality the motors and feedback, if the system hasn't been tuned to produce the best possible motion for the application, even the best components will underperform. One of the most common approaches to servo control and tuning is the proportional, integral, derivative (PID) loop method. The PID loop provides a simple, flexible tool for adjusting the controller to get the desired system performance.
Consider a single-axis motion system. The controller commands the motor to generate a certain amount of torque that will be translated into motion and a feedback device tracks the result. In an ideal system, the commanded position, xc, and actual position, xa, would be one and the same. We live in the real world, however. Machines suffer from compliances and resonances. Motor torque varies from unit to unit. All of this combines to introduce a position error E(t). The feedback device sends this information to the controller, which uses it to calculate a new trajectory command to drive the system closer to the commanded position, and the process repeats.
In this best case scenario, the system arrives at xc within one or two iterations. In the worst-case scenario, it dithers about the desired position, driving machine into oscillations. The PID loop provides a tool for tuning controller gain to achieve the desired position.
One way to express the output of the PID loop is as follows:
where Kp is the proportional term, Ki is the integral term, and Kd is the derivative term.
By adjusting each of the terms individually a user can drive the error in position or settling time to the desired levels. PID loops can be implemented in hardware as analog electronics or digitally, in software. The hardware consists of three potentiometers integrated in the controller that can be adjusted manually by screwdriver. The software solution, the PID loop is essentially a control algorithm that provides a different overall gain number depending on how each of the gain coefficients is adjusted.
Tuning the Loop
The various gain terms in equation  derive their names from the way they interact with the error term. As a result, they tend to respond over characteristic frequency bands. The proportional gain term, for example, tends to primarily affect midrange frequencies. As its name suggests, Kp directly scales the error term (see figure 1). It’s primarily used to adjust system speed. It can’t correct for spatial offset, however. As a result, if the proportional gain is pushed too high, the controller’s repeated attempts to correct the error can drive the system into oscillation.
The integral feedback gain provides a method to eliminate the offset, while permitting a faster response (see figure 2). Instead of just being directly proportional to the input, Ki acts over time, integrating the gain over the error interval. The integral feedback loop can correct for cases in which the starting torque of the motor isn't enough to overcome bearing friction, for example. In such cases, the error is sufficiently small that the controller can’t command enough current to the motor to actually break the starting frictional torque, making it impossible for the system to close in on the error. Increasing the proportional gain might provide enough muscle to break starting torque, but might also introduce overshoot, replacing one problem with another. “The integral gain sees an error for longer periods of time, so the gain keeps increasing and increasing until it actually breaks free,” says Jonathan Roberts, Product/Application Engineer at Moog Inc. “With the integrator, you can most of the time get exactly where you want to go.”
The integral gain tends to act primarily on the low-frequency components of machine response. The error term under the integral introduces a sine term, so even with digitization, the integrator introduces a phase delay. Coupled with an overly high gain, this phase lag can lead to serious problems. If the system overshoots, for example, the delay can create a runaway feedback loop that can drive the system into oscillation.
Enter the derivative gain term, Kd. Just as the integral loop provides a means for correcting offsets introduced by proportional gain, the derivative gain introduces a phase advance that can be used to balance the phase lag introduced by the integrator gain (see figure 3). There are trade-offs, of course. The derivative gain reacts primarily to high-frequency input from the electrical system, generating a significant amount of noise if improperly handled. "You start amplifying the noise problems from EMC or anything of that nature, so too high of a derivative gain causes lots of problems," says Roberts. "With most of the things we do here at Moog, we don't even include the derivative gain.”
Tricks of the trade
Because the process is in some ways parametric, converging on a solution can take time. Roberts starts by calling for a step command, increasing the proportional gain until the system begins to oscillate. “Once you start getting this resonance, back off by 25 or 30%. That's a good starting point for proportional gain," he says.
Next, call for another step command and check for spatial error. To correct for overshoot, increase the integral gain, but be aware that it will in turn increase the frequency response. You can correct for that by decreasing integral gain. It's a delicate balancing act. Adjusting derivative gain can also help modify overshoot, but remember that it also increases noise.
Tom Bullock, President of Industrial Controls Consulting, refers the method as IPD loop tuning, preferring to adjust the loops in order of increasing frequency response. "You start with the integrator but then you need to adjust the proportional gain at the crossover frequency or else you’ve got an unstable system. You have to introduce the proportional term to keep it from oscillating, then you introduce the derivative term, which gives you even more of a phase shift so that at crossover you can push out the bandwidth out as far as you can."
Bill West, Director, Global Application Engineering at Kollmorgen (Radford, Virginia), has still another technique. It's easy to fall prey to the temptation to over tune a machine, which ultimately leads to more wear and early failure. To ensure the machine is stable to a safe margin, he recommends using both frequency-response and time-response tuning for each PID loop. The first step is frequency-response tuning to establish baseline tuning gains. The second step is to use time-response techniques to tune for motion performance. Step three is to verify system stability with frequency response techniques.
He advocates being conservative with tuning - make the machine only as good as it needs to be. "If you ask me to optimize for a certain move, I'm not going to turn the gains all the way up because the machine will be more stable [with them lower]," he says. "I'm going to try to get all the margin I can for mechanical wear.”
Tuning a PID loop is an iterative process. Adjusting any one of the gains affects the system response to the other two, so making changes requires a thorough review the performance of the system. Once you're satisfied with your results, finished by running a test for stability to ensure the machine doesn’t vibrate or oscillate in some way in the absence of commands.
Pitfalls To Avoid
In general, motion designers need to strike a balance between how effectively the system follows commands and how effectively it rejects disturbances. A machine optimized for command following will likely become vulnerable to noise sources ranging from encoder lines to vibrations from a nearby machine or axis, for example. As with so many things in engineering, it's a matter of trade-offs. “It's very easy with one degree of freedom, which is what the PID is, to make a system follow commands easily or to reject disturbances easily, but you can't necessarily do both," says West. For best performance, he advocates adding a low pass filter after the PID loop.
The most common issue Robert sees is failure to test over the full frequency range of the machine. Every system has resonances, driven by inertia, machine compliances, etc. If you tune over what you think is your full range and you don't encounter resonances, keep going, he urges. "At a certain frequency, you're going to start getting resonances. It usually happens after your break frequency, when you don't care but it's still within the range of operation that the machine might require. Tune over the whole frequency range, even higher than you think you might need.”
Above all, the tuning process needs to take place within the context of the actual mechanical system, under the expected load and at the anticipated speeds. Tuning by itself without taking the system into account is akin to dropping a Maserati engine into a Ford Escort - it might seem like a nifty idea, until you realize that there’s no part of the Escort that can actually support that performance.”
Real machines have compliances, resonant frequencies, and other types of mechanical problems that prevent gains from being turned up. If those levels are ignored, the machine might simply make audible noise, which shouldn’t be discounted, especially in the absence of commanded moves -- noise indicates motion and wear, or possibly destructive resonances. In the worst-case scenario, bad tuning can lead to runaway oscillations and damage to products, machines, and personnel.
"I've seen 1500-lb. tables shot off the edge of tables when gains have been set wrong or feedback connected wrong," says West. "I've seen a 500-kg block of granite jammed into the end of a machine and breaking off another part of it.” It's essential to integrate safety with controls, he stresses. The algorithms need to be able to cut current or shut down if errors exceed certain levels.
Most of all, it's important to be clear about performance goals and priorities. If you tune a packaging line to process 200 to 300 bottles per minute, the performance will be less across the entire range than if you tuned it for one specific rate. That said, the broader the tuning range, the more forgiving and adaptable the machine will be. A tightly tuned machine, on the other hand, will do one thing and do it well. That may not be the case for other rates, however. "You might tune to a very specific frequency and make a response perfect for 200 bottles per minute, but the machine throws a bottle across the room at 300 parts per minute," says Roberts. That's an important issue to consider, given the tendency of end users to push machines far beyond their designed performance.
Above all, be realistic. “You're never going to get exactly what you want,” Roberts says. “There's this give-and-take with the three different feedbacks, frequency response versus overshoot versus stability. Make sure you understand what your goal is in the beginning so that you know what you're looking for and understand the issues. That way what you won't get with it, as well, won't affect you later on."