There are two types of motion control engineers: Those who are comfortable tuning a servo loop, and those who aren't. The latter basically, have two options. The first is to use a non-servo device such as a stepmotor; the alternative, a better idea, is to *get* comfortable.

Whether you're a novice or an experienced hand with servo tuning, this article can help you become more proficient when applying PID (proportional, integral, derivative) based servo loops. For starters, it explains two standard manual tuning methods that work well for many systems. It also covers an ever more common remedy to manual tuning, autotuning, which despite its name, isn't necessarily as automatic as one would hope. Beyond that, in the realm of advanced servo techniques, it explores feedforward and frequency domain biquad filtering, which, in certain instances, produce smoother motion profiles, resulting in better system operation.

### PID-based servo loops

No discussion of servo tuning can begin without addressing how servomotors behave. There are two types of servomotors that engineers commonly use for positioning applications. One is a dc servo, which uses mechanical brushes to commutate the motor. The other is a brushless dc servo, also known as a permanent magnet (PM) brushless motor, commutated electronically by external circuitry. Unlike stepmotors, which move in discrete position steps, servomotors have no built-in sense of angular position, and thus require a feedback device, such as a quadrature encoder. The servo loop, or “compensator,” keeps the motor at a desired position by comparing the actual position from the feedback device to the desired position and applying corrective motor commands. The better a servo loop performs, the more accurately the motor tracks desired position under various loads and motion profiles.

While a number of servo compensation schemes are available, the most common is the PID loop. Several implementations exist, however, and different vendors often use different approaches. Generally, PID controllers fall into two groups: the *PID position* loop and the *cascaded position/velocity loop*.

The more common PID position loop requires users to determine three values — the position loop gain *K _{p}*, the integral gain

*K*, and the derivative gain

_{i}*K*. Even for such a basic servo system, motion vendors provide additional options, namely integrator limits, feedforward gains, motor bias, and frequency-domain filtering using notch and bandpass filters.

_{d}Cascaded position/velocity loops, on the other hand, are tuned from the inside out with users setting either four or five parameters. The inner velocity loop (usually a PI controller) is tuned first, then the outer position loop (generally a PI or PID controller). External amplifiers that provide velocity control are one example of a cascaded position/velocity loop. Although this control approach is not discussed further, other techniques presented here may be adapted to it.

The following equations are a basic form of PID filter defined in both continuous and discrete time domains.

where *E(t)* is position error at time *t*.

The continuous form is used in system modeling and analysis and can represent the discrete time form when the sampling rate is significantly higher than the system bandwidth.

where *E _{n}* is position error at sampling time

*n*. The discrete form is used when implementing digital servo loops, executing on either a DSP or microprocessor.

### Manual tuning methods

One reason why PID compensators are so widespread is that they're relatively intuitive. The derivative *D* term introduces resistance or drag, the proportional *P* term introduces a linear restoring force, and the integral *I* introduces a time-dependant windup term. The effect of each term working alone can be combined or superimposed to provide an accurate picture of the overall output.

One of the more common manual tuning methods, **step response**, works directly in conjunction with the intuitive notion of a PID loop. This method measures a servo system's response to an instantaneous (within one servo cycle) change in position. It requires an accurate performance trace facility to display the results of a move, including desired position, actual position, and position error (or difference).

The basic approach is to initialize the integral term *I* to zero, set the derivative term *D* to a small non-zero value, and increase the proportional term *P* from zero until the system substantially overshoots. Then, increase *D* until the oscillation is critically damped. The goal is to find a set of values with a high *P*, while still being critically damped.

By increasing *D*, however, the optimum value of *P* changes, which in turn changes the optimum value of *D*, and so on. Not surprisingly, it takes several iterations to reach stable values because *D* operates at the highest frequency zone, *P* at a middle point, and *I* at the lowest frequency zone. A better method would involve tuning the highest frequency component first, then the middle-range value, and finally the lowest frequency part.

This is exactly what **zone-based tuning** does, another common manual tuning method. “Zone based” refers to the frequency zones of the PID terms, and is adapted from a method discussed in *Control System Design Guide*, written by George Ellis. Here, a performance trace plots velocity versus time, and the desired profile is a step function of velocity (rather than position, as in the step-response method).

The first step is to set the profile so it accelerates instantaneously between zero and a fixed velocity, and then back to zero. The next step, leaving *P* and *I* at zero, is to increase *D* until the actual velocity profile closely matches the desired profile. The destination positions needn't match as only differences in velocity (velocity error) are examined at this stage.

Next, set up the profiler to use moves with accelerations and velocities typical for the application, and change the capture facility so it plots the desired position, actual position, and position error. Then, increase *P* until minimizing servo error. While increasing *P*, the motion may exhibit high overshoot or become unstable; if that happens, simply reduce P by at least 20% for the final value.

Zone-based tuning offers several advantages over step-response tuning, such as being less iterative, as it tunes *P*, *I*, and *D* in order of frequency response. Another is it utilizes real motion profiles with ramps, rather than unrealistic position jumps. When employing either manual tuning method, check motion in both the positive and negative directions to ensure the gain parameters work well.

Absent from this discussion of manual tuning methods is the integral gain, *K _{i}*. This gain should be kept as small as possible because it contributes directly to servo instability or, in servo analysis terms, a loss of phase margin. Typically,

*K*is the last parameter set and is used to offset dc biases on the load (such as gravity), minimize final position errors, or reduce position errors at high velocities.

_{i}When tuning parameters toward a certain goal, be mindful that there is not one set of PID parameters that is optimized for all uses of a motion system. Some systems need very safe, conservative servo parameters. Others require aggressive parameters that optimize a specific characteristic, such as point-to-point transfer time. Still others may emphasize small errors during moves.

Most importantly, remember *what* is being optimized when determining the best servo parameters. Although obvious, the intended motion and load range are often overlooked by system designers as well as autotuning programs that determine the ‘best’ values.

### Autotuning

While manual tuning methods rely on biased judgments, such as when a profile is over damped or under damped, automatic tuning, or autotuning, makes this process more scientific and repeatable. Specifically, it places much (but not all) of the burden of tuning onto an algorithm. Most autotuning packages provide workable initial values, which are then further hand-optimized for a specific application.

Autotuning tends to use academically researched methods. Of these, Zeigler-Nichols (ZN) is the best known. Unlike manual tuning, this method assumes a certain mathematical model that describes the process being controlled. It then runs tests, which are translated through a series of rules into the PID parameters.

Because the earliest version of ZN was not optimized for automatic tuning, modified methods have since been created. One is the *frequency response method*. It replaces the PID with a relay (*all-on* positive, *all-on* negative) controller during tuning. The approach causes the servo loop to oscillate, the measured frequency and gain of which are used to determine the PID parameters.

Despite this, little has been published about implementing autotuning procedures for servo loop tuning. Possible reasons include vendor proprietary algorithms and a lack of interest until recently, when computing power became less expensive.

### Advanced servo control

In a perfect world, every force a motor experiences could be predicted. In reality, while some forces are predictable, others, such as loads that are larger or smaller than expected or motor characteristics that change over time, are not. One valuable aspect of servo control is that without knowing anything about a motor or load, one can still develop passable PID parameters by using manual and autotuning techniques.

However, with information about a motor or load, it is possible to improve system performance further — even for a well-tuned system — by directly *feeding forward* offsets into the servo loop's output. For motion control, this technique is generally used with the profile generator to provide velocity and acceleration feedforward control. In general, feedforward is expressed as

*Output _{n} = Output_{n} + _{vff}V_{n} + _{aff}A_{n}*.

Velocity feedforward compensates for any viscous friction — including some types of friction forces on the motor or load — or velocity-proportional lagging force. Often a voltage-mode amplifier (one without a torque loop) is used because back-EMF introduces a velocity-proportional lag.

Acceleration feedforward, on the other hand, compensates for any acceleration-proportional lagging force. This includes, theoretically, all hardware with non-zero inertia because physics dictates that if velocity is changed, an object will resist it. This resistance appears as an *acceleration-proportional lag*.

Practically speaking, feedforward only works if inertia, friction, and other system forces are predictable. However, many motion systems have a variable load or friction forces that change dramatically over the expected operating temperature range or product lifetime. A word of caution: Be sure that feedforward gains helping one set of conditions do not hurt another.

Many modern servo filters provide some facility for frequency-dependant filtering. That is, filtering that affects only certain domains of the overall operational frequency spectrum. This is useful for compensating for mechanical systems that have a resonance at a certain frequency or speed, or to reduce high-frequency noise.

The most common implementation of such a filter is known as a biquad. Biquads are common in digital control systems because they are flexible and easy to implement. They can be programmed to operate as notch, bandpass, band reject, or high or low-pass filters. Combining user-programmed coefficients A1, A2, B0, B1, B2, and K with current and previous inputs and outputs generates a biquad's output.

Selecting filter coefficients that meet desired characteristics is not exactly straightforward. For help, designers can visit informative websites such as www.octave.org, which provide tools to calculate these values. A biquad filter is represented as:

*Y _{n} = K(B0X_{n} + B1X_{n-1} + B2X_{n-2} + A1Y_{n-1} + A2Y_{n-1})*

where:

*Y _{n}* is the filter's output at time

*n*

*X _{n}* is the filter's input at time

*n*

*K* is a positive scalar

*B0, B1, B2, A0, A1* are programmable biquad coefficients.

*For more information, contact Performance Motion Devices at (781) 674-9860, visit* www.pmdcorp.com, *or e-mail the editor at* ctelling@penton.com.