How-to
Path control of a hydraulic cylinder with 4-20 mA feedback
Short answer
Yes, a 4-20 mA transducer closes a hydraulic cylinder position loop as a slow process value, never as an encoder substitute. Scale the 16 mA span to the calibrated stroke, run acquisition, trajectory, control and valve output in one fixed-period task, treat out-of-range current as a motion-stopping fault, and keep the measured input-to-output delay below the following-error budget your velocity allows. Worked example: 250 mm stroke, 200 mm/s, 25 ms budget.

On this page
- Can a 4-20 mA transducer really close a hydraulic position loop?
- How do I scale the 4-20 mA current into cylinder position?
- How fast does the position loop have to run?
- How do I get velocity out of a position-only signal?
- What do I do when the current goes out of range?
- Do I need a dedicated hydraulic-axis module or will a PLC cyclic loop do?
- How do I commission the loop from scratch?
- Why does my cylinder hunt around the target and how do I stop it?
- Questions asked
A 4-20 mA transducer can close a position loop on a hydraulic cylinder — as a process value, not as an encoder. The loop closes in software: scale the current to the calibrated stroke, generate a time-based trajectory, run read, control and output write in one fixed-period task, and treat any out-of-range current as a fault that stops motion. What never works is converting the current to an integer and feeding that integer into a pulse-train input. The decisions below are arithmetic, not judgment calls: a two-point scaling formula, a delay budget of allowed following error divided by commanded velocity, and a commissioning order that switches integral action on last. The worked example is a 250 mm stroke commanded at 200 mm/s with a ±5 mm tracking allowance, which turns into a 25 ms delay budget that every later section leans on.
Can a 4-20 mA transducer really close a hydraulic position loop? #
Yes, for path control at hydraulic speeds: a magnetostrictive in-cylinder transducer on a current loop is an absolute position signal, so a controller that reads it every cycle, generates a time-based trajectory and drives a proportional or servo valve can track position and velocity together.
Path control means the commanded position moves in time and the cylinder must follow, velocity included — a single-axis CNC move, not a go-to-endpoint jog. The simpler endpoint case on a voltage signal is covered in Controlling Hydraulic Cylinder Position From a 0-10V Analog Input; what path control adds is a trajectory to track, which is why delay and update rate become first-order decisions here instead of afterthoughts.
The transducer side is friendly. These sensors are absolute and continuous, built for the pressure, temperature and cycle rates inside a working cylinder, and they report position as a calibrated current, not a pulse train. That property is also the trap. Reading the loop into an integer and presenting that integer to a motion module's encoder port closes nothing: those ports exist for counting encoder pulses on a PLC without losing position, and they count edges, not process values. The loop closes in your code, on a value you scale and sample yourself.
How do I scale the 4-20 mA current into cylinder position? #
Span the 16 mA between the two endpoints: position = retracted + ((measured − 4) ÷ 16) × stroke, so 4 mA is one end, 20 mA is the other, and every milliampere in between is a fixed slice of stroke.
Worked example, in mA directly: a 250 mm stroke, transducer calibrated at its retracted and extended endpoints per the formula above, input reading 12.0 mA.
position = retracted + ((12.0 − 4) ÷ 16) × 250 mm = (8 ÷ 16) × 250 mm = 0.5 × 250 mm = 125 mm
One milliampere is worth 250 ÷ 16 = 15.6 mm of stroke, so an input that resolves 0.1 mA resolves about 1.6 mm of position — the sensor sets the floor before any tuning starts. Calibrate on the machine, not on paper: command the piston to both mechanical stops, record the raw input at each, and scale between the measured values, because a sensor whose low endpoint sits a few millimeters off the stop otherwise puts a constant offset into every target. The raw-to-engineering-units step itself is the same conversion walked through in how PLC analog input and output modules convert signals; the arithmetic does not care whether the raw value is counts, milliamps or an integer, as long as the two calibration points are real.
How fast does the position loop have to run? #
Set the budget from your own numbers: allowed following error divided by commanded velocity, added across the whole path — analog input conversion and filter, task execution, analog output update, valve response — and treat that total as a hard limit the measured delay must come in under.
Worked example: the intro's move allows ±5 mm of tracking error at 200 mm/s, so the budget is 5 mm ÷ 200 mm/s = 0.025 s = 25 ms. Measure what you actually have: command a constant velocity and trend measured position against commanded; a 30 ms total delay shows as a steady lag of 200 mm/s × 0.030 s = 6 mm — over the 5 mm allowance, and no gain removes it, because dead time is not a tuning problem. The fixes are concrete: faster input conversion, lighter filtering, a valve with a quicker response time (take the figure from the valve datasheet), or a slower trajectory until the budget closes. Run the whole chain in one fixed-period task; a variable-duration scan has a delay that changes every scan, and a budget you cannot verify.
How do I get velocity out of a position-only signal? #
Subtract successive position samples and divide by the task period — velocity = (x now − x previous) ÷ Δt — using the real fixed period of your task, never an assumed one, because a variable-scan task makes every velocity figure noisy.
Quantization sets the noise floor. On the 250 mm example with a 10 ms task, if the analog input resolves 0.05 mm of stroke, one raw step of feedback becomes 0.05 mm ÷ 0.010 s = 5 mm/s of velocity step; those inputs are illustrative, so substitute your own resolution and period. Filter only as much as the noise forces: a moving average over N samples adds (N − 1) ÷ 2 samples of delay, so averaging 8 samples on a 10 ms task costs (8 − 1) ÷ 2 × 10 ms = 35 ms — more than the entire delay budget of the section above, spent silently. If the velocity signal needs heavy smoothing to look usable, shorten the task period or get a better input rather than a longer filter.
What do I do when the current goes out of range? #
Treat any reading outside the valid span as a fault: under the NAMUR NE43 convention most transducers follow, current at or below 3.6 mA or at or above 21 mA means a broken loop, and the controller must stop motion and drive the valve to its defined safe state.
The convention's valid span is 3.8 to 20.5 mA, and between 20.5 and 21 mA many transducers hold at end-of-scale instead of faulting, so a value pinned at the top can be saturation rather than motion — treat a pinned reading as suspect until the piston is confirmed at the stop. Your analog input may document its own underrange and overrange thresholds; use those where they differ. Build three explicit fault states: underrange (broken wire or lost supply), overrange (failed or misranged sensor), and frozen (value unchanged while the piston is commanded to move). Each must inhibit automatic motion, hold the valve at its safe state, and require a manual reset. Confirm with a meter, not the screen: read actual milliamps in series at the input terminals at both endpoints. One safety note: the loop cannot protect the machine when its feedback is gone, so this response belongs in your machine's risk assessment alongside the guard and stored-energy practice you already apply.
Do I need a dedicated hydraulic-axis module or will a PLC cyclic loop do? #
A cyclic PLC loop is enough when your delay budget closes and your trajectory is simple; a dedicated hydraulic-axis module earns its cost when you need deterministic trajectory generation, richer diagnostics, or periods a scan-based task cannot hold.
Before choosing any hardware, read four things from its own documentation: accepted position feedback (analog process value or encoder only), input conversion time, effective resolution, and accepted valve command — plus how it reports underrange, overrange and communication loss. A module whose manual lists encoder feedback only will not accept your scaled value, whatever the adapter suggests; the electrical interface and the software convention are different things.
A cyclic loop on general PLC hardware does run hydraulic axes in production when the budget closes — Running Three Phase-Shifted Hydraulic Cylinders With PLC PID is that pattern working across three axes at once. The dedicated module buys trajectory generation and axis diagnostics inside a guaranteed period, which is what to reach for when the plain loop's worst-case scan exceeds the budget. The valve question is the same in both architectures: whether a PLC-driven servo valve can stop a hydraulic ram repeatably is a loop-and-valve property — Can a PLC Servo Valve Stop a Hydraulic Ram Repeatably — not a module property.
How do I commission the loop from scratch? #
Commission in one order: define the trajectory, wire and calibrate the feedback, prove the scaling, add the valve command with limits, close the loop with low gain and no integral, then raise gain and add integral only against a measured steady-state error.
- Fix the requirements first: stroke endpoints, position tolerance, maximum velocity and acceleration, load cases and stop behavior — the inputs that produced the 25 ms delay budget of the worked example above.
- Wire the transducer and prove the loop with a series multimeter: endpoint current confirmed at both mechanical stops, shield landed per your wiring standard, supply per the sensor datasheet.
- Calibrate the scaling from measured raw values at both mechanical stops, never from nominal endpoints on paper.
- Write the fault states — underrange, overrange, frozen — and prove each one inhibits motion before the loop ever runs.
- Put input read, trajectory, control, limiting and output write in one fixed-period task, and compute velocity from that period only.
- Generate the trajectory with velocity and acceleration limits ahead of the position controller; a raw position step commands an instantaneous move no hydraulic axis can deliver.
- Limit the valve command to the range in the valve's documentation, and expect asymmetry: a single-rod cylinder has unequal bore-side and rod-side areas, so one command is not one speed in both directions.
- Close the loop with low proportional gain and integral off, and confirm it holds position without oscillating.
- Add deadband compensation only if the valve's documentation provides for it: a small jump term that carries the spool through its dead zone, trimmed on the machine because it drifts with supply pressure and oil temperature.
- Add integral last, with anti-windup that clamps or back-calculates whenever the output sits at a limit, and only to remove a measured steady-state error.
Why does my cylinder hunt around the target and how do I stop it? #
Hunting usually comes from delay you have not paid for: integrator windup behind a saturated valve output, or gain set past what the total loop delay supports. Cut integral action on saturation and drop gain until the oscillation stops, then rebuild.
Windup is the classic: the integrator keeps summing while the output sits at its limit, and the stored surplus throws the piston past the target on the way back. Stop integrating — or back-calculate the term — whenever the output saturates, and the overshoot collapses. Gain past the delay does the same thing at a higher frequency: with dead time in the loop, gain tuned on a slow move will oscillate on a fast one.
Sort everything else by how cheap it is to check. A command wired backwards slams the piston end to end at full output — check polarity before anything else. Jerky low-speed motion is valve deadband and friction more than tuning, and its anatomy is in Why a Hydraulic Cylinder Jerks When the Valve Shifts. A loop that stays slow no matter the gain is dead time and hydraulic stiffness, the territory of Why PI Tuning Is Slow on a High-Inertia Hydraulic Drive. Trend commanded position, measured position and valve command on one timebase; the trace tells you which of these you have.
Questions asked
What stroke lengths do 4-20 mA cylinder transducers cover?
Magnetostrictive in-cylinder transducers are typically offered in full-scale strokes from about 100 mm to 900 mm, either port-mounted or built into the cylinder, and the element is absolute, so position survives a power cycle. Take the exact range, pressure and temperature ratings from the datasheet of the family you are buying, because they vary between products.
Does a current loop resist the electrical noise near a hydraulic power unit?
Yes; noise immunity is a main reason 4-20 mA is used on machines. A current signal is far less sensitive to induced voltage and cable resistance than a voltage signal, so runs out to a cylinder are practical. Keep the cable shielded, land the shield at one end per your wiring standard, and route it away from solenoid and power leads.
Loop-powered or separately powered transducer, which should I pick?
A two-wire loop-powered transducer draws its supply from the same 4-20 mA loop, which keeps the wiring to one pair but limits what the electronics can consume. A four-wire version carries its own supply and keeps the loop purely a signal. Both read identically at the controller; choose from the transducer datasheet and the input channels you have.
How much position error does a small current error make?
Scale it linearly: position error in mm equals current error times stroke divided by 16 mA. On a 500 mm stroke, 0.1 mA of zero drift or input error moves the computed position by 0.1 mA x 500 mm / 16 mA, about 3.1 mm. Input resolution and transducer linearity set the floor, and no amount of tuning moves it.
