TG Motion  version 421 - 4033/904 cnc 121
Real-time system for controlling servo drives and I/O modules
G-code description

Supported and internal G/M functions.

Addresses

All parameters of the G or M functions are called addresses. Addresses are always composed with a letter and number (e.g. X 20.45). Some of the addresses are modal, i.e. the value is kept in the following G functions even if they are not specified in the G-code. TG Motion supports up to 10 interpolated axes. The mapping of address letters to axis index is fixed:

Letter X Y Z C B U V W A O
Index 0 1 2 3 4 5 6 7 8 9

Values in the addresses can be numbers, parameters or mathematical expressions. See G-code extensions.

G Functions

G functions are used mainly for movements, but have also some specialized meanings. The following functions are internally supported by the system:

Function Addresses (optional are in [] brackets) Description
G0 [X] [Y] [Z] [C] [B] [U] [V] [W] [A] [O] Rapid linear travese movement.
G1 [X] [Y] [Z] [C] [B] [U] [V] [W] [A] [O] [F] Linear movement, feed is specified in the F address (in mm/min).
G2, G3 [X] [Y] [Z] [I] [J] [K] [C] [B] [U] [V] [W] [A] [O] [F] Arc movement CW (G2) or CCW (G3). Center is defined by IJK addresses relatively from start point.
G2, G3 [X] [Y] [Z] [I] [J] [K] [C] [B] [U] [V] [W] [A] [O] [F] Q70 Arc movement. Center is defined by IJK addresses in absolute coords.
G2, G3 [X] [Y] [Z] R [C] [B] [U] [V] [W] [A] [O] [F] Arc movement. Center is defined by radius R. Maximal arc angle is <= 180°.
G4 [W ms] or [T H X s] Wait (dwell). Time is specified in seconds (addresses T or H or X) or in miliseconds (address W).
G17 Set arc movement plane to XY.
G18 Set arc movement plane to XZ.
G-18 Set arc movement plane to ZX (lathe only).
G19 Set arc movement plane to YZ.
G21 Empty function, does nothing
G24 Lathe only: radius programming. Treat values in X as radius (default is diameter).
G25 [L number] or [label] Call subroutine on line N number or starting with label. Alias for keyword CALL. Subprogram must end with M17 or RETURN.
G26 [L number] or [label] H repeats Call subroutine repeatedly (repeats times).
G27 [L number] or [label] Jump to line N number or to label. Alias for keyword GOTO.
G29 any text Comment in the G-code text. Comment can also start with // (double slash), REM keyword or ( (opening bracket)
G33 [X] [Y] [Z] [K or F] Screw (movement in sync with spindle). K or F specifies the screw pitch.
G40 End of tool compensation.
G41 Tool compensation on the left side of tool path. Compensation size is given by GCODE_PARAMETERS::correction[0].
G42 Tool compensation on the right side of tool path. Compensation size is given by GCODE_PARAMETERS::correction[1].
G43 Tool compensation on the left side of tool path. Compensation size is given by GCODE_PARAMETERS::correction[2].
G44 Tool compensation on the right side of tool path. Compensation size is given by GCODE_PARAMETERS::correction[3].
G45 Tool compensation on the left side of tool path. Compensation size is given by GCODE_PARAMETERS::correction[4].
G46 Tool compensation on the right side of tool path. Compensation size is given by GCODE_PARAMETERS::correction[5].
G47 Tool compensation on the left side of tool path. Compensation size is given by GCODE_PARAMETERS::correction[6].
G48 Tool compensation on the right side of tool path. Compensation size is given by GCODE_PARAMETERS::correction[7].
G53 Disable zero offset (set to zero).
G54 [X] [Y] [Z] Set zero offset. Addresses not present in the G54 set the particular offset to zero. (G54 X10 is the same as G54 X10 Y0 Z0).
G55 [X] [Y] [Z] Set zero offset. Same as G54.
G56 [X] [Y] [Z] Set zero offset. Same as G54.
G57 [X] [Y] [Z] Set zero offset. Same as G54.
G59 [X] [Y] [Z] Set zero offset. Addresses not present in the G59 does not change the particular offset of that axis.
G90 [X] [Y] [Z] [C] Set absolute programming. Values in the XYZCBUVWAO addresses are treated as absolute. If any of XYZC addresses are present in G90, acts as G1 as well (with absolute coords).
G91 [X] [Y] [Z] [C] Set relative programming. If any of XYZC addresses are present, acts as G1 as well (with relative coords).
G92 [X] [Y] [Z] [C] [B] [U] [V] [W] [A] [O] Sets the new value to specified axis (without any movement).
G94 Set feed (address F) in mm/min units. Lathe only: also disable constant cutting speed.
G95 Set feed in mm/rev units.
G96 Lathe only: set constant cutting speed - spindle speed changes with radius (X address)
G97 [S] Lathe only: disable constant cutting speed. If address S is present, set turn speed value (does not change the actual spindle speed).
G98 [X] [Y] [Z] [C] [B] [U] [V] [W] [A] [O] Reference. Must have support in PLC for reference axis moves. After successful reference, spcified coordinates of axes are set.
G167 [E] [A] [U] [Q] Enable/disable auto insert arcs between lines. E is maximal allowed deviation, A is minimal deviation, U is maximal angle (90° is default), Q is arc plane. Use G167 without addresses to disable arc insertion.
G168 X Y Z R [Q plane] Rotation. Depending on plane, XYZ is center of rotation, R is angle. Q is optional (must be 17/18/19), if not used, the last G17/G18/G19 is used to determine the rotation axis (always perpendicular to the plane).
G168 X Y Z I J K R Rotation. Center is given by XYZ, rotation axis by vector IJK. R is rotation angle.
G169 Switch off rotation.
G172 [R] [C] [D] Affects tool companesation calculation. R sets CORR_STRATEGY_NO_ADD_R value, C sets number of parts to be searched for possible crosses (see CORR_STRATEGY_SEARCH_DEEP_ALL), D sets (1) or disables (0) CORR_STRATEGY_REMOVE_SMALL_ARCS.
G173 Set default strategy for tool compensation: Sets CORR_STRATEGY_REMOVE_SMALL_ARCS, CORR_STRATEGY_DEFAULT_DEEP and disables CORR_STRATEGY_NO_ADD_R.
G900 S value [additional addresses] Change settings of GCODE_PARAMETERS. See Special settings function G900 for detailed description.

