AutomateDirectUSAMotion LibraryIndustrial monitors & PCs

Explainer

Why backlash compensation overshoots the destination

Servo and stepper motion Published 6 min read By AutomateDirectUSA engineering team

Short answer

Backlash compensation is added outside the position loop, so an axis with linear-scale feedback stops exactly one backlash amount past the destination. Disable the built-in compensation, rebuild the same ramp in a user program at a rate corrected for its slower interval, and bleed the injection down so the scales close what remains.

On this page
  1. Where the loop closes decides what the jump means
  2. The exaggerated test that pins the jump to the destination
  3. Why tuning alone keeps losing this race
  4. Rebuild the ramp where you can change it
  5. Bleed the injection off and let the scales finish
  6. The decision
  7. Questions asked

If the feedback that closes your position loop is a linear scale on the table, built-in backlash compensation will stop the tool past every destination by exactly the backlash amount. That is not a tuning fault and not a wiring fault. The compensation is added to the axis destination outside the position loop, and a loop that measures the table drives faithfully to destination plus backlash, so it is never asked to remove the injection. On a mill with 1 µm scales and closed-loop AC servos whose measured backlash spans 0.005 to 0.011 in the machine's user units, setting the compensation to 0.010 and commanding a 1 in move stopped the tool at 1.010. The fix is to leave the built-in compensation off, rebuild the same ramp in a user program at a rate corrected for its slower interval, and then shrink the injection so the scales close what remains.

Where the loop closes decides what the jump means #

The same compensation value means opposite things depending on which side of the backlash the feedback sits. With a rotary encoder on the motor, behind the gearbox and ahead of the gap, the loop cannot see the table at all. After a reversal the encoder reports the position the table will reach once the gap is crossed, so adding the backlash amount to the destination is a correct model of real motion; classic compensation methods for semi-closed-loop servo control are built on exactly that assumption. With a linear scale mounted on the table, the measured position already includes the backlash error. The controller still adds the amount to the destination, so the loop now steers the table itself to destination plus backlash, which is a genuine physical overshoot.

Which side of the backlash the loop closes on is the same question that decides a servo conversion; where the position loop closes decides your servo conversion works through it. The placement also shows up as a different symptom when compensation meets jog moves: why backlash compensation makes jog moves erratic covers that case.

The exaggerated test that pins the jump to the destination #

Set the compensation to 0.010 and command a 1 in move. The axis executes the initial compensation jump, runs the commanded inch, and the scale reads 1.010: 1.000 + 0.010 = 1.010, so the miss equals the compensation amount exactly. Reverse the direction and command the inch back: the injected amount ramps out along the way, the move ends with no injection left, and the axis returns to 0.000 accurately. The overshoot therefore appears on moves that continue in a direction the ramp has already saturated, and it always equals the amount still injected at convergence. The loop is doing its job perfectly; it is just doing it to a destination that includes the jump.

The internal routine that runs every servo cycle while compensation is enabled is short enough to read in full, and KFLOP's C source publishes it as DoBacklash:

void DoBacklash(CHAN *chx)
{
    if (chx->Dest > chx->PrevBacklashDest + chx->BacklashAmount * 0.005)
    {
        chx->PrevBacklashDest = chx->Dest;
        chx->BacklashDirection = 1;
    }
    else if (chx->Dest < chx->PrevBacklashDest - chx->BacklashAmount * 0.005)
    {
        chx->PrevBacklashDest = chx->Dest;
        chx->BacklashDirection = -1;
    }
    chx->Backlash += chx->BacklashRate * chx->BacklashDirection * TIMEBASE;
    if (chx->Backlash > chx->BacklashAmount)
        chx->Backlash = chx->BacklashAmount;
    else if (chx->Backlash < 0.0f)
        chx->Backlash = 0.0f;
}

Three lines decide the behavior. Direction flips only when the destination passes the previous reversal point by BacklashAmount * 0.005; with the amount at 0.010 that threshold is 0.010 × 0.005 = 0.00005, a small anti-dither band. The injected value then ramps at BacklashRate * TIMEBASE per call, clamped between 0 and BacklashAmount. The controller calls this function every 90 µs, so BacklashRate is calibrated for 90 µs steps.

Why tuning alone keeps losing this race #

With compensation off, the loop does correct the reversal: the scale sees the table stop, the following error grows, and the loop pushes the motor through the gap. The problem is time. At low speed the error does not accumulate fast enough to build output before the cutter engages the wall, which is what gouges pockets and inside threads. On this machine, raising the integral gain far enough to correct at low speed caused oscillation at higher speeds, and the derivative gain was still zero, so there is untuned margin left. Start there, derivative up from zero and integral in small steps, because a loop that converges the reversal inside your gouge tolerance before the cutter arrives needs no injection code at all. Drive and control vendors also document observer-based tuning that compensates for disturbances such as backlash automatically; that changes what the loop estimates instead of what you inject, and it is worth checking whether your drive family offers it.

Rebuild the ramp where you can change it #

  1. Turn built-in backlash compensation off. The controller then stops calling DoBacklash, and nothing adds the amount to the destination.
  2. Copy the logic above into a user program and call it continuously from a single thread that loops forever on one WaitNextTimelice() call. That user loop executes every 180 µs; the internal call ran every 90 µs.
  3. Correct the ramp rate. One second holds 1 / 0.000090 s ≈ 11,111 internal calls but only 1 / 0.000180 s ≈ 5,556 user-loop passes, so half the calls would add half the amount each second. Replace TIMEBASE with 2.0 * TIMEBASE in the increment line; each call then adds twice as much, and the ramp saturates in the same time as before.
  4. Run the 1 in test again and confirm your copy reproduces the original overshoot before changing anything. A faithful port that overshoots identically proves the harness is right, and only then do you modify behavior.

Bleed the injection off and let the scales finish #

Once the ramp lives in your code, the injection no longer has to survive to convergence. Apply it quickly at the reversal, since it is motion the machine must physically make anyway, then reduce it while the loop closes the remaining error from the scales, so the tool converges on the commanded destination instead of destination plus backlash. Treat that as a hypothesis to prove on your machine, not as documented controller behavior. Short moves can end before the injected amount is removed, and the bleed-down has to be gentle enough not to fight the loop. Closing the loop on an external scale has prerequisites of its own; what an external encoder position loop needs to close lists them before you rely on the scales for the final approach.

Verify with direction reversals and short moves before any cutting. Record the commanded destination, the linear-scale position, the injected backlash value and the following error through each reversal, and run the sequence dry with the cutter clear of the work. Accept the change only when the axis lands on the commanded destination with none of the exaggerated-test offset and no oscillation across the speeds and loads you actually run.

The decision #

  • Motor or gearbox encoder only, no table feedback: keep the built-in compensation. Its model matches that machine, and the amount belongs in the destination.
  • Linear scales closing the loop: built-in compensation stays off in every branch. Enabled, it lands the tool past the destination by exactly the injected amount, and no gain setting changes that.
  • If raised derivative and stepped-up integral gains converge a reversal inside your gouge tolerance before the cutter arrives, you are done: no injection code.
  • If tuning oscillates at speed before it converges at low speed, rebuild the ramp in a user program with 2.0 * TIMEBASE, prove your port reproduces the overshoot, then bleed the injection down and let the scales finish.
  • If you ever move feedback from the table back to the motor side, the compensation model changes with it; switching a CNC axis from linear scale to motor encoder covers that move.

Questions asked

What units does the backlash amount use?

The amount uses the same user units as every other position value on the axis, including the commanded destination and the scaled feedback counts. The measured 0.005 to 0.011 figures and the 0.010 test value are all user units on that machine, and the direction threshold and ramp rate inherit those units, so changing user units rescales every constant at once.

Why does a short reversal still land short of the destination with compensation enabled?

Because the injected value is a ramp, not a step. Direction flips only after the destination passes the previous reversal point by 0.5 percent of the backlash amount, and the value then builds at the programmed rate toward the full amount. A move that ends before the ramp finishes leaves only part of the amount injected, so test the shortest and fastest reversals you run, not just full-size moves.

Why not patch a correction on top of the built-in compensation?

You cannot cancel cleanly what another function adds. Built-in compensation adds the amount to the channel destination before the loop runs, so a program-side correction would have to predict and subtract a ramp executing inside the controller at every cycle. Disable built-in compensation and own the whole ramp in your user program instead; one piece of code then controls the injected value and can reduce it as the scales close the remaining error.

Keep reading

  • Explainer

    What an External Encoder Position Loop Needs to Close

    The axis reference an encoder block returns is a measurement, not a loop: an external encoder closes the servo position loop only where the drive or motion controller documents a secondary feedback assignment for the commanded axis. Verify direction, scaling, motion-block compatibility and encoder-loss faulting before you enable, and tune for the reversal transient the backlash now creates inside the loop.

    Servo and stepper motion

  • How-to

    Tuning a Closed-Loop Stepper With Linear Scale Feedback

    Commission the axis open loop first, verify both linear scale channels and the counts-per-unit constant with gains at zero, then close the loop at an integral gain near 0.01 with about 100 Hz filtering. Backlash, stiction and compliance end up inside the loop, so it limit-cycles at rest — fix the mechanics and the gains together.

    Servo and stepper motion

  • Explainer

    Why a Closed Loop Stepper Hunts on Linear Encoder Feedback

    A linear encoder finer than the smallest step your drive can reach does not make a closed loop stepper hunt. Hunting starts only when the loop keeps issuing corrective pulses across a target it can never hit. Derive the smallest axis increment from command pulse scaling times the screw lead, compare it with the scale increment in the same units, and set the in-position window wider than half that increment.

    Servo and stepper motion

Why Tool Cups Save Y Travel on a Pneumatic Sliding Tool Rack