Servos are closed loop devices.
They operate by comparing the position they're supposed to be at with
the position their encoder says they actually are at and applying current
to the servo motor until the two match. This linkage between the encoder
and motor is commonly called a "PID loop", although there are
other names and methods used to close the loop. The linkage requires tuning
in almost every case.
Think of a servo as a mechanical
system not unlike your car's suspension. There is a spring and a shock
absorber. The spring allows the wheel to follow the road, moving up and
down with the bumps. If the spring is extremely soft, the ride is smooth.
That's great for the car, but lousy for your CNC, because those "bumps"
are fine positional movements that are lost because the spring was too
soft. You want to feel every bump! So you want tight springs. The stiffness
of the spring is controlled by a parameter known as "Gain".
More gain results in a stiffer system.
Why not just turn the Gain
all the way up and be done with it? Recall there is a shock absorber involved
here too. Lots of gain makes a very stiff suspension, and that suspension
will ring like a bell. That "ringing" is called oscillation
in the case of a servo. It means that after a move is commanded, the servo
oscillates roughly around the actual position. Since this is an electrical
system with no friction, its possible for that oscillation to continue
forever, and even for it to get pretty violent. Imagine your spindle slamming
around the desired location back and forth maybe 1/4". Scary!
We need the shock absorber
to dampen the oscillation, hence servo systems have another tuning parameter
called "Dampening" or "Damping". It's role is to stop
With that understanding, there
are two ways to tune a servo system. One is by ear, when we listen for
oscillation. They other is using an oscilloscope or other means of observing
the position versus time plot so we can tell visually whether there is
If we plot position error (not
position, but the error or difference between what the encoder says and
where we told the servo to move to) versus time, we can see the effects
of different amounts of damping as a series of "bumps" or other
features in the graph of position error. Note that the first bump is normal,
and appears on every graph. It is the point of maximum error, when the
servo was commanded, but hasn't yet moved. It's what happens after the
bump that matters.
If we don't have enough damping,
we can see the position oscillates back and forth, often with slowly decreasing
amplitude. The servo heads for the intended location, but it overshoots,
then it heads back and undershoots, so it reverses direction again, ad
nauseum. The effect is called "oscillation" or "ringing"
and it is very audible in most cases. The amplitude decreases because
there is a little damping, but the oscillation goes on for too long:
You can hear or
sometimes see an underdamped servo oscillating. Give the servo a motion
input that's pretty extreme: lots of acceleration and velocity. A change
of direction really puts it to the servo. Normally servos are pretty quiet,
but you can hear this oscillation. I burned out a Geckodrive one time
due to oscillation. I couldn't hear it over the noise of the mill cutting
chips, but eventually I saw the timing belt oscillating very slightly--just
enough to make the lettering on the logo look fuzzy.
The solution to
under damping is more damping (obviously!). Turn up the damping trim pot
on your servo driver.
The opposite of underdamping
is (pretty obviously) overdamping. It looks like this:
has no oscillation, but damping really slows down the curve moving to
commanded position too much...
servo does not oscillate, but as we can see, too much dampening really
slows down the ability of the curve to reach equilibrium and stop moving.
It makes it sloppy, as though the servo is afraid and creeps up on the
commanded position. Imagine your mill cutter is a racecar running through
the curves that are the desired cuts on your workpiece. An overdamped
servo means that the racecar is always a little slow to respond to where
it should be. Take a sharp turn and the driver is too slow or timid, turns
the wheel late, and the car swings a little wide. This is not very accurate,
although at least it does not oscillate. Still, it is an undesirable and
Now what should
the curve look like?
Here is the condition
known as "critically damped":
damped is just right!
In a critically
damped system, the initial command to move creates a large error which
the servo rapidly closes and then it stops moving when it gets there.
Pretty simple, eh? Servo performance doesn't get any better than this.
Now how do we
get a servo system tuned so it is critically damped? We can either do
so by ear or with an oscilloscope or other measuring device that can show
us the plot. Is one better than the other? Many have achieved excellent
results tuning by ear, but it does require a bit of "touch".
You can well imagine the pitfalls. Your only way of knowing you are underdamped
is audible oscillation. You don't really have a great way to hear overdamping
other than that motion may not be so smooth when you reverse direction
because the system is slow to respond.
Because it is
harder to detect overdamping than underdamping by ear, you want to err
on the side of too little damping. That's what the method I'll show does--it
gets as much gain going as possible and turns up damping until it just
stops the oscillation.
If you have access
to an oscilloscope, or your motion control board or servo driver can show
you a position error diagram, tuning can be much more precise and obvious.
What's the worse
case tuning by ear? If you do it right, you have eliminated oscillation
and underdamping, which is audible. The worst case is you dialed in too
much damping and you now have an overdamped servo. Hopefully it is only
slightly overdamped. Your response is a little slow, but probably not
too bad. You're not squeezing the last iota of performance from your machine.
Check the accuracy of axis motion. You can just slow down the speeds until
it is accurate when cutting. Cutting speeds are not very fast anyway.
Remember, if left to find its position long enough, the underdamped servo
still goes to the right place. So largely, the penalty of a less than
optimal tuning job will be you have to run at slower speeds to achieve
thing to note before we get on with the tuning. It does no good to tune
a servo motor sitting on the bench. It must be installed on the machine,
and the machine must be set up as near to how it will be used in production
as possible. That means the gibs are adjusted and so on. I would even
go so far as to throw your vise or 4th axis on the table if that's how
you plan to run. Really tight servo tuning can change even with the difference
between a really heavy workpiece and a light workpiece, so set up your
mill table the way you expect it will be used before attempting to tune.
Servo Tuning by Ear
When the servo is on, but not
moving, you will normally hear a little bit of "singing" from
it. Perhaps an occassional ticking, or maybe a little bit more insistent
noise, but it is periodic, and not continuous. This is normal. Encoders
have a finite number of positions, and the servo often stops between two
positions. This will cause it to do what's called "dithering",
where it is alternately seeking to find that missing position between
the two locations it can actually measure on the encoder. Dithering is
not overly noisy. Too much noise or continuous noise usually indicates
oscillation. Don't let your servo oscillate for very long without making
an adjustment or you can damage the drive. If an axis is making noise
and the drive is getting hot, you are oscillating, not dithering! If you
can turn up the damping and the noise stops, you were likely oscillating
slightly. If the noise happens right after you move the axis and dies
out, that's oscillation from an underdamped servo.
On my Geckos, I start out a
tuning session with the Gain and Dampening trimpots in about the 11 o'clock
position. This should be enough to allow the servos to at least remain
stationary without faulting. If they fault, try a little more Gain, but
it's likely you have a problem to diagnose if that doesn't fix it up pretty
easily. See the troubleshooting page for
Now tuning is pretty easy.
"Bump" the axis, or as some will say "disturb" the
axis. That means to move it. It's time to move it, move it, as they said
in the movie. Use a motion that has a fair amount of acceleration and
speed, like a fast jog. Also try changing direction. Then stop. What happens?
If nothing happens, turn up the gain a little bit and try again. You are
trying to provoke oscillation. When you get some oscillation, advance
the dampening slightly until the oscillation stops. Try again, first without
moving the gain. If there is oscillation, turn up damping slightly. If
not, turn up gain slightly. Be conservative on the dampening, because
it is hard for you to detect overdamping by ear. You want just enough
to eliminate oscillation, which should be readily audible.
You will go through this cycle
of upping gain and then damping oscillation several times. If you stop
too early, the holding torque on your machine will be "soft"
and you will not have "tight" servo control. When
you have ridden the gain up until you have almost no travel left on the
damping pot to stop oscillation, you are done. You've gotten as much gain
in as you can while keeping it damped. Hopefully it is critically damped
and not overdamped. Now try disturbing the axis again, but this time use
a variety of speeds and accelerations and travels to different locations
on the axis. You want to make sure you haven't overlooked some little
area of the performance envelope where oscillation still exists. That's
why you kept a little extra dampening travel available.
Only connect one axis at a
time so you can hear it well and make sure it is quiet in the shop. Ideally,
you don't even want the other servos "singing" while you tune
Servo Tuning with an Oscilloscope or other Position
vs Time Plot
OK, now let's see how the other
half lives, the "pro" half, because they often use better means
of tuning than ear. Many pro-quality motion controllers and servo drives
have a tuning display built right in that shows graphs like what I've
shown. Some even have a self-tuning mode so you never need to tune manually.
For this discussion, we'll assume the entry level pro approach, which
involves connecting an oscilloscope to your Geckodrive in order to tune
What kind of oscilloscope will
I need? What's expensive on oscilloscopes is bandwidth, and some high-end
features (like a storage 'scope). The good news is it takes a very minimal
oscilloscope to tune servos. As little as 20-30 MHz of bandwidth will
suffice. You want dual channels to connect properly as we'll see. Beyond
that, it's up to you. If you want the oscilloscope to be good for other
things, more features are probably needed. I have an older Tektronix 465
100 MHz scope. It was the workhorse of its day (late 70's), and is a good
general purpose scope. They are widely available used for $200-300. Another
possibility that is cheaper are the USB oscilloscopes that just plug into
Here's how I connect my Tek
465 oscilloscope on the Gecko 320 drives:
- Connect Channel 1 to the
Gecko 320 test point (the location is shown in the Gecko documentation).
DC couple this input. Use the blue capacitor's ground lead to ground this
- Connect Channel 2 to the
direction signal. You will be measuring (or triggering) the curve whenever
the axis changes direction. DC couple this input. Ground to the blue capacitor,
or leave ground disconnected and the scope will use Channel 1 ground.
- Set trigger to "normal",
trigger source to "channel 2", and trigger edge to "+".
- Set the scales to 2V/cm vertical
and 1 millisecond/cm horizontal.
- Adjust the vertical position
of the trace so it is near the bottom, rather than in the middle of the
is connected, but the axis isn't moving yet. I also haven't set everything
up or you wouldn't see that trace without a moving axis!
I use the circle
pocket wizard's g-code for servo tuning. Set a small diameter circle and
a relatively high feed rate and you'll get lots of direction reversals
to use for tuning...
The procedure we will use is
not unlike what we used when tuning by ear, except that now we have an
oscilloscope display to look at. You get one oscilloscope trace every
time you change direction, because the direction change triggers the trace.
So we want to set up the axis so it is receiving a steady command to move
at a particular speed, but the direction is changing constantly. An easy
way to do this is with the interpolated hole wizard in Mach3. If we look
at just one axis, it is constantly reversing direction as the cutter goes
around the circle. Choose a hole with a fairly small diameter, say 1"
or 2", and set the feedrate up low to start with. Use a very shallow
depth of cut so lots of passes will be needed to give you time to finish
tuning before the g-code program runs out.
OK, now run the g-code and
take a look at the oscilloscope display. You should see something close
to one of the three cases mentioned above. If you are underdamped, increase
the damping until the display shows critical damping. If you are overdamped,
increase gain until you can see critical dampening. When you have critical
damping, stop the program, go back to the wizard, and try again with a
higher feedrate. Eventually, you will have tuned the servos to critical
damping all the way up to the maximum feedrate (the max motor speed as
set by the motor tuning in Mach3).
Do you still have more travel
left on the damping trim pot? If so, and you have a good scope display
showing critical damping, you can try for more performance. Go to the
Mach3 motor tuning and you can increase either acceleration or maximum
motor speed. Acceleration is the more valuable of the two to increase,
but it is also the most expensive. In other words you will likely be able
to get more top end than acceleration from your servos.
When you get close to running
out of travel on damping, it's time to stop. No more performance is available.
Remember, a lot of factors will affect the performance over time. Friction
increases if your ways need lube. Gib adjustment can affect tuning too.
Keep an eye on all this.
The biggest difficulty with
the oscilloscope is the waverform display can be a bit unstable. You only
see the trace every other direction change, and it fades pretty rapidly.
So you really want to change directions very frequently to keep repainting
Is the Oscilloscope Better
than Tuning by Ear?
I found the oscilloscope was
a little more sensitive to detecting oscillation than my ear. I trusted
it a little more as a result to get closer to the last little bit of performance.
In practice, I tried tuning each axis by ear and then touching it up with
the oscilloscope just so I could see what difference it would make. Depending
on the axis, I got maybe 10-20% more performance with the oscilloscope.
It may be that you can do just as well if your ear is sensitive or if
you really work at it though.
Based on a 10-20% advantage,
I don't think I would buy an oscilloscope just for this purpose. It will
be hard to use that small improvement in practice. I prefer to think of
it as a little extra safety margin. I dialed back my final accelerations,
for example, just a tad after tweaking them up to their max after an oscilloscope
I got my mill
X and Y axes up to 50 in/sec/sec or 0.13g's acceleration with the o-scope.
Without it, I could only get to maybe 40'ish by ear. Z has the heavy mill
head, so about half this much acceleration is available...
The X-axis right
after o-scope tuning. Full clockwise current, nearly full gain, a little
bit less damping. Your tuning settings will definitely be something different!
- Interpolating a circle generates
code for X and Y axes, what about tuning Z? Lots of ways to skin that
cat. You can modify the g-code with search and replace to change either
the X or the Y motions to be Z motions. Or, you can simply connect step
and dir from X or Y to the Z servo drive to achieve the same result. Don't
forget to connect the right Z step and dir back when you are done!
- Gain controls following error
and damping controls oscillation. If you have too much following error,
but you have successfully damped oscillation and you cannot raise the
gain further (no more travel on damping), you're probably running too
much acceleration and the system just can't keep up. Try reducing the
- In some cases, way to much
damping also leads to oscillation. Back way off on the damping until you're
sure there is not enough. Gradually increase damping until the oscillation
stops. Now you're in the right place.
Related to Servo Tuning
thread on how to connect the oscilloscope to a G320.
Livingston gets help tuning his Bridgeport by ear.
servos for an X3 mill.
using an oscilloscope from Motion Engineering.
Caudle tells how he tunes Geckos by ear.
the Man offers a pdf with tuning tips.