1 / 16 · Foundations

What an axis actually controls

Follow a move from PLC to carriage, and learn what setpoint, actual position and following error can and cannot prove.

The carton lands short, and the drive says it arrived

A pusher transfers a carton from a conveyor into a fixture. The PLC asks for 250 mm. The drive reports 250 mm. The carton still sits 4 mm short of the fixture stop, and the next station rejects it.

The program did exactly what it was told, so before you change a line of it, find out where position is measured. A motor encoder measures the motor shaft. Backlash in a gearbox, a loose coupling, a stretched belt or a carton sliding on the pusher plate all leave the load somewhere else, and an encoder on the motor sees none of it.

That gap between "the axis" and "the thing you care about" runs through the whole course. The motion controller holds a number. You want a carton in a fixture. This chapter follows the path from one to the other and shows which signal proves what. If you have never commissioned a servo axis, read it slowly: every later chapter assumes these words.

What a motion controller means by "axis"

An axis is the motion controller's model of one mechanism. The model holds a coordinate with units (millimetres, degrees), motion limits, a feedback source, a drive to command and a state such as Disabled, Standstill or ErrorStop. When you call MC_MoveAbsolute you never talk to the motor. You talk to the model, and the model talks to the drive.

There are three common kinds:

  • A physical axis has a real drive and real feedback. The carriage on the bench above is one.
  • A virtual axis has no motor at all. It produces a position that other axes can follow, for example a virtual master that every station on a packaging machine is geared to.
  • An encoder axis has feedback only. It reads something you do not drive, such as a line shaft or a conveyor run by a separate inverter, so other axes can follow it.

In your program the axis appears as an AXIS_REF: a reference to the configured axis. It is not the position, and it is not the drive. Every MC block has an Axis input, and passing the same AXIS_REF to several blocks is how you say "these blocks all command the same motor". Declaring two MC_MoveAbsolute instances does not create two motors. On this site's engine, Ax : AXIS_REF; in VAR creates one simulated axis, and you read it through MC_ReadActualPosition, MC_ReadActualVelocity and MC_ReadStatus.

What sits behind the reference depends on the platform:

PlatformBehind the referenceConfigured in
Beckhoff TwinCAT 3, Tc2_MC2AXIS_REF linked to an NC axisThe NC motion configuration of the project
Siemens S7-1500 and S7-1500TA technology object: TO_SpeedAxis, TO_PositioningAxis, TO_SynchronousAxis or TO_ExternalEncoderTechnology objects in TIA Portal
CODESYS SoftMotionAXIS_REF_SM3, the drive object in the device treeThe SoftMotion axis editor
Omron NJ/NXAn axis variable (_sAXIS_REF), also reachable as _MC_AX[0] to _MC_AX[63]Axis settings in Sysmac Studio
Rockwell LogixAn AXIS_CIP_DRIVE or AXIS_VIRTUAL tag, driven by MAM, MAJ and MAS, which are not PLCopen blocksAxis properties in Studio 5000

One Beckhoff detail catches people early. The Status structure inside a Tc2_MC2 AXIS_REF is a processed copy, and it is not refreshed by itself. Beckhoff's documentation says to call Axis.ReadStatus() once at the start of every PLC cycle, or to use MC_ReadStatus. Forget it and your sequence reads a status that never changes.

Follow one command from the PLC to the load

Here is the path a single "go to 250 mm" takes on a typical servo axis:

  1. Your sequence raises Execute on MC_MoveAbsolute with a target, a velocity and an acceleration.
  2. The motion runtime's trajectory planner (often called the interpolator) works out a profile and, every motion cycle, a new setpoint.
  3. The fieldbus carries that setpoint to the drive. EtherCAT drives that follow the CiA 402 profile usually run in cyclic synchronous position mode (CSP), where the setpoint is a position. SINAMICS drives on PROFINET use a PROFIdrive telegram.
  4. The drive closes its control loops and turns the setpoint into motor current.
  5. Motor torque goes through a coupling, a gearbox and a screw or belt to the carriage.
  6. The encoder reports where the shaft went, and the motion runtime converts that into the actual position in millimetres.

A setpoint is where the controller wants the axis to be at this instant, calculated from the profile. It is also called the command position. The target is where the move ends. During a move these are two different numbers: the target stays at 250 mm while the setpoint walks towards it, a little further every motion cycle.

The drive runs three loops inside each other. The current loop controls the motor's electrical effort, which is torque. Around it, the velocity loop controls shaft speed. Around that, the position loop corrects the difference between setpoint and actual position. Each inner loop must be much faster than the one outside it, so the current loop on an industrial servo drive usually updates in a fraction of a millisecond, while the motion cycle that produces setpoints runs at something like 1 to 4 ms. Your PLC task, at 10 ms, is slower still.

Put numbers on one move. A 250 mm transfer that takes 1.5 s spans about 150 calls of your function block in a 10 ms PLC task, 750 setpoints from a 2 ms motion cycle, and many thousands of current-loop updates in the drive. When someone says "the PLC controls the motor", ask which of those loops they mean. Usually they mean the 150 calls, and the motor is controlled by the drive.

Where the position loop lives depends on the architecture. In CSP mode the controller sends positions and the drive closes the position loop. In cyclic synchronous velocity mode (CSV) the controller closes the position loop itself and sends a velocity command. Both are legitimate, and they change where you tune. The name of the network alone tells you little about motion quality: PROFINET with IRT, or EtherCAT with distributed clocks, gives a synchronised cycle, and the drive and controller still have to be configured to use it.

Setpoint, actual position and following error

Four numbers describe an axis at any moment. They answer different questions, and none of them proves everything.

QuantityWhat it tells youWhat it cannot prove on its own
Target positionWhere the application wants the move to finishThat the planner accepted it
Setpoint (command position)The planner's demand at this instantThat the mechanics followed it
Actual positionFeedback converted into axis unitsWhere the product is after a slipping coupling
Following errorSetpoint minus actual position, at the same instantWhy the axis is not keeping up

Following error, also called lag or position deviation, is normal while an axis moves. A position loop with gain Kv and no feedforward lags behind by roughly velocity divided by Kv. With Kv = 40 s⁻¹ and a carriage at 200 mm/s, that is 200 / 40 = 5 mm. Velocity feedforward hands the drive the speed it needs directly, and the same move then lags by a fraction of a millimetre. A small lag that holds constant while the speed is constant is healthy. A lag that keeps growing means the axis is overloaded or blocked.

Compare values from the same instant. If the actual position you read is one 4 ms motion cycle older than the setpoint, then at 200 mm/s your computed following error is 200 × 0.004 = 0.8 mm too large. At 1,000 mm/s the error is 4 mm. Most motion runtimes hand you setpoint and actual position in the same cycle structure, so take both from there instead of mixing a value from your PLC task with one from the drive.

Controllers monitor following error themselves. TwinCAT's position lag monitoring has a maximum lag value and a filter time: when the lag is above the value for longer than the filter time, the NC stops the axis with error 0x4550 (17744 decimal). The filter time keeps a short spike during hard acceleration from tripping the axis. Sign conventions differ between platforms, some reporting setpoint minus actual and some the reverse, so compare magnitudes when you port an alarm from one vendor to another.

The live example below puts the same model behind a real MC_MoveAbsolute. The engine has no drive or mechanics, so its position is a perfect setpoint. The program adds a soft simulated drive that closes 40 % of the gap per scan, roughly ten times softer than a tuned servo, which makes the numbers big enough to read.

