6.1. G Codes: G12 (X#) (Y#) Z#R#Q#S#SA#AS#RA#H#
6.1. G Codes: G12 (X#) (Y#) Z#R#Q#S#SA#AS#RA#H#
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.
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 Machine
Example
(codes valid from V1.0.6.5) Explanation Format type
G01
Travel in a straight line using the G01 [X#]
programmed feed rate (F). This code [Y#][Z#] G01 X2.5 All
[F#] Y4.1 F200 machines
is used for machining.
G02
XY-machines
Circular/Helical Interpolation
clockwise. It causes a clockwise
circular movement at programmed
feed rate (F). The motion can be 2- G02[X#]
dimensional (flat) or 3-dimensional [Y#][Z#] G02 X10
(helical). The default plane of the [I#][J#] Y10 I10 J0 All
[K#][R#] F200 machines
circular movement is the XY-plane
Lathe (G17) but other planes can be used as [F#]
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#] G03 X10 All
XY-machines motion is going counterclockwise. [Y#][Z#] Y10 I10 J0 machines
[I#][J#] F200
[K#][R#]
[F#]
Lathe
G04
G04 Dwell in milliseconds. This will keep P2000
G04 P# All
the axes unmoving for the period of (Two
machines
time specified by the P number. seconds
delay)
G17
Milling
Selects the XY plane for circular G17 G17 machines
movements (see G02 and G03).
only
Milling
machines
Selects the XZ plane for circular only
G18 G18
movements (see G02 and G03)
G21 All
G21 Enforce use of millimeter units. G21
machines
G40 All
Cancel cutter compensation previously G40 G40 machines
activated by G41 or G42. More info except the
3D Printer
G41 All
Activates left side cutter compensation G41[D#]
G41 machines
(or nose radius compensation in a [P#] More info except the
lathe).
3D Printer
G42
All
Activates right side cutter G42[D#] G42 machines
compensation (or nose radius [P#] More info except the
compensation in a lathe).
3D Printer
Milling
Cancel tool length compensation G49
G49 G49 machines
(activated by G43).
only
G54-G59 Fixture (work) offsets. A typical use of G54 G00 G54 All
these G-codes is to establish a local X0 Y0 Z3 machines
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…
G61 All
G61 Exact stop mode. G61
machines
G64 All
G64 Normal stop mode (cancels G61) G64
machines
G65 P#
Direct call of a macro. P is the macro A... G65
All
G65 number to be called. For more B... P1005
machines
information, see Macro programming. C... A180
etc.
G68
X(center
in X)
Y(center
in Y)
Activates rotation of the coordinate R(angle)
system.
or Milling
G68
Two syntax are allowed. machines
G68
Use G69 to cancel the rotation. A(center
in X)
B(center
in Y)
R(angle)
Cancel the rotation of the coordinate G69 Milling
G69
system. machines
Finishing Cycle.
G73
Peck drilling canned cycle. The cycle
is intended for deep drilling or chip
breaking milling operations. The cycle
retracts the tool to break chips. Code G73 [X#]
letter Q is used for peck size. R is [Y#][Z#] G73 Z-20 Milling
starting plane and Z is total depth. [R#][Q#] R1 Q1 machines
[P#] P100 only
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.
Milling and
Cancels any canned cycle. Please
G80 turning
G80 note that G00 – G03 also cancels G80
machines
canned cycles.
only
G81
Use to reposition the origin point (zero G92[X#] G92 X20 All
G92 [Y#][Z#] Y20 Z10
point). machines
Milling and
G94 Set feed in millimeter or inch per G94 turning
G94
minute. machines
only
Milling and
G95 turning
G95 Set feed per revolution mode. G95
machines
only
G96[S#] Turning
G96 Constant surface speed control. G96 S300
machines
G99
Milling and
R level return at the end of a canned G99 G81 G99 turning
cycle. Z-7 R2 machines
only
6.2. 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
(codes valid from Explanation Format Example Machine type
V1.0.6.5)
Optional stop (pause). Will pause the
M00 execution of the CNC program if the
“Op.Stop” switch on the virtual CNC
Controller is activated. Click start or play to M00 M00 All machines
continue.
M02
Program end. Simulation will stop. M02 M02 All machines
M03
Milling and
Start of spindle clockwise. The rotation M03 M03
turning
speed is controlled by the S code letter. S2500
machines only
M04
Start of spindle counterclockwise. The Milling and
M04 M04
rotation speed is controlled by the S code turning
S2500
letter. machines only
M05
Milling and
Spindle stop. M05 M05 turning
machines only
M06
Execute a tool change. The number of the Milling and
tool has to be preselected with the T code M06 T17 M06 turning
letter. machines only
M08
Milling and
Turn on coolant. M08 M08 turning
machines only
M09
Milling and
Turn off coolant. M09 M09 turning
machines only
M21
M30
Program end. Simulation will stop. M30 M30 All machines
M99
Return from a macro, subroutine or M99
M99 All machines
subprogram. More info
6.3. $-commands and regions
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 $-commands are special simulation commands for controlling the various aspects of the
simulation. They have nothing to do with CNC codes and should not be transferred to a real CNC
controller. $-commands can be put within parenthesis and will still be read by the simulator. Blocks
of $-commands can be hidden from the CNC code by encapsulating them in a region making the
block collapsible.
Do you notice the little - (minus) sign before the region command at the first line? If you click it, the
region will be collapsed hiding the block of $-commands.
A collapsed region will show three dots and a + (plus) sign. If you click the plus sign, the region will
expand.
You can see what a collapsed region hides without expanding it by hover the mouse pointer over it.
When you open a CNC program from the disk, it always loads with its regions collapsed.
In the following table we list and give a brief explanation of all built in $-commands. Please not that
many of them are not for common use but rather made for special use in examples or when
creating portable programs. We have colored the commands you will likely use in red. If you are
not an advanced user that wants to learn all aspect of the CNCSimulator, you can skip over the
commands colored in black. Not even all red command is a must to know. As a minimum, you have
to know the $AddRegPart command as you will need it to place workpieces on the table (or in the
chuck). If you are a 3D Printer only user, you can ignore the $-commands.
Note that these commands works even when they are inside parentheses. It is normally good to
keep them in parentheses to avoid confusion with other software or CNC controllers.
6.4. Other codes
Code Explanation Format Example
Absolute or incremental X axis value used in canned X#
X X2.43
cycles and codes like G00-G03.
Absolute or incremental Y axis value used in canned Y#
Y Y1.16
cycles and codes like G00-G03.
Absolute or incremental Z axis value used in canned Z#
Z Z-3.2
cycles and codes like G00-G03.
Represents the center in X in G02 and G03 circle/ arc I# G02 X34 Z106.867
I
commands. I4.8 K0
Represents the center in Y in G02 and G03 circle/ arc J#
J G02 Y0 J-20
commands.
Represents the center in Z in G02 and G03 circle/ arc K# G02 X34 Z106.867
K
commands. I4.8 K0
Selects a tool from the user defined tool registry in the
T Inventory Browser (F2). M06 is used to execute the actual T# T1 M06
tool change.
Selects a tool from the fixed embedded tool registry. M06 ET#
ET ET9 M06
is used to execute the actual tool change.
Selects a predefined milling tool. The tool must first have
DT been defined using the $DefineMillTool command. M06 is DT# DT3 M06
used to execute the actual tool change.
S Defines spindle rotation in revolutions per minute (RPM). S# S2000
F Defines feed rate in millimeter or inches per minute. F# F240
M98 P1001 L1
Used in M98 to define a sub program number. Also used P#
P G73 Z-20 R2 Q5
as dwell time in canned cycles.
P100 F350
L Used in M98 to define the number of repetitions. L# M98 P1001 L1
(Drilling sub
Sub program number. Should be the first line of every sub O#
O program 1)
program.
O1000
Reference or starting plane in canned cycles. R is also
R used in G02/G03 to give the radius when I/J/K are not R# G81 Z-20 R2
used.
Q#G73 Z-20 R2 Q5 P0
Q Peck size in canned cycles.
F350
G12 X0 Y0 Z-20 R2
SA,AS, Start Angle, Angle Step and Radius used in G12 Circular SA# AS#
RA# Q5 SA0 AS36 RA30
RA drilling cycle.
H10
G12 X0 Y0 Z-20 R2
Used for number of holes in the G12 Circular drilling
H Q5 SA0 AS36 RA30
cycle.
H10
Used for comments. G and M codes inside parenthesis
(Drilling sub
( and ) will not be executed. $-commands will be executed even (text)
program 1)
when inside the parenthesis.
G01 Z-20 F440
Used for comment out one or several lines. G, M and $- /G03 I23.2 J0
/
commands will not be executed. /G03 X15 I19
G00 Z7
N Block number. N# N500