GCode is the most common language for programming CNCs. GCode is made up of simple commands that are easy for machines to understand. Many of these commands (such as G0 and G1) are common to nearly every CNC but most machines have their own unique codes and so there are many GCode dialects. There are also other languages for programming CNCs, such as TPL.

CAMotics supports a subset of LinuxCNC GCode. The GCode commands supported by CAMotics are listed here.

Code Parameters Description
Motion
G0 axes Rapid Move
G1 axes Linear Move
G2, G3 axes I J K or R, P Arc Move
G4 P Dwell
G5 X Y I J P Q Cubic Spline
G5.1 X Y I J Quadratic Spline
G5.2 P X Y L NURBS
G38.2 - G38.5 axes Straight Probe
G33.1 X Y Z K Rigid Tapping
Homing & Probing
G28.2, G28.3 axes (Un)set Axis Homed State
G38.6 - G38.9 axes Seek Switch
Tool Control
T Select Tool
M6 T Tool Change
M61 Q Set Current Tool
G10 L1 P axes R I J Q Set Tool Table
G10 L10 P axes R I J Q Set Tool Table
G10 L11 P axes R I J Q Set Tool Table
G43 H Tool Length Offset
G43.1 axes Dynamic Tool Length Offset
G43.2 H Apply additional Tool Length Offset
G49 Cancel Tool Length Compensation
Feed Control
F Set Feed Rate
G93, G94, G95 Feed Rate Mode
M52 P0 (off) or P1 (on) Adaptive Feed Control
M53 P0 (off) or P1 (on) Feed Stop Control
Spindle Control
S Set Spindle Speed
M3, M4, M5 S Spindle Control
M19 R Q P Orient Spindle
G96, G97 D S Spindle Control Mode
G33 X Y Z K Spindle Synchronized Motion
Coolant
M7, M8, M9 Coolant Control
M7.1, M8.1 Disable Coolant
Stopping
M0, M1 Program Pause
M2, M30 Program End
M60 Pallet Change Pause
Units
G20, G21 Units (inch, mm)
Distance Mode
G90, G91 Distance Mode
G90.1, G91.1 Arc Distance Mode
G7 Lathe Diameter Mode
G8 Lathe Radius Mode
Cutter Radius Compensation
G40 Compensation Off
G41, G42 D Cutter Compensation
G41.1, G42.1 D L Dynamic Cutter Compensation
Path Control Mode
G61, G61.1 Exact Path Mode
G64 P Q Path Blending
Overrides
M48, M49 Speed and Feed Override Control
M50 P0 (off) or P1 (on) Feed Override Control
M51 P0 (off) or P1 (on) Spindle Speed Override Control
Coordinate Systems, Offsets & Planes
G54-G59.3 Select Coordinate System
G10 L2 P axes R Set Coordinate System
G10 L20 P axes Set Coordinate System
G53 Move in Machine Coordinates
G92 axes Coordinate System Offset
G92.1, G92.2 Reset G92 Offsets
G92.3 Restore G92 Offsets
G28, G28.1 axes Go/Set Predefined Position
G30, G30.1 axes Go/Set Predefined Position
G17 - G19.1 (affects G2, G3, G81…G89, G40…G42) Plane Select
Flow-control Codes
o sub/endsub/call Subroutines, sub/endsub call
o while Looping, while/endwhile do/while
o if Conditional, if/else/endif
o repeat Repeat a loop of code
[] Indirection
o call Call named or numbered file
Modal State
M70 Save modal state
M71 Invalidate stored state
M72 Restore modal state
M73 Save and Auto-restore modal state
Input/Output
M62 - M65 P Digital Output Control
M66 P E L Q Wait on Input
M67 T Analog Output,Synchronized
M68 T Analog Output, Immediate
User Defined Commands
M101 - M199 P Q User Defined Commands
Canned cycles
G73 X Y Z R L Q Drilling Cycle, Chip Breaking
G76 P Z I J R K Q H E L Threading Cycle
G80 Cancel Canned Cycle
G81 X Y Z R L Drilling Cycle
G82 X Y Z R L P Drilling Cycle, Dwell
G83 X Y Z R L Q Drilling Cycle, Peck
G84 X Y Z R L Right-Hand Tapping Cycle
G85 X Y Z R L Boring Cycle, Feed Out
G86 X Y Z R L P Boring Cycle, Spindle Stop, Rapid Move Out
G87 X Y Z R L I J K Back Boring Cycle
G88 X Y Z R L P Boring Cycle, Spindle Stop, Manual Out
G89 X Y Z R L P Boring Cycle, Dwell, Feed Out
G98, G99 Canned Cycle Return Level
Comments & Messages
; (…) Comments
(MSG,…) Messages
(DEBUG,…) Debug Messages
(PRINT,…) Print Messages