M functions

M functions are used for specialized tasks like start spindle rotation, cooling off/on, etc. There are built-in functions with standardized (default) actions. At the startup, the built-in M fucntions are active, but the their default behaviour can be disabled (then the function will be signalled to PLC as normal M function). Changing the meaning of the buil-in functions can be done either by settings in .INI file or by using GCODE_PARAMETERS fields programatically.
All the signalled M functions need support in PLC.
A few M functions are fixed, cannot be redefined and are not signalled to PLC.

Function Addresses (optional are in [] brackets) Description
M0 Unconditional stop. Cannot be redefined. This function is not signalled to PLC.
M1 Synchronize. Waits till interpolator finishes all the G-code parts from buffer and then continue. Not signalled to PLC.
M2 End of G-code. Can be redefined in .INI file or by GCODE_PARAMETERS::M02_programEnd1.
M3 [S] Start spindle in CW direction. Spindle speed is given by S address or by previous G97 S... function. Can be redefined in .INI file or by GCODE_PARAMETERS::M03_startSpindleCW.
M4 [S] Start spindle in CCW direction. Spindle speed is given by S address or by previous G97 S... function. Can be redefined in .INI file or by GCODE_PARAMETERS::M04_startSpindleCCW.
M5 Stop the spindle. Can be redefined in .INI file or by GCODE_PARAMETERS::M05_stopSpindle.
M6 T [D] [Z] Change tool. T is tool number, D is optional tool diameter, Z is optional length correction. For mill-like machines. Can be redefined in .INI file or by GCODE_PARAMETERS::M06_changeTool.
M6 T [X Y Z] Change tool. T is tool number, XYZ are optional tool placement correction. For lathe.
M7 Cooling ON. Can be redefined in .INI file or by GCODE_PARAMETERS::M07_coolOn.
M8 Lubricating ON Can be redefined in .INI file or by GCODE_PARAMETERS::M08_oilOn.
M9 Cooling and lubricating OFF. Can be redefined in .INI file or by GCODE_PARAMETERS::M09_coolOilOff.
M17 Return from subroutine. Alias to keyword RETURN. Can be redefined in .INI file or by GCODE_PARAMETERS:M17_return.
M29 Print text report. Alias to keyword PRINT. Can be redefined in .INI file or by GCODE_PARAMETERS::M29_print.
M30 End of G-code. Can be redefined in .INI file or by GCODE_PARAMETERS::M30_programEnd2.
M80 Switch OFF mirroring. Can be redefined in .INI file or by GCODE_PARAMETERS::M80_mirrorOff.
M81 Mirror on X axis (change sign on all the X axis values). Can be redefined in .INI file or by GCODE_PARAMETERS::M81_mirrorX.
M82 Mirror on Y axis. Can be redefined in .INI file or by GCODE_PARAMETERS::M82_mirrorY.
M83 Mirror on Z axis. Can be redefined in .INI file or by GCODE_PARAMETERS::M83_mirrorZ.
M84 Mirror on X and Y axes. Can be redefined in .INI file or by GCODE_PARAMETERS::M84_mirrorXY.
M85 Mirror on X and Z axes. Can be redefined in .INI file or by GCODE_PARAMETERS::M85_mirrorXZ.
M86 Mirror on Y and Z axes. Can be redefined in .INI file or by GCODE_PARAMETERS::M86_mirrorYZ.
M87 Mirror on X, Y, and Z axes. Can be redefined in .INI file or by GCODE_PARAMETERS::M87_mirrorXYZ.
M99 F Set default feed. All the movement G functions with F0 will use the specified feed. Can be redefined in .INI file or by GCODE_PARAMETERS::M99_defFeed.

All the others M functions (till M999) are signalled to PLC and are waiting functions, i.e. the movement stops till PLC signals M function finish by zeroing INTERPOLATOR::M_Func value. Normal M functions can have any addresses (with the exception of G, M, N and P) and these values are also signalled to the PLC.
M functions with numbers greater than 1000 (M1001 and above) are so called continous functions. These can be appended in the G-code after the movement functions (G1, G2, G3) and are signalled to the PLC without wait for its finish. Continuous functions are signalled at the begin of the particular movement.

G1 X 14.2 Y 45.89 M2003

Special M functions

There is also a set of buil-in M functions with negative numbers. These M functions are not signalized to PLC.

Function Addresses (optional are in [] brackets) Description
M-5 [X0/1] [Y0/1] [Z0/1] [C0/1] [B0/1]] [U0/1] [V0/1] [W0/1] [A0/1] [O0/1] Disable (0) or enable (1) limits for specified axis. The limit values must be already set in GCODE_PARAMETERS::axisLimits array.
M-6 [A plcDataAddress] [S gCodeIndex] If A address is used, save G-code index of the actual part to PLC shared memory (TGM_Data) at the byte address given by A. If S address is used, gCodeIndex value is the new start value of the G-code parts which follows the M-6.