Anda di halaman 1dari 17

G codes

These are the default standard codes that are used in our normal virtual machines. Please note that customized machines may have other codes and formats.

The following tables will give a brief explanation to the various G, M and other codes recognized by the CNCSimulator interpreter. In the Format column, you will
see the format expected by the program. If a code is written within brackets like this [X#] it means that the code is non obligatory and can be omitted if not needed.
The # sign means that the CNCSimulator expects a number and the $ sign means that it is expecting a text string within quotation marks.

Let's show an example:


G12[X#][Y#]Z#R#Q#S#SA#AS#RA#H#

This means that the code G12 accepts X and Y coordinates but they are not obligatory and can be omitted. On the other hand, you must specify the
Z,R,Q,S,SA,AS,RA and H codes to avoid an alarm at runtime.

G-code Explanation Format Example Machine type


(codes valid from V1.0.6.5)

G00 Go rapidly (with maximum traverse G00 [X#][Y#][Z#] G00 Z100 All machines
rate) to the X/Y/Z position. This code
is used for position and not for actual
machining.

G01 Travel in a straight line using the G01 [X#][Y#][Z#][F#] G01 X2.5 Y4.1 All machines
programmed feed rate (F). This code is F200
used for machining.
G02 Circular/Helical Interpolation G02[X#][Y#][Z#] G02 X10 Y10 I10 All machines
XY-machines clockwise. It causes a clockwise [I#][J#][K#][R#][F#] J0 F200
circular movement at programmed feed
rate (F). The motion can be 2-
dimensional (flat) or 3-dimensional
(helical). The default plane of the
circular movement is the XY-plane
(G17) but other planes can be used as
Lathe well (see G17-G19). The center of the
arc or circle is programmed using the I,
J and K letters (R can also be used).

G03 Exactly like G02 but the circular G03[X#][Y#][Z#] G03 X10 Y10 I10 All machines
XY-machines motion is going counterclockwise. [I#][J#][K#][R#][F#] J0 F200

Lathe

G04 Dwell in milliseconds. This will keep G04 P# G04 P2000 (Two All machines
the axes unmoving for the period of seconds delay)
time specified by the P number.
G09 Will force the machine to do a full stop G09 All machines
before continuing with the next move.
This is a non-modal variant of G61 and
hence does not have to be cancelled.

G12 Circular drilling canned cycle. Use to G12[X#][Y#]Z# G12 X0 Y0 Z-20 Milling machines only
drill holes around the contour of a R#Q#S#SA# R2 Q5 SA0 AS36
circle. R is starting plane and Z is total AS#RA#H# RA30 H10
drill depth for each hole. Q is
incremental depth (peck). SA is circle
start angle (angle of first hole too) and
AS is angle between holes. RA is circle
radius and H specifies the number of
holes to drill.

G17 Selects the XY plane for circular G17 G17 Milling machines only
movements (see G02 and G03).

Selects the XZ plane for circular G18 G18 Milling machines only
movements (see G02 and G03)
Selects the YZ plane for circular G19 G19 Milling machines only
movements (see G02 and G03).

G20 Enforce use of inches units. G20 G20 All machines

G21 Enforce use of millimeter units. G21 G21 All machines

G28 Return home command. This G28[X#][Y#][Z#] G28 Z10 Milling and turning
command will first go to the machines only
programmed position X/Y/Z and then
to the Xmin Ymax Zmax of the
machine axes. It can be a convenient
way to end a program putting the
machine table in a position to change
workpiece.

G40 Cancel cutter compensation previously G40 G40 All machines except the 3D
activated by G41 or G42. More info Printer
G41 Activates left side cutter compensation G41[D#][P#] G41 All machines except the 3D
(or nose radius compensation in a More info Printer
lathe).

G42 Activates right side cutter G42[D#][P#] G42 All machines except the 3D
compensation (or nose radius More info Printer
compensation in a lathe).

G43 Activates tool length compensation. G43[H#][P#][Z#] G43 H2 Z2 Milling machines only
(Optional, if not used, automatic tool More info
length compensation will be used).

G49 Cancel tool length compensation G49 G49 Milling machines only
(activated by G43).

G53 Move in absolute non-compensated G53 [X#][Y#][Z#] G53 X0 Y0 Z100 All machines
coordinates.
G54-G59 Fixture (work) offsets. A typical use of G54 G00 G54 X0 Y0 All machines
these G-codes is to establish a local Z3
coordinate system for each workpiece
when using multiple ones. You need to
setup the offsets in the Zero Points
Data table in the Inventory Browser
(F2).
G54 corresponds to offset registry
index 0, G55 to index number 1 etc…

G54.1 Fixture (work) offsets. A typical use of G54.1 P# (0-99) G54.1 P10 (Use All machines
these G-codes is to establish a local work offset 10)
coordinate system for each workpiece
when using multiple ones. You need to
setup the offsets in the Zero Points
Data table in the Inventory Browser
(F2).
G54.1 uses letter P to specify the offset
registry index.
G61 Exact stop mode. G61 G61 All machines

G64 Normal stop mode (cancels G61) G64 G64 All machines

G65 Direct call of a macro. P is the macro G65 P# A... B... C... etc. G65 P1005 A180 All machines
number to be called. For
more information, see Macro
programming.
G66 Initiates modal calling of macro G66 P# A... B... C... etc. G66 P7000 All machines
defined by P. The macro will not be
called in the G66 block but rather after
each tool move following the block.
Cancel with G67. For more
information, see Macro programming.

G67 Cancels any model macro call initiated G67 All machines
by G66. For more information, see
Macro programming.

G68 Activates rotation of the coordinate G68 X(center in X) Y(center in Milling machines
system. Y) R(angle)

Two syntax are allowed. or

Use G69 to cancel the rotation. G68 A(center in X) B(center in


Y) R(angle)

G69 Cancel the rotation of the coordinate G69 Milling machines


system.
G70 Finishing Cycle. G70 [P#][Q#] G70 P100 Q250 Turning machines only

After roughing, finishing can be


performed with this cycle. P is first
block of finishing contour and Q is the
last block.

For more information see: G71 Rough


Turning Cycle and G70 Finishing
Cycle.

G71 Rough Turning Cycle G71 G71 Turning machines only

Two block format Roughing cycle.

For more information see: G71 Rough


Turning Cycle and G70 Finishing
Cycle.

G73 Peck drilling canned cycle. The cycle G73 [X#][Y#][Z#] G73 Z-20 R1 Q1 Milling machines only
is intended for deep drilling or chip [R#][Q#][P#] P100
breaking milling operations. The cycle
retracts the tool to break chips. Code
letter Q is used for peck size. R is
starting plane and Z is total depth.
Parameter P is used for dwell at each
peck. Please note that at the end of the
cycle, the return position in Z is
controlled by G98 and G99.
G74-G75 Generic drilling/boring/tapping canned G74 [X#][Y#][Z#][R#] G74 Z-20 R1 Milling and turning
cycle. These are used in a generic way machines only
to create compatibility with many
common CNC controllers on the
market. They will bring the tool to the
programmed Z depth. If R is
programmed it will be used as the start
plane, if not the current Z position will
be used as the start plane. All other
parameters will be ignored.

G76 Generic drilling/boring/tapping canned G76 [X#][Y#][Z#][R#] Milling machines only


cycle. See G74-G75 above.

G76 Threading Cycle G76 G76 Turning machines only

For more information see: G76 Lathe


Threading Cycle

G80 Cancels any canned cycle. Please note G80 G80 Milling and turning
that G00 – G03 also cancels canned machines only
cycles.

G81 Basic drilling canned cycle. R is G81 [X#][Y#][Z#][R#] G81 Z-6 R2 Milling and turning
starting plane and Z is total depth. machines only
Please note that at the end of the cycle,
the return position in Z is controlled by
G98 and G99.
G82-G89 Generic drilling/boring/tapping canned G82 [X#][Y#][Z#][R#] G82 Z-20 R1 Milling and turning
cycle. Same as G74-G76 above. machines only

G90 Absolute programming mode. G90 G90 G00 X10 Y10 All machines
Distances given will move the tool
relative to an absolute zero.

G91 Incremental programming mode. G91 G91 G00 Z5 All machines


Distances given will move the tool
relative to the current position of the
tool.

G92 Use to reposition the origin point (zero G92[X#][Y#][Z#] G92 X20 Y20 Z10 All machines
point).

G94 Set feed in millimeter or inch per G94 G94 Milling and turning
minute. machines only
G95 Set feed per revolution mode. G95 G95 Milling and turning
machines only

G96 Constant surface speed control. G96[S#] G96 S300 Turning machines

G97 Cancel constant surface speed control. G97 G97 Turning machines

G98 Initial level return at the end of a G98 G81 G98 Z-7 R2 Milling and turning
canned cycle. machines only

G99 R level return at the end of a canned G99 G81 G99 Z-7 R2 Milling and turning
cycle. machines only
M codes
These are the default standard codes that are used in our normal virtual machines. Please note that customized machines may have other codes and formats.

M-code Explanation Format Example Machine type


(codes valid from V1.0.6.5)

M00 Optional stop (pause). Will pause the M00 M00 All machines
execution of the CNC program if the
“Op.Stop” switch on the virtual CNC
Controller is activated. Click start or play
to continue.

M01 Unconditional stop (pause). The execution M01 M01 All machines
of the CNC program will pause. Click start
or play to continue.
M02 Program end. Simulation will stop. M02 M02 All machines

M03 Start of spindle clockwise. The rotation M03 M03 S2500 Milling and turning machines
speed is controlled by the S code letter. only

M04 Start of spindle counterclockwise. The M04 M04 S2500 Milling and turning machines
rotation speed is controlled by the S code only
letter.

M05 Spindle stop. M05 M05 Milling and turning machines


only

M06 Execute a tool change. The number of the M06 T17 M06 Milling and turning machines
tool has to be preselected with the T code only
letter.

M08 Turn on coolant. M08 M08 Milling and turning machines


only
M09 Turn off coolant. M09 M09 Milling and turning machines
only

M17 Return from subroutine or subprogram. M17 M17 All machines


More info

M20 Open machine doors. M20 M20 All machines with doors

M21 Close machine doors. M21 M21 All machines with doors

M30 Program end. Simulation will stop. M30 M30 All machines

M97 and M98 Call sub program. Use P for sub program M98 P# L# M98 P1000 L1 All machines
number and L for the number of More info
repetitions.
M99 Return from a macro, subroutine or M99 M99 All machines
subprogram. More info

Copyright © 2018 by CNCSimulator.com. All Rights Reserved.

Other codes
Other codes interpreted by the simulator.

Code Explanation Format Example


X Absolute or incremental X axis value used in X# X2.43
canned cycles and codes like G00-G03.

Y Absolute or incremental Y axis value used in Y# Y1.16


canned cycles and codes like G00-G03.
Z Absolute or incremental Z axis value used in Z# Z-3.2
canned cycles and codes like G00-G03.
I Represents the center in X in G02 and G03 I# G02 X34 Z106.867 I4.8 K0
circle/ arc commands.
J Represents the center in Y in G02 and G03 J# G02 Y0 J-20
circle/ arc commands.
K Represents the center in Z in G02 and G03 K# G02 X34 Z106.867 I4.8 K0
circle/ arc commands.
T Selects a tool from the user defined tool registry T# T1 M06
in the Inventory Browser (F2). M06 is used to
execute the actual tool change.
ET Selects a tool from the fixed embedded tool ET# ET9 M06
registry. M06 is used to execute the actual tool
change.

DT Selects a predefined milling tool. The tool must DT# DT3 M06
first have been defined using the
$DefineMillTool command. M06 is used to
execute the actual tool change.
S Defines spindle rotation in revolutions per S# S2000
minute (RPM).
F Defines feed rate in millimeter or inches per F# F240
minute.

P Used in M98 to define a sub program number. P# M98 P1001 L1


Also used as dwell time in canned cycles.
G73 Z-20 R2 Q5 P100 F350
L Used in M98 to define the number of repetitions. L# M98 P1001 L1
O Sub program number. Should be the first line of O# (Drilling sub program 1)
every sub program. O1000

R Reference or starting plane in canned cycles. R is R# G81 Z-20 R2


also used in G02/G03 to give the radius when
I/J/K are not used.
Q Peck size in canned cycles. Q# G73 Z-20 R2 Q5 P0 F350
SA, AS, RA Start Angle, Angle Step and Radius used in G12 SA# AS# RA# G12 X0 Y0 Z-20 R2 Q5 SA0 AS36
Circular drilling cycle. RA30 H10
H Used for number of holes in the G12 Circular G12 X0 Y0 Z-20 R2 Q5 SA0 AS36
drilling cycle. RA30 H10

( and ) Used for comments. G and M codes inside (text) (Drilling sub program 1)
parenthesis will not be executed. $-commands
will be executed even when inside the
parenthesis.
/ Used for comment out one or several lines. G, M G01 Z-20 F440
and $-commands will not be executed. /G03 I23.2 J0
/G03 X15 I19
G00 Z7
N Block number. N# N500

Copyright © 2018 by CNCSimulator.com. All Rights Reserved.