|   Creating Motion  |  Program Flow  |  Variables  |  Encoder and Pulse Train Following  |
|   Input and Output  |  Communications  |  The PID Filter  |

The PID Filter

PID filter control

The SmartMotor™ includes a very high quality, high performance brushless D.C. servomotor. It has a rotor with extremely powerful rare earth magnets and a stator (the outside, stationary part) that is a densely wound multi-slotted electro-magnet.

Controlling the position of a brushless D.C. servo's rotor with only electro-magnetism working as a lever is like pulling a sled with a rubber band. Accurate control would seem impossible.

The parameter that makes it happen is found in the PID (Proportional, Integral, Derivative) filter section. These are the three fundamental coefficients to a mathematical algorithm that intelligently recalculates and delivers the power needed by the motor about 4,000 times per second. The input to the PID filter is the instantaneous actual position minus the desired position, be it at rest, or part of an ongoing trajectory. This difference is called the error.

The Proportional parameter of the filter creates a simple spring constant. The further the shaft is rotated away from its target position, the more power is delivered to return it. With this as the only parameter the motor shaft would respond just as the end of a spring would if you grabbed and twisted it.

If you twist the spring and let go it will vibrate wildly. This sort of vibration is hazardous to most mechanisms. In this scenario a shock absorber is added to cancel the vibrations which is the equivalent of what the Derivitive parameter does. If you sat on the fender of a car it would dip down because of your weight based on the constant of the car's spring. You would'nt know if the shocks were good or bad. If you jumped up and and down on the bumper, however, you could quickly tell whether the shock absorbers were working. That's because they are not activated by position but by speed. The Derivative parameter steals power away as a function of the rate of change of the overall filter output. The parameter gets its name from the fact that the derivative of position is speed. Electronically stealing power based on the magnitude of the motor shafts vibration has the same effect as putting a shock absorber in the system, and the algorithm never goes bad.

Even with the two parameters a situation can arise that will cause the servo to leave its target created by dead weight". If a constant torque is applied to the end of the shaft, the shaft will comply until the deflection causes the Proportional parameter to rise to the equivalent torque. There is no speed so the Derivative parameter has no effect. As long as the torque is there, the motor's shaft will be off of its target.

That's where the Integral parameter comes in. The integral of position is time, and the Integral parameter mounts an opposing force that is a function of time. As time passes and there is a deflection present, the Integral parameter will add a little force to bring it back on target each cycle. There is also a separate parameter (KL) used to limit the Integral parameter's scope of what it can do.

Each of these parameters have their own scaling factor to tailor the overall performance of the filter to the specific load conditions of any one particular application. The scaling factors are as follows:

            KP Proportional

            KI Integral

            KD Derivative

            KL Integral Limit


Tuning the filter

The task of tuning the filter is complicated by the fact that the parameters are so interdependent. A change in one can shift the optimal settings of the others. The automatic utility relieves you of this aggravation, but you still may want to know how to tune a servo.

When tuning the motor it is useful to have the status monitor running. This will allow you to monitor various bits of information that will reflect the motors performance.

            KP=exp Set KP, proportional coeff.

            KI=exp Set KI, time-error coefficient

            KD=exp Set KD, damping coefficient

            KL=exp Set KL, time-error term limit

            F                     Update PID filter

The main objective in tuning a servo is to get KP as high as possible, while maintaining stability. The higher the KP the stiffer the system and the more under control it is. A good start is to simply query what to begin with (RKP) and then start increasing it 10% to 20% at a time. It is a good idea to start with KI equal to zero. Keep in mind that the new settings do not take effect until the F command is issued. Each time you raise KP, try physically to destabilize the system, by bumping or twisting it. Alternatively, you could have a program loop cycling that invokes abrupt motions. As long as the motor always settles to a quiet rest, you can keep raising KP.

As soon as you reach the limit, you need to rediscover the appropriate derivative compensation. Move KD up and down until you locate the position that gives you the quickest stability. If KD is way too high, you will hear a grinding sound. It is not really grinding, but it is a sign that you will want to go the other way. A good tune is not only stable, but reasonably quiet. After optimizing KD, you may find that you can raise KP a little more. Keep going back and forth until you have exhausted all you can do to improve the stiffness of the system. Then it is time to take a look at KI.

KI in most cases is used to compensate for friction. Without it you will never get exactly on target. Begin with KI equal to zero and KL equal to 1000. Move the motor off target and start increasing KI and KL. Keep KL at least ten times KI during this phase.

Continue to increase KI until the motor always reaches its target, and once that happens add about 30% to KI and start bringing down KL until you notice it hampering the ability for the KI term to close the position precisely to target. Once you reach that point, increase KL by about 30% as well. You want the Integral term to be strong enough to overcome friction, but you also want the limit to be set so that an unruly amount of power will not be delivered if the mechanism were to jam or simply find itself against one of its ends of travel.

E=expression             Set maximum position error

The difference between where the motor shaft is and where it is supposed to be is appropriately called the error". The magnitude and sign of the error is delivered to the motor in the form of torque, after it is put through the PID filter. The higher the error, the more out of control the motor is. Therefore, it is often useful to put a limit on the allowable error, after which time the motor will be turned off. That is what the E command is for. It defaults to 1000 encoder counts, but can be set from 1 to 32,000.

There are still more parameters that can be utilized to reduce the position error of a dynamic application. Most of the forces that aggravate a PID loop through the execution of a motion trajectory are unpredictable, but there are some that can be predicted and further eliminated preemptively.

KG=expression       Set KG, Gravity offset term

KGOFF                    Kill KG term during error

KGON                      Maintain KG during error

The simplest of these is gravity. Why burden the PID loop with the effects of gravity in a vertical load application, if it can simply be weeded out. If in a particular application, motion would occur with the power off due to gravity, a constant offset can be incorporated into the filter to balance the system. KG is the term. KG can range from -8388608 to 8388607. To tune KG simply issue the KGON command, while the motor is not servoing, and make changes to KG until the load equally favors upward and downward motion. If when there is a position error you want the motor to drop the load, then issue KGOFF.

KV=expression        Set KVff, velocity feed forward

Another predictable cause of position error is the natural latency of the PID loop itself. At higher speeds, because the calculation takes a finite amount of time, the result is somewhat old news". The higher the speed, the more the actual motor position will slightly lag the trajectory calculated position. This can be programmed out with the KV term. KV can range from zero to 65,535. Typical values range in the low hundreds. To tune KV simply run the motor at a constant speed, if the application will allow, and increase KV until the error gets reduced to near zero and stays there.

KA=expression         Set KAff, acceleration feed forward

Force equals mass times acceleration. If the SmartMotor™ is accelerating a mass, it will be exerting a force during that acceleration. This force will disappear immediately upon reaching the cruising speed. This momentary torque during acceleration is also predictable and need not aggravate the PID filter. It's effects can be programmed out with the KA term. It is a little more difficult to tune KA, especially with hardware attached. The objective is to arrive at a value that will close the position error during the acceleration and deceleration phases. It is better to tune KA with KI set to zero because KI will address this constant force in another way. It is best to have KA address 100% of the forces due to acceleration, and leave the KI term to adjust for friction.

KS=expression         Set KS, dampening sample rate

You can reduce the sampling rate of the derivative term, KD, with the KS term. This can sometimes add stability to very high inertial loads. Useful values of KS range from 1 (the default) to 20. Results will vary from application to application.

            PID1 Set normal PID update rate

            PID2 Divide normal PID update rate by 2

            PID4 Divide normal PID update rate by 4

            PID8 Divide normal PID update rate by 8

The trajectory and PID filter calculations occur within the SmartMotor™ 4069 times per second. That is faster than is necessary for very good control, especially with the larger motors. A reduction in the PID rate can result in an increase in the SmartMotor™ application program execution rate. The ‘PID2 command will divide the PID rate by two, and the others even more. The most dramatic effect on program execution rate occurs with PID4. PID8 does little more and is encroaching on poor control. If you do lower the PID rate, keep in mind that this is the sample" rate that is the basis for Velocity values, Acceleration values, PID coefficients and wait times. If you cut the rate in half, expect to do the following to keep all else the same:

            Halve wait times

            Double Velocity

            Increase Acceleration by a factor of 104


Current limit control

AMPS=expression   Set current limit, 0 to 1000

In some applications, if the motor misapplied full power the mechanism could be damaged. It can be useful to reduce the maximum amount of current available thus limitimg the torque the motor can put out. Use the AMPS command with a number, variable or expression within the range of 0 to 1000. The units are tenths of percent of full scale peak current, and varies with the size of your SmartMotor™.

 
|  Home   |   About Us  |   Products  |   Sales  |   Support  |   Press and Literature  |  Contact Us   |   Site Map  |
Animatics Corporation. 3200 Patrick Henry Drive, Santa Clara, CA, 95054 Tel: +1 408.748.8721
Copyright © 2008   All rights reserved.  Any comments or problems email webmaster