G-code (also RS-274), which has many variants, is the common name for the most widely used numerical control (NC) programming language. It is used mainly in computer-aided manufacturing to control automated machine tools.
G-code is a language in which people tell computerized machine tools how to make something. The "how" is defined by instructions on where to move, how fast to move, and what path to move. The most common situation is that, within a machine tool, a cutting tool is moved according to these instructions through a toolpath and cuts away material to leave only the finished workpiece. More details in Wikipedia's G-Code article.
This page describes the G-Code words supported by Easy CNC firmware (eCNC fw) and how they work. The fw follows the RS274/NGC G-Code standard.
A typical piece of G-Code as sent to the eCNC fw machine might look like this:
G17 G20 G90 G94 G54 G0 Z0.25 X-0.5 Y0. Z0.1 G01 Z0. F5. G02 X0. Y0.5 I0.5 J0. F2.5 X0.5 Y0. I0. J-0.5 X0. Y-0.5 I-0.5 J0. X-0.5 Y0. I0. J0.5 G01 Z0.1 F5. G00 X0. Y0. Z0.25`
A permissible line of input G-Code consists of the following, in order, with the
restriction that there is a maximum (currently 256) to the number of characters allowed on a line.
Any input not explicitly allowed is illegal and will cause the Interpreter to signal an error.
Spaces and tabs are allowed anywhere on a line of code and do not change the meaning of the
line, except inside comments. A field can be interpreted as a command, parameter, or for any other special purpose. It consists of one letter directly followed by a number. The letter gives information about the meaning of the field (see the list below in this section). Numbers can be integers (128) or fractional numbers (12.42), depending on context. In this description, the numbers in the fields are represented by nnn as a placeholder.
Letter | Meaning |
---|---|
Gnnn | Standard G-Code commands |
Mnnn | Proprietary G-Code commands, they can change from a machine to another depending on the controll software used |
Tnnn | Select tool nnn |
Snnn | Command parameter, such as time in seconds |
Pnnn | Command parameter |
Xnnn | X coordinate, usually to move to. This can be an Integer or Fractional number. |
Ynnn | Y coordinate, usually to move to. This can be an Integer or Fractional number. |
Znnn | Z coordinate, usually to move to. This can be an Integer or Fractional number. |
Innn | Parameter - X-offset in arc move |
Jnnn | Parameter - Y-offset in arc move |
Rnnn | Parameter - radius of an arc move |
Lnnn | Parameter - Fixed cycle loop count |
Fnnn | Feedrate in mm per minute. (Speed of print head movement) |
Nnnn | Line number. |
Gcode comments begin at a semicolon, and end at the end of the line:
N3 T0*57 ; This is a comment N4 G92 E0*67 ; So is this N5 G28*22
Usage
G0 Xnnn Ynnn Znnn
G1 Xnnn Ynnn Znnn Fnnn
Parameters:
Not all parameters need to be used, but at least one has to be used.
Xnnn The position to move to on the X axis
Ynnn The position to move to on the Y axis
Znnn The position to move to on the Z axis
Fnnn The feedrate per minute of the move between the starting point and ending point (if supplied)
Example
1. G0 X12 2. G1 X10 Y5.1 F150 3. G1 X5 Y3.45
First line moves the tool in the position X 12 (the system keeps the Y and Z current values) at the max motion speed of the machine. Second line moves the tool in the position X:10 Y:5.1 with a feedrate of 150 mm/min. Third line moves the tool in X:5 Y:3.45 with the same feedrate of the previous command.
Usage
G2 Xnnn Ynnn Innn Jnnn Fnnn (Clockwise Arc)
G3 Xnnn Ynnn Innn Jnnn Fnnn (Counter-Clockwise Arc)
Parameters:
Xnnn The position to move to on the X axis
Ynnn The position to move to on the Y axis
Innn The point in X space from the current X position to maintain a constant distance from
Jnnn The point in Y space from the current Y position to maintain a constant distance from
Fnnn The feedrate per minute of the move between the starting point and ending point (if supplied)
Example
1. G2 X90.6 Y13.8 I5 J10 2. G3 X90.6 Y13.8 I5 J10
First line moves in a Clockwise arc from the current point to point (X=90.6,Y=13.8), with a center point at (X=current_X+5, Y=current_Y+10).
Second line moves in a Counter-Clockwise arc from the current point to point (X=90.6,Y=13.8), with a center point at (X=current_X+5, Y=current_Y+10)
Usage
G2 Xnnn Ynnn Rnnn Fnnn (Clockwise Arc)
G3 Xnnn Ynnn Rnnn Fnnn (Counter-Clockwise Arc)
Parameters
Xnnn The position to move to on the X axis
Ynnn The position to move to on the Y axis
Rnnn The radius of the arc.
Fnnn The feedrate per minute of the move between the starting point and ending point (if supplied)
Example
1. G2 X90.6 Y13.8 R5 2. G3 X90.6 Y13.8 R10
First line moves in a Clockwise arc from the current point to point (X=90.6,Y=13.8), with a radius of 5mm
Second line moves in a Counter-Clockwise arc from the current point to point (X=90.6,Y=13.8), with a radius of 10mm
Usage
G4 Pnnn
Parameters
Pnnn Number of milliseconds to be paused
Example
1. G4 P5
First line pauses the machine for five seconds.
G20 sets units in inches from now on.
G21 sets units in millimeters from now on. It is the default setting.
G90 sets absolute coordinates system for the tool positioning.
G91 sets relative coordinates system for the tool positioning.
Usage
G92 Xnnn Ynnn Znnn
Parameters
Xnnn The position of X axis
Ynnn The position of Y axis
Rnnn Z postion of Z axis
Lnnn Times that has to repeat the operation
Example
1. G92 X10 Y10 Z10 2. G92 X10 Y10 3. G92
First line sets the current position to X=10, Y=10 and Z=10.
Second line sets the current position to X=10, Y=10 and Z=0.
Third line sets all axes to X=Y=Z=0
G98 sets the retraction position after a drilling sycle at the Z position specified by R.
G99 sets the retraction position after a drilling sycle at the Z position kept before the cycple beginning. But if the Z position is lower than R, the retraction will be at R.
Usage
G81 Xnnn Ynnn Znnn Rnnn Lnnn
Parameters
Xnnn The position to move to on the X axis
Ynnn The position to move to on the Y axis
Rnnn Z postion after retraction
Lnnn Times that has to repeat the operation
Example
1. G90 G81 G98 X400 Y500 Z150 R280 2. G91 G81 G98 X400 Y500 Z-60 R180 L3
First line stes absolute coodinates, than makes the below operations
1. rapid movement to position (X=400, Y=500)
2. rapid movement to Z position Z=280
3. move down Z to position Z=150 with the current feedrate
4. rapid tool retraction at Z=280.
Second line sets relative coordinate system (G91) and the retraction mode to R (98), let suppose that the current position is (X=100, Y=200, Z=300), so the cycle makes the below operations:
1. rapid movement to the position (X=100, Y=200, Z=300+180)
2. rapid movement to the position (X=100+400, Y=200+500, Z=480)
3. move down up to the position (X=500, Y=700, Z=480-60)
4. rapid tool retraction at the position (X=500, Y=700, Z=480)
5. repeat from point 2 with current position (X=500, Y=700, Z=480), the cycle is repeated for three times.
M0 stops the router and the tool
M3 has different behaviours depending on the tools:
LASER: it turns on the laser,
MILLING MACHINE: it turns on the milling machine and set the CW spindle if it is supported,
* SERVO PLOTTER: it moves down the pen
M4 has different behaviours depending on the tools:
LASER: it turns on the laser,
MILLING MACHINE: it turns on the milling machine and set the CCW spindle if it is supported,
* SERVO PLOTTER: it moves down the pen
M5 has different behaviours depending on the tools:
LASER: it turns off the laser,
MILLING MACHINE: it turns off the milling machine,
* SERVO PLOTTER: it moves up the pen
Easy CNC by Francesco Giurlanda is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Permissions beyond the scope of this license may be available at http://sourceforge.net/projects/easycnc/support?source=navbar.