PROGRAM Main
VAR
    Go        : BOOL;          (* input: start the transfer *)
    Ax        : AXIS_REF;      (* pusher axis, units mm *)
    Power     : MC_Power;
    Move      : MC_MoveAbsolute;
    ReadCmd   : MC_ReadActualPosition;
    Cmd       : REAL;          (* engine position = ideal setpoint *)
    Act       : REAL;          (* simulated load position *)
    ActPrev   : REAL;          (* last scan's load position *)
    FollowErr : REAL;          (* setpoint minus actual, same scan *)
    StaleErr  : REAL;          (* setpoint minus last scan's actual *)
    InPos     : BOOL;          (* Done and the load inside 0.5 mm *)
END_VAR

Power(Axis := Ax, Enable := TRUE);
Move(Axis := Ax, Execute := Go, Position := 250.0, Velocity := 100.0,
     Acceleration := 500.0, Deceleration := 500.0);

ReadCmd(Axis := Ax, Enable := TRUE);
Cmd := ReadCmd.Position;

(* A soft simulated drive: closes 40 % of the gap every 100 ms *)
ActPrev := Act;
Act := Act + (Cmd - Act) * 0.4;

FollowErr := Cmd - Act;
StaleErr  := Cmd - ActPrev;
InPos := Move.Done AND ABS(FollowErr) <= 0.5;
END_PROGRAM
Live example — open this page with JavaScript to run and edit it. Inputs you can drive: Go.

Switch Go on and step through. During the cruise FollowErr sits at 15 mm and StaleErr at 25 mm. The 10 mm difference is one scan of travel, exactly the mistake you make by mixing timestamps. Then watch the end of the move. Move.Done comes on while the simulated load is still about 12 mm short, and InPos follows several scans later as the load settles. On this engine Done means the setpoint reached the target. Real controllers add an in-position check: Omron has an In-position Range and In-position Check Time, and TwinCAT can make Done wait for its target position monitoring. Execute, Busy, Active and Done goes through those settings.

Give zero and the positive direction a physical meaning

A coordinate is only useful if you can walk up to the machine and point at it. Give zero a physical meaning: the fixture datum, the edge of a reference switch, or a position you established with an absolute encoder and wrote down. Record which way is positive. On the bench above, positive travel moves the carriage to the right and the units are millimetres. Its rail drawing is illustrative and has no end stops.

A ball-screw feed usually works in millimetres and a rotary index table in degrees. Both blocks take a number called Position, so the number means nothing without the axis configuration behind it. A target of 90 is a quarter turn only on an axis scaled in degrees; on the screw axis it is 90 mm. Units, encoders and screw pitch builds that conversion, Homing and coordinate validity covers how zero gets attached to the machine, and Positioning and continuous travel handles rotary axes that wrap at 360°.

Direction is set in more than one place, which is how it goes wrong. A typical failure: a drive is replaced after a fault, the new one arrives with factory parameters, and the old one had its direction reversed in a drive parameter. The first jog goes left instead of right. The software limits were built on the old coordinate, so they protect the wrong end of the stroke. The fix is a commissioning record that lists every place direction is set (drive parameter, axis configuration, encoder setting) plus a saved copy of the drive parameters, and a slow test move after any drive swap before automatic mode is allowed.

Where position is measured decides what it proves

An encoder proves what happens at its own mounting point. Everything between that point and the product is outside its view:

Between motor and productTypical sizeSeen by a motor encoder?
Gearbox backlashA few arc-minutes at the outputNo
Belt stretch under accelerationGrows with force and belt lengthNo
Timing belt skipping a toothOne tooth pitch, 5 mm on an HTD 5M beltNo
Thermal growth of a steel screwAbout 0.0115 mm per metre per °CNo
Coupling slip after a crashAny amountNo
Product sliding on a pusher or gripperAny amountNo

The thermal line is easy to underestimate. A 1 m steel screw that warms by 10 °C over a morning grows by about 0.115 mm. On a carton pusher nobody cares. On a machine that places parts to 0.05 mm, it decides whether you need a load-side scale.

Some axes have a second encoder on the load, such as a linear scale on the carriage, and the drive or controller can use it for the position loop (often called dual-loop or full closed loop). Even with a single encoder you can add a plausibility check: compare the motor-side position with a cheaper load-side measurement and alarm when they drift apart. The next example does that on a belt conveyor with simulated slip.

PROGRAM Main
VAR
    Run         : BOOL;          (* input: run the belt *)
    Slip        : BOOL;          (* input: the belt starts slipping *)
    Realign     : BOOL;          (* input: re-reference load to motor *)
    Belt        : AXIS_REF;      (* belt axis, units mm *)
    Power       : MC_Power;
    Drive       : MC_MoveVelocity;
    ReadPos     : MC_ReadActualPosition;
    MotorPos    : REAL;          (* motor-side position, mm *)
    MotorPrev   : REAL;
    LoadPos     : REAL;          (* load-side measurement, mm *)
    Discrepancy : REAL;          (* motor minus load, mm *)
    SlipAlarm   : BOOL;
END_VAR

Power(Axis := Belt, Enable := TRUE);
Drive(Axis := Belt, Execute := Run, Velocity := 200.0,
      Acceleration := 1000.0, Deceleration := 1000.0);
ReadPos(Axis := Belt, Enable := TRUE);
MotorPos := ReadPos.Position;

(* Load side: follows the motor, loses 5 % while slipping *)
IF Slip THEN
    LoadPos := LoadPos + (MotorPos - MotorPrev) * 0.95;
ELSE
    LoadPos := LoadPos + (MotorPos - MotorPrev);
END_IF;
MotorPrev := MotorPos;

IF Realign THEN
    LoadPos := MotorPos;
    SlipAlarm := FALSE;
END_IF;

Discrepancy := MotorPos - LoadPos;
IF ABS(Discrepancy) > 2.0 THEN
    SlipAlarm := TRUE;           (* latched until Realign *)
END_IF;
END_PROGRAM
Live example — open this page with JavaScript to run and edit it. Inputs you can drive: Run, Slip, Realign.

Run the belt at 200 mm/s, which is 20 mm per scan, then switch Slip on. The load loses 1 mm per scan and the alarm latches on the third scan. Switch Slip off: the discrepancy stops growing but does not go away, because the lost millimetres are lost. A slipped belt behaves the same way, so the alarm stays latched until someone has checked the belt and realigned the two measurements.

For a real transfer station, accept a move only when three separate conditions hold:

  1. The motion command completed: Done, not CommandAborted or Error.
  2. The feedback is plausible: actual position within a window of the target, and load-side and motor-side measurements agree if you have both.
  3. A product sensor confirms the transfer.

The carton from the first section passes the first two and fails the third.

Field story: the carton that kept landing short

The symptom was a carton 4 mm short of the fixture on roughly one cycle in five, never on the first cycle after a restart. Following error was small throughout the move, and Done came on every time.

The previous commissioning engineer had raised the position loop gain, then the velocity loop gain, chasing the error. The motor tracked its setpoint more tightly than ever, and the cartons still landed short, because the loss happened after the encoder. A camera on the pusher showed the cause: the pusher plate decelerated hard at the end of the stroke, and a full carton slid 4 mm on the plate while the plate itself arrived exactly. On the first cycle after a restart the plate was dry; once it picked up dust from the cartons it slid.

The fix had two parts. The deceleration of the last 30 mm was reduced so the carton stopped with the plate, and a photo-eye at the fixture became the third acceptance condition, with a timeout and an alarm instead of a silent reject downstream. Tuning was put back to its original values.

When following error stays small and the product still lands in the wrong place, look at the mechanics and the product before touching the loops. If you have motor and load feedback, compare them at low speed first. Draw the command path for the axis, mark where position is measured, and name one fault that point would miss.

A following-error alarm you can trust

A useful following-error alarm needs two thresholds, like the TwinCAT monitoring above: a magnitude that normal motion never reaches, and a time the error must stay above it, so a spike during a hard acceleration does not stop production. Once it trips, it should hold the axis, stay latched until someone acknowledges it, and refuse to restart the move on its own. An alarm that clears itself and lets a held start button restart the axis is how a jammed carriage gets driven into the jam a second time.

Try it on the bench

The bench above runs TryPLC's motion runtime at 20 ms per scan, with the same blocks the examples use. Its default move goes to 200 mm at 100 mm/s with 200 mm/s² acceleration and deceleration.

  1. Press Reset bench. Switch Move Execute on before Drive enable and press Advance one scan. Error is TRUE with ErrorID 1, this runtime's code for "axis not powered". The target was never accepted.
  2. Switch Move Execute off, Drive enable on, advance one scan, then switch Move Execute on and press Run scans. Work out the time first: 0.5 s to accelerate (covering 25 mm), 150 mm at 100 mm/s (1.5 s) and 0.5 s to brake, so about 2.5 s or 125 scans. Check the terminal's t when Done comes on.
  3. Set the target to 0, switch Move Execute off and on to start the return, and switch it off again halfway. The accepted move carries on to its target. The function block decides when the command is complete; how long the button was held makes no difference.
  4. Set the target to -50 mm and run it. The carriage passes the 0 mark. A real axis would stop at a software limit set inside its hardware limit switches, which sit inside the mechanical stops. The bench has none of the three.

Where motion logic ends and safety begins

Everything in this chapter is ordinary control: following-error alarms, plausibility checks, software limits and MC_Stop. None of it is a safety function. People are protected by functions such as Safe Torque Off (STO), SS1 and safely limited speed (SLS), defined for drives in IEC 61800-5-2, triggered by a safety relay or safety PLC and validated against the machine's risk assessment. STO is wired from that safety circuit, never from an ordinary MC_Power output. Your program should still read the safety state and react to it, so the sequence knows why the axis lost torque, but it does not replace it.

Before testing on physical equipment, use the machine's risk-assessed safety arrangement, the current manufacturer documentation and the site's approved procedure.

References

Check your reasoning

The motor encoder says the carriage reached 250 mm and following error stayed under 0.2 mm, yet the carton sits 4 mm short of the fixture. Where do you look first?

  • Raise the position and velocity loop gains
  • Shorten the PLC task cycle
  • The mechanics after the encoder
  • The drive's current loop settings
Worked answer

The mechanics after the encoder. A small following error proves the motor followed its setpoint. A loss after the encoder (coupling, belt, product sliding on the pusher) is invisible to it, so higher gains change nothing.

You compute following error from this cycle's setpoint and an actual position that is one 4 ms motion cycle older. The axis runs at 500 mm/s. How much error does the timestamp mismatch add?

  • 0.4 mm
  • 2 mm
  • 5 mm
  • 20 mm
Worked answer

2 mm. In 4 ms at 500 mm/s the axis moves 500 × 0.004 = 2 mm, so mixing timestamps inflates the error by that much. Take setpoint and actual position from the same cycle.

A position loop has Kv = 25 s⁻¹ and no feedforward. The carriage cruises at 300 mm/s with a constant 12 mm lag. What does that tell you?

  • Normal: 300 / 25 is 12 mm
  • The axis is jammed and will trip on lag soon
  • Encoder scaling is wrong by a factor of twelve
Worked answer

Normal: 300 / 25 is 12 mm. Without feedforward a proportional position loop lags by about velocity divided by Kv. A lag that matches v / Kv and stays constant is healthy; a growing one would point to a jam or overload.

A failed drive is replaced, and the first jog moves the carriage the opposite way. Which record would have prevented the surprise?

  • A backup of the PLC program only
  • The saved drive parameters
  • The motor's nameplate data
  • The HMI alarm history
Worked answer

The saved drive parameters. Direction is often reversed by a drive parameter. A new drive arrives with factory settings, so without the saved parameter set the reversal is lost and the software limits protect the wrong end.

Your following-error alarm trips on most hard accelerations, although every move arrives correctly. Which change keeps it useful?

  • Raise the limit until the alarm stays quiet
  • Switch the monitoring off during acceleration phases
  • Add a filter time
Worked answer

Add a filter time. A brief spike during acceleration is normal lag. Requiring the error to persist for a set time ignores it but still catches a sustained jam; raising the limit or switching monitoring off hides real faults too.