Skip to content

Useful code snippets

Sven edited this page May 4, 2021 · 5 revisions

Useful code snippets

Check linuxcnc for further GCode information.
Here are some useful gcodes for use inside scripts or custom buttons:

Move in absolute machine coordinates (homing with end-switches is needed)

Note: Used coordinates are individual for each machine!

G90 G0			(absolute distance mode, rapid move)
G53 Z-10		(move in machine coordinates to save height)
G53 X-150 Y-50		(move in machine coordinates to stationary switch/tool length sensor)

Probing (assume units = mm, tool stays above tool length sensor)

Note: Used coordinates are individual for each machine!

G38.3 Z-30 F100		(probe towards tool length sensor, maximum 30 mm downwards, speed 100 mm/min, stop on contact)
G43.1 Z#PRBZ		(Offset Tool with result from probing)
G91 G0 Z5		(move relative 5 mm upwards, to get free from sensor)
G90			(switch back to absolute distance mode)

Other internal variables

PRBX, ...Y, ...Z	// Probing coordinates
PRDX, ...Y, ...Z	// Probing delta coordinates delta = actual - last
MACX, ...Y, ...Z	// actual Machine coordinates
WACX, ...Y, ...Z	// actual Work coordinates
MLAX, ...Y, ...Z	// last Machine coordinates (before break)
WLAX, ...Y, ...Z	// last Work coordinates (before break)
TOAN			// Tool Actual Number
TOAX, ...Y, ...Z	// Tool change position
TOLN			// Tool Last Number
TOLX, ...Y, ...Z	// Tool Last change position

GMIX, GMIY, GMIZ	// Minimum values of graphics dimension
GMAX, GMAY, GMAZ	// Maximum values of graphics dimension