G-code and M-code

The Twinwright controller (kernel) runs the G-code below. The codes follow RS274/NGC and LinuxCNC. A code the controller does not support answers error:20, and the line does nothing.

For the real-time commands (single bytes such as ?, ! and ~), see Protocol. For how the controller differs from other Grbl controllers, see The Twinwright controller.

G-code

CodeMeaningNotes
G0, G1Rapid move, linear feed
G2, G3Arc clockwise, counter-clockwise (I J K or R), helixThe tool follows the true circle. An R-form arc with no chord in its plane answers error:33.
G4 PDwell, P secondsThe dwell lasts as long as programmed.
G5, G5.1Cubic spline, quadratic splineA G5 without I and J continues in the direction the previous move ended.
G7, G8Lathe diameter mode, radius modeLathe mode only ($32=2).
G10 L2, G10 L20Set a work offset
G10 L1, G10 L10, G10 L11Set the tool table32 tools. The table is kept when the controller is off.
G17, G18, G19Select the plane
G20, G21Inch units, millimetre units
G28, G30Go to a stored position through an intermediate point
G28.1, G30.1Store the current position
G33, G33.1, G76Spindle-synchronized motion, rigid tapping, threading cycleThese need a spindle encoder. The MC-1 has none, so they answer error:20.
G38.2–G38.5ProbeThe result is the point where the probe triggered, reported as [PRB:]. Set zero from that point, not from where the axes stopped.
G40Cutter compensation off
G41, G42, G41.1, G42.1Cutter radius compensation: D from the tool table, or .1 with a diameterG17 plane only. Entry and exit moves as in LinuxCNC. A move that would gouge is refused.
G43 Hn, G43.2 HnTool length offset from the tool table, added offset
G43.1Dynamic tool length offset
G49Tool length offset off
G50, G51Scaling off, on
G52Local coordinate systemShares its offset with G92, as in LinuxCNC.
G53Machine coordinates for this line
G54–G59, G59.1–G59.3Work coordinate systems$486 can lock G59.1–G59.3.
G61Exact path
G61.1Exact stopThe axes stop at the end of every programmed move.
G64 P QPath blendingWhere it saves time, the corner between two straight moves becomes an arc within P of the corner. Q is accepted and not used.
G65 P1–P6Built-in macrosSettings, tool offsets, parameters, machine state, probe choice, spindle wait. P7 (Modbus messages) is not supported.
G65 P100 and up, G66, G66.1, G67File macros, modal macro callsP must be an integer. No other command may share the line (error:21).
G73, G81, G82, G83Drilling cycles, peck drillingEach hole gets the pecks it needs.
G84, G85, G86, G89Tapping and boring cycles
G80Cycle off
G90, G91Absolute distances, incremental distances
G91.1Incremental arc centres
G92, G92.1, G92.2, G92.3Coordinate offset: set, clear, suspend, restore
G93, G94, G95Inverse time, units per minute, units per revolutionArcs in inverse time take the programmed time.
G96, G97Constant surface speed, constant spindle speedLathe mode only.
G98, G99Cycle retract to the start height, to the R plane

These G-codes are not supported (error:20):

M-code

CodeMeaningNotes
M0, M1Program pause, optional pauseThe 0x88 real-time command switches M1 pauses on or off.
M2, M30Program end
M3, M4, M5Spindle clockwise, counter-clockwise, off
M6Tool change$341 sets what M6 does. M6 and a motion in one line answer error:40.
M7, M8, M9Coolant: mist, flood, offOn the MC-1, M8 runs the spindle's water cooling.
M25Z up to the homed heightCentroid's code, written by some CAM post-processors.
M48, M49Overrides on, off
M50–M53Feed override, spindle override, adaptive feed, feed hold: on or off
M56Parking on or off
M60Pallet change pause
M61Set the current tool without a change
M62–M65Digital output on or off, with the next move or at onceOn boards with auxiliary outputs.
M66Wait for an inputThe wait starts when the moves before it have ended.
M70–M73Save and restore the modal state
M98 P L, M99Call a subroutine, returnIn programs run from the controller's file system. An M98 sent line by line answers error:39. An M99 in the main program ends it.

These M-codes are not supported (error:20):

Words, syntax and parameters

Line structure

Parameters and expressions

O-words

Polar coordinates

@ is the radius and ^ the angle, in the XY plane around the work origin.

Errors in a line