X CNC Library
From G-code to the axes: spline merging, corner smoothing, look-ahead velocity planning, 1 ms interpolation and 5-axis RTCP.
In short
X CNC Library is a path planning and interpolation library developed by ONX Control for CODESYS V3.5 based CNC machines. It merges the short lines coming from CAM into quintic splines within the contour tolerance, smooths corners with verified transition bridges, plans look-ahead velocity from the axis velocity/acceleration/jerk limits and produces position targets for the X/Y/Z/A/C axes every 1 ms. With RTCP the program describes the tool tip; production functions such as the tool changer, program check and start from line come with the web HMI.
With M140 the program describes the tool tip; X/Y/Z are corrected while A/C rotate and the tip stays on the path.
Fully used and never exceeded on a 64,058-line program.
Finished without error in 29:36; no command limit overruns, longest 1 ms task cycle 640 µs.
On the 64,058-line program, tracked by an overrun counter.
Measurements from ONX lab tests: CODESYS Control RTE, Intel J1900 industrial PC, 1 ms EtherCAT task, virtual axes. Real-axis, servo following and surface measurements are done on the machine during commissioning.
From G-code to axis position
Geometry preparation and motion execution run on separate time scales. The 20 ms Path task reads the program, refines the geometry and plans velocity; ready objects are written to a queue. In the 1 ms EtherCAT task the Interpolator produces an axis position target from this queue in every cycle. The whole file does not have to be loaded in advance; the queue streams live (including a 139,882-line program). With RTCP on, the tool tip transformation sits between the interpreter and spline merging, so the planner sees the real motion of the axes.
What is G-code, explained on video
How a G-code block is built, the most important G and M codes, a complete part program line by line, and how the controller runs it with look-ahead and interpolation.
- Modal commands; G0, G1, G2/G3 and G17/G18/G19; G90/G91, G20/G21
- G54 work offset, G43 tool length, G41/G42 radius compensation; M3, M6, M8, M30
- Generic ISO/Fanuc-style codes; X CNC has its own dialect (feed in mm/s)
What is CNC, explained on video
How a CNC machine turns a drawing into a part: the control chain from CAD to servo axis, interpolation, the closed loop, axis layouts, machine types and real time in PC-based CNC.
- CAD → CAM → G-code → controller → interpolator → servo drive → axis
- Encoder feedback and following error; 3, 4 and 5 axes, RTCP
- Resolution, repeatability and accuracy; EtherCAT, 1 ms cycle and jitter
Short lines, one smooth spline
CAM output often describes free-form surfaces with thousands of sub-millimetre G1 lines. A path that changes direction at every vertex keeps forcing the speed down and makes the axes shudder.
X CNC merges consecutive lines into quintic (5th-order) splines that stay inside the contour tolerance. Every candidate is verified numerically; a candidate that leaves the tolerance tube, loops or drifts away from the contour is rejected.
- Merge and corner smoothing use one tolerance budget
- Programmed stops, M and H points are preserved
- An upper deviation bound is recorded and traceable for every object
Through the corner without stopping, within tolerance
Instead of an exact stop where two objects meet, both sides are trimmed and a quintic transition bridge is built. The bridge deviation is limited by the remaining tolerance budget; on short objects both ends share one trim allowance so the bridge is not shortened unnecessarily.
- Corner smoothing set from the program with G51 D
- Corner rounding within angular tolerance while A/B/C rotate
- A separate corner tolerance for consecutive G0 moves
- On circles written as coarse polygons the spline chain is broken at the sharp corner and G51 rounds it
Continuous acceleration, not steps
The end of a G-code line is not a reason to slow down by itself. The look-ahead planner evaluates upcoming objects together; as long as geometry and dynamics allow, speed rises to the target feed in one acceleration rather than step by step over short objects.
Path speed and axis speed are kept apart: every axis's own velocity, acceleration and jerk limits enter the plan; real corners, programmed stops and physical limits are respected.
- Per-axis V / A / J limits and path jerk
- 0–100 % override in motion with jerk-limited transitions
- Controlled and quick stop, resume from where it stopped
- Velocity-limit reason per line: F, axis velocity, axis acceleration, radius or curvature change
Deterministic in a 1 ms cycle
In every EtherCAT cycle the Interpolator produces the next position target from the plan; lines, arcs, ellipses and splines are evaluated with the same length model. Heavy plan updates are split into a per-cycle time budget so the 1 ms task is not disturbed.
Position gaps at start-up and during operation are closed with jerk-limited motion; at the end of the program the axes settle on the last point.
Rotary axis smoothing on 5 axes
In programs where the tool axis changes with A and C, rotary motion is smoothed with a cubic Hermite law through the source nodes. Angular deviation is bounded by its own tolerance; rotary speed does not jump at object boundaries and the path does not slow down needlessly at A/C nodes.
In a lab test on a 4,822-line 5-axis program all 4,796 rotary transitions were smoothed (0 fallbacks), with A/C deviation 0.006° and XYZ deviation 0.0061 mm.
A 139,882-line 5-axis turbine program finished without error in 29:36. Narrowing the A/C tolerance from 1.5° to 0.3° left the time unchanged (29:35) and cut the A/C deviation from 0.75° to 0.15°.
RTCP: the program describes the tool tip, the controller carries the head
Without RTCP (Rotational Tool Center Point) a 5-axis program contains the positions of the machine axes: the post processor embeds the tool length and head dimensions in the program. When the tool is reground or changed, or the part zero shifts, the program has to be posted again; with a tilted head, turning A makes the tool tip drift.
In X CNC, M140 in the program switches RTCP on: X Y Z are now the tool tip position and F is the tip speed. The kinematics core maps every move to the machine axes before planning; X/Y/Z are corrected while A/C rotate and the tip stays on the programmed path. Tool length, tool offsets and work zero are read live, so the program is independent of the tool.
In the video
- 0:00Start and M140: RTCP on
- 0:10Orientation only: the tool tip stays still while A turns 30° and C 360°
- 0:23A straight tip line while the tool tilts; an arc (G2) with a tilted tool
- 0:37A G0 with changing orientation and a 3+2 (A −45°) plunge
- 0:53A straight tip line while C turns 180°; back to machine coordinates with M141
M140 / M141 and tip speed
RTCP is switched on and off inside the program. F is the tool tip speed; on a line that only changes orientation, F is the angular speed (°/s).
G0, G1, G2/G3 in tip space
The tip stays on the line or arc: the move is split into pieces whose tip deviation from the programmed path stays within 0.005 mm, and the pieces are merged into splines again.
A/C tolerance from the tip allowance
In an RTCP job the rotary tolerance is computed as contour tolerance / lever (0.019° at 150 mm pivot to tip). The HMI shows the upper bound of the tip deviation.
TCP jog and Move to
Jog in Machine, Work or Tool coordinates; the tip stays in place while A/C turn. Move to goes to a work or machine position at feed or rapid.
Retract along the tool axis
Start from line and return after intervention at M: retract along the tool axis, then the target orientation, then descend along the tool axis. The retract distance is adjustable.
Tool change with a tilted head
M6 K<n> also works with RTCP on: RTCP is suspended during the change, the tool retracts along its axis, the head straightens at safe Z, then the tool is dropped and picked.
Kinematics setup
Head or table with up to two rotary axes; the parameters are entered in the web HMI under Settings → Kinematics with an animated diagram and are retentive.
Visibility for the operator
Tool tip position in machine and work coordinates, an RTCP badge on the job card, the tip trace in the 3D view; a warning in the program panel if G53 is written inside RTCP.
If no kinematics are defined or the program has no M140, the planner runs exactly the same path as without RTCP; this is checked after every change with a regression test of 17 test programs. RTCP tests were done with virtual axes on CODESYS Control RTE and in CODESYS simulation; the machine's kinematic dimensions are measured and entered during commissioning.
A CNC operator panel in the browser
The web HMI offers the same functions from any device on the machine network (PC, tablet, phone) and works as the operator panel in full screen and kiosk mode. It talks to the PLC over OPC UA; bulk data such as trace and file transfer flows over a separate TCP link.
What is on the panel?
- One-click start, live job status
- 3D path: program, command and actual trace
- 5-axis head model, tip trace with RTCP
- Path V/A/J charts, override
- 1 ms live trace, CSV
- Servo and smoothing contour deviation
- Time over F: lost time and its reason
- Check program, Start from line
- Single block, Stop at next
- Manual / TCP jog, Move to
- Tool table and measurement
- Kinematics diagram, settings backups
- G-code editor, N renumbering
- File sending with progress window
Axes, manual motion, job progress, override, contour deviation, M and H state.
Program, executed path, set and real path; tool axis, deviation magnification.
Path and axis velocity/acceleration/jerk, limit lines, 1–10 ms sampling, CSV.
Screenshots are from the web HMI demo mode (simulated machine); the values on screen are not measurement results.
Program and machine functions for production
Next to path planning, the functions a CNC needs for daily use on the shop floor come ready on the PLC side and are operated from the web HMI.
G-code (DIN 66025)
G0, G1, G2/G3 arcs and helices, G4 dwell, G51 corner smoothing, G75, G53/G54 and live variables such as $XOFF$, subprograms; modal commands from the CODESYS interpreter.
Unsupported code shield
Codes this chain does not implement, such as radius compensation (G41/G42), G43, G5/G6 and G10, are stopped with the line number before motion starts and flagged in the program panel beforehand.
Program check before cutting
Without moving the axes and faster than real time: expected job time, axis min/max, software limit overruns (axis, value, line), axes not installed on the machine.
Start from line
Starts at the selected line; skipped M functions and the H output state are shown first. The approach is a Z-safe three-step move, along the tool axis with RTCP.
Single block and next stop
In single block the job stops after every line and continues with Next block; "stop at next stop" can be given while running.
Time over F
The extra time of every line over the programmed F and its reason: F/path limit, axis velocity, axis acceleration, radius, curvature change or a stop. The path view can be coloured by reason.
Tool changer
M6 K<n>; the change, measure and reference moves are editable G-code subprograms, the magazine, gripper and probe steps run in the PLC. Tool length is measured with a probe.
Intervention at M functions
While the program waits at an M function the axes can be jogged or moved; on acknowledgment they return to the stop point and continue.
H switching points
Outputs switched at a position along the path; does not stop the motion or break spline merging.
Override and stop
0–100 % override in motion, pause/resume, controlled and quick stop; transitions are jerk-limited.
Diagnostics, trace and contour deviation
Servo deviation (normal distance of the actual position from the command path, cutting and G0 separately) and smoothing deviation; largest jerk and its location; trace down to 1 ms.
3, 4 or 5 axes
On a machine without A and/or C the axis is switched off in the settings; if a program tries to move a missing axis the job stops.
Settings backup
Each time the settings are stored, the web HMI automatically backs up the axis, CNC and lock code values; any backup can be loaded into the editor and written to the controller.
Regression test
After every library change, 17 test programs run through the same chain in CODESYS simulation; time, stop and limit results are compared with the previous version.
Protection and delivery
Compiled library, X Motion lock code, software limit fence, manual motion safety via HMI heartbeat.
From a DXF drawing to an X CNC program
No CAM needed for simple contours: it converts your DXF file to G-code that follows the X CNC rules, shows the toolpath in 3D and simulates the motion with a velocity model close to X CNC. The file is processed in your browser and never uploaded.
All DXF geometry
Lines, arcs, polylines, ellipses, blocks (arrays, mirrored, nested), hatch boundaries and NURBS splines. Splines are split into equal G1 pieces of the length you choose; X CNC merges and smooths them with G38 O1.
G-code by the X CNC rules
One G per line, arcs as G2/G3, F for cutting and FF for G0 (mm/s), G51 D corner smoothing. Codes the shield would stop, such as G41/G42, G5 or G10, are never written; the .cnc file loads directly.
Line ↔ drawing link
Click a piece in the drawing to see its G-code line, or click a line to see it in the drawing. Each line shows its DXF entity, layer and length.
3D toolpath
Safe height, plunges and passes in 3D; rotate, zoom, Z exaggeration and the stock plane. One click switches to the 2D top view.
Motion simulation
Acceleration and jerk limited velocity profile, corner speeds, override; path velocity, acceleration and jerk charts and an X/Y/Z/A/C readout. On two sample programs the job time was within 1.5 % of the X CNC CODESYS simulation.
A / C rotary axes
Tangential knife / wheel following with C, wrapping onto tubes and shafts with A, bevel cutting with A + C and RTCP (M140).
No CODESYS SoftMotion licence required
X CNC Library drives the axes with ONX's X Motion Library, performs interpolation with its own Interpolator and the RTCP transformation with its own kinematics core. CODESYS's licensed SoftMotion axis definitions and SMC_Interpolator are therefore not used.
Not required
- SoftMotion axis licence
- SoftMotion CNC interpolator licence (SMC_Interpolator)
- SoftMotion kinematic transformations for RTCP (X CNC's own kinematics core is used)
- An extra licence for G-code reading/interpreting (SMC_ReadNCFile2, SMC_NCInterpreter)
Required
- The controller's CODESYS Control runtime licence
- ONX X Motion lock code (activates X CNC and X Motion)
Operator panel
For the web HMI the PLC publishes about 450 OPC UA tags, tool changer and RTCP included, staying below CODESYS's 512-tag limit that needs no extra licence. Trace and file transfer use a separate TCP link.
Licensing terms may vary with the CODESYS version and controller; your project's licence list is confirmed together at the quotation stage.
Lab measurements
The values below come from ONX's own test records. Conditions: CODESYS Control RTE, Intel J1900 industrial PC, 1 ms EtherCAT task, virtual axes; contour tolerance 0.05 mm, axis jerk limit 4·10⁵. Rows marked simulation ran in CODESYS simulation with the same planner chain.
| Program | Measured | Result |
|---|---|---|
| Free-form surface, 64,058 lines (57,187 G1) | Contour deviation · axis jerk | Max 0.0500 mm (tolerance 0.05 mm) · 0 overruns |
| Relief, 8,235 lines | EtherCAT jitter · longest ipo() call | Max 28 µs · 764 µs (within the 1 ms task) |
| 5-axis, 4,822 lines | Rotary smoothing · deviation | 4,796 / 4,796 transitions, 0 fallbacks · A/C 0.006°, XYZ 0.0061 mm |
| Free-form surface, 64,058 lines | Before / after time-budgeted planning | Max jitter 4460 µs → 27 µs |
| 5-axis turbine, 139,882 lines | Time · command limit overruns | 29:36 without error · 0 |
| 5-axis turbine, 139,882 lines | A/C tolerance 1.5° → 0.3° | Time 29:36 → 29:35 · A/C deviation 0.75° → 0.15° |
| End of the 5-axis turbine, 2.3 million cycles | Task times (web HMI and screen recording connected) | 1 ms EtherCAT: longest cycle 640 µs, jitter ±33 µs · 20 ms Path: longest 12.3 ms, no missed cycles |
| RTCP: ONX logo on an R120 dome, tool normal to the surface (simulation) | Tool tip deviation · limit overruns | ≤ 0.005 mm · 0 (3:17, without error) |
| RTCP: 3+2 drilling program from CAM, tool change included | Tip deviation from the drilling line | 0.0000 mm |
Which hardware does it run with?




Related: CNC metal cutting · Custom machine software · Motor sizing · X Motion Library · DXF to G-code converter
X CNC and CNC machines + camera-based alignment
The position and angle of a sheet or part placed anywhere on the table are found by camera and passed to X CNC Library's work coordinate system (origin and rotation), shortening manual referencing. On glass and wood, the sheet edge and defective areas can become inputs to the cutting or painting plan. The machined part's dimensions can be checked before it leaves the machine.
Frequently asked questions
What is X CNC Library?
A CNC path planning and interpolation library developed by ONX Control for CODESYS V3.5 based machines. It refines the geometry coming from G-code within the contour tolerance, plans velocity from the axis dynamics and produces position targets for X/Y/Z/A/C every 1 ms.
Which CODESYS version does it work with?
The library is developed and compiled with CODESYS V3.5 SP22 Patch 3. Axes are driven through ONX's X Motion Library; G-code reading and interpretation use CODESYS's standard NC reader and interpreter.
How is the contour tolerance kept?
Spline merging and corner smoothing share one total tolerance budget and never spend it twice. Each spline candidate is verified inside the tolerance tube through the convex hull of its Bézier control points; a candidate that cannot be verified is shortened or the raw geometry is kept.
What does it do on 5-axis programs with A and C?
A separate angular tolerance (default 0.3°) is set for the rotary axes; A/B/C motion is smoothed with a cubic Hermite law through the source nodes, so the rotary axis speed does not jump at object boundaries. Corners can also be rounded within this tolerance while A/B/C rotate. In an RTCP job this tolerance is narrowed automatically so that the allowance at the tool tip is not exceeded.
Does X CNC support RTCP (tool center point control)?
Yes. M140 in the program switches RTCP on and M141 switches it off. With RTCP on, X Y Z are the tool tip position and F is the tip speed; while A/C rotate, the controller corrects the axes through inverse kinematics and keeps the tip on the programmed path. G0, G1 and G2/G3 run in tool tip space. Tool length, tool offsets and work zero are read live, so the program does not have to be re-posted when the tool is reground or changed. The kinematics are set by parameters as head or table with up to two rotary axes.
Is the tool tip kept during manual motion?
Yes. Jogging is possible in the Machine, Work or Tool coordinate system; in Work and Tool the tool tip stays in place while A/C are turned, and in Tool, Z is a retract along the tool axis. The approach when starting from a line, the return after intervention at an M function and a tool change with a tilted head are also done by retracting along the tool axis.
Is there a tool changer and tool length measurement?
Yes. M6 K<n> in the program changes the tool. The change, measure and reference moves are G-code subprograms that can be adapted to the machine; the magazine, gripper and probe steps run in the PLC. Tool length is measured with a probe, the tool table is in the web HMI and the offsets enter the program through live variables ($XOFF$ …).
Can a program be checked before cutting?
Yes. Check program in the web HMI runs the program through the same planner without moving the axes and faster than real time: the expected job time, axis min/max values, software limit overruns (axis, value, line), axes that are not installed and unsupported G codes are reported before cutting starts.
Is there an operator panel?
Yes. A browser-based web HMI (PC, tablet, phone; full screen / kiosk): axes, manual and TCP motion, job monitoring, program check, start from line, single block, 3D path view with a 5-axis head model, live trace, contour deviation, velocity-limit reason (Time over F), tool table, kinematics setup, settings backups and a G-code editor.
Is a CODESYS SoftMotion licence required?
No. Axes are driven with ONX's X Motion Library and interpolation is done by X CNC's own Interpolator; CODESYS's licensed SoftMotion axis definitions and SMC_Interpolator are not used, and the RTCP transformation is in X CNC's own kinematics core. The SM3_CNC components used for reading and interpreting G-code (SMC_ReadNCFile2, SMC_NCInterpreter) do not require a licence. The controller's CODESYS Control runtime licence and ONX's X Motion lock code are required.
How is it delivered?
The library is delivered as a compiled CODESYS library together with an example machine project and the HMI, and is activated with the X Motion lock code. Commissioning and adaptation to the machine are planned with ONX engineers within the project.
Let's look at X CNC on your CNC machine
Share your machine type, axis layout, drives and a sample G-code program; we will come back for a demo with the web HMI and adaptation to your machine.
In this section
Estun Automation
CODESYS
Crevis
Nexcom / Nexcobot
Leroy-Somer
Servo Systems
AC Drive + Motor
DC Drives
Smart PLC
Panel PC / IPC
Remote I/O