This section describes extra GCodes not support by LinuxCNC.

G28.2, G28.3 (Un)set Axis Homed State

G28.2 axes
G28.3 axes

G28.2 and G28.3 are typically used as part of an axis homing procedure.

G28.2 sets the specified axes unhomed. By setting the global variables _<axis>_homed to zero. The value specified in the axis variable is not used. For example:

G28.2 X0    (_x_homed = 0)

G28.3 does four things for each axis specified:

  1. Set the axis' absolute position to the value in the axis variable.
  2. Set the axis' global offset to zero.
  3. Mark the axes homed by setting the global variable _<axis>_homed to one.
  4. Save the new absolute position in the global variable _<axis>_home.

For example:

G28.3 Y0 A0 (_y_homed & _a_homed = 1 and _y_home & _a_home = 0)

After seeking an axis' maximum position you would likely set a positive value for the absolute position. For example:

G28.3 X300 (_x_homed = 1 and _x_home = 300)

It is an error if:

  • No axis is specified.

G38.6 - G38.9 Seek Switch

G38.6 axis or G38.6 P- axes (Seek active switch with error)
G38.7 axis or G38.7 P- axes (Seek active switch without error)
G38.8 axis or G38.8 P- axes (Seek inactive switch with error)
G38.9 axis or G38.9 P- axes (Seek inactive switch without error)

G38.6 - G38.9 execute a straight incremental move at the current feedrate. The move will halt or ramp down to a stop when the specified switch changes to the target state. If the switch is already in the target state no move is made. G38.6 and G38.8 will trigger an error if the move completes with out the switch reaching to the target state. G38.6 and G38.7 seek an active switch whereas G38.8 and G38.9 seek an inactive switch.

These commands can be specified either with a single axis and relative position or with one or more axes with the target switch specified through the P parameter. Seek moves are always incremental moves and are not affected by the distance mode codes G90 and G91.

When only a single axis is specified the target switch is determined by the axis and travel direction. If the travel direction is negative a min switch is sought otherwise a max switch. For example, to seek the active X-min switch with error traveling no more than 100 units:

G38.6 X-100

Arbitrary linear moves can be made by explicitly specifying a switch ID via the P variable. Possible switch IDs are as follows:

ID Switch ID Switch
0 X-min 1 X-max
2 Y-min 3 Y-max
4 Z-min 5 Z-max
6 A-min 7 A-max
8 B-min 9 B-max
10 C-min 11 C-max
12 U-min 13 U-max
14 V-min 15 V-max
16 W-min 17 W-max
18 Probe

The following example seeks the inactive A-max switch without error while moving in both X and Y:

G38.9 P7 X20 Y20

Whether such a move makes sense depends on the machine. Some machines may support additional switch IDs.

It is an error if:

  • No feed rate has been set.
  • No axis is specified.
  • More than one axis is specified with out P.

M7.1, M8.1

M7.1 (Turn mist coolant off)
M8.1 (Turn flood coolant off)

These commands allow you to turn off mist and flood coolant separately. Use M9 to turn off both at once.

This section lists features of the LinuxCNC GCode language which are not yet implemented in CAMotics:

  • Cutter radius compensation. G40, G41.1, G42, G42.1  #296
  • Canned cycles. G73, G76, G83, G84, G87, G88. Issue  #39.
  • Cubic and quadratic B-splines. G5 & G5.1.
  • NURBS. G5.2 & G5.3.
  • Feed modes: inverse time, units per revolution. G93 & G95. Issue  #40. (Only important for estimating run time)
  • Lathe Modes G7 & G8.
  • Spindle-synchronized motion. G33.
  • Rigid Tapping. G33.1.
  • More than 3-axis simulation. Issue  #17.

This list is probably incomplete.

Here you will find additional GCode resources from the LinuxCNC website: