LinuxCNC
LinuxCNC (formerly Enhanced Machine Controller, EMC2) is an open-source CNC machine control system that runs on a real-time Linux kernel. It provides motion planning, G-code interpretation, hardware I/O, and a configurable user interface for mills, lathes, plasma cutters, 3D printers, robots, and custom automation equipment.
Architecture
LinuxCNC is structured as a set of cooperating processes connected by a shared-memory HAL (Hardware Abstraction Layer):
- HAL (Hardware Abstraction Layer) — real-time signal bus connecting components via named pins and parameters; components can be kernel modules or user-space; configuration via
.halfiles orhalcmd - Motion controller (EMCMOT) — real-time kernel thread running under PREEMPT-RT or RTAI; executes trajectory planning, PID loops, and encoder/drive I/O at servo period (typically 1 ms)
- Task controller (EMCTASK) — user-space process; interprets G-code, coordinates motion and I/O, handles MDI commands, and manages tool and offset tables
- G-code interpreter (RS274NGC) — full RS274/NGC dialect with subroutines, parameters, expressions, and O-word looping; supports custom M-codes backed by Python or HAL
- NML messaging — inter-process communication layer between the UI, task, and motion controllers
- User interfaces — Axis (Tkinter/OpenGL), Gmoccapy (GTK), QtDragon (Qt5), Touchy (touchscreen), Probe Basic; all communicate via NML
- Classicladder — soft PLC with ladder logic diagrams; runs as a HAL component for interlocking, safety logic, and sequential control
Embedded and Real-Time Use
- PREEMPT-RT — the recommended real-time kernel for LinuxCNC on x86-64; servo periods of 250 µs to 1 ms are achievable on modern hardware
- RTAI — legacy real-time kernel patch; still supported but PREEMPT-RT is preferred for new installations
- HAL components — written in C with
hal_init()/hal_export_pin()API or in Python; compiled as kernel modules for hard real-time or as user-space threads for soft real-time - Mesa Electronics cards — the standard hardware interface; FPGA-based PCI/PCIe/Ethernet cards handle step generation, encoder counting, and PWM at rates the PC kernel cannot sustain; driven by
hm2_pci/hm2_ethHAL drivers - Parallel port and GPIO — software step generation via
parportorhal_gpiofor low-speed machines; limited to ~40 kHz step rate - EtherCAT — supported via the
lcecHAL component (using IgH EtherCAT master); enables servo drives, I/O modules, and encoders over standard Ethernet
Configuration
Machine configuration lives in an INI file (machine.ini) with sections for:
[AXIS_n]— per-axis limits, homing sequence, PID gains[TRAJ]— trajectory planner parameters (max velocity, acceleration, arc error)[EMCMOT]— servo period, base period[HAL]— list of.halfiles to load at startup
The linuxcnc-uspace variant runs the motion controller in user space, easing development and testing on non-RT kernels.
Versioning
| Branch | Status | Notes |
|---|---|---|
| 2.9.x | Current stable | Python 3, Qt UIs, joint/axis rework |
| 2.8.x | Maintenance | Python 2 removed, RTAI still supported |
LinuxCNC follows a slow, quality-driven release cadence; 2.9 has been in development since 2020 and is the recommended branch for new installations.
Upstream Contribution
LinuxCNC uses GitHub pull requests against the master branch. Code review is done by maintainers on the forum and mailing list. Tests run under the Buildbot CI system. Key tools: runtests (HAL/G-code regression suite), linuxcnc-build scripts.
Related Technologies
- Linux Kernel — PREEMPT-RT patches are essential for LinuxCNC servo operation
- MachineLinux — 32bitmicro's industrial Linux distribution; a natural host OS for LinuxCNC deployments
- Mesa Electronics — dominant FPGA I/O card vendor for LinuxCNC hardware interfaces
- Machinekit — a fork of LinuxCNC targeting BeagleBone and cloud-connected CNC; diverged from mainline circa 2014
- grbl — lightweight G-code interpreter for Atmel/STM32 microcontrollers; not real-time Linux