Vous êtes sur la page 1sur 18

6.1.

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 Machine
Example
(codes valid from V1.0.6.5) Explanation Format type

G00 Go rapidly (with maximum traverse


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

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)

Will force the machine to do a full stop


before continuing with the next move.
G09 All
G09 This is a non-modal variant of G61
machines
and hence does not have to be
cancelled.

Circular drilling canned cycle. Use to


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

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)

Selects the YZ plane for circular G19 G19 Milling


movements (see G02 and G03). machines
only
G20 All
G20 G20
Enforce use of inches units. machines

G21 All
G21 Enforce use of millimeter units. G21
machines

Return home command. This


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

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

Activates tool length compensation. G43[H#] G43 H2 Z2 Milling


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

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

Move in absolute non-compensated G53 [X#] G53 X0 Y0 All


G53 [Y#][Z#] Z100
coordinates. machines

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…

Fixture (work) offsets. A typical use of


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

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.

Initiates modal calling of macro


G66 P#
defined by P. The macro will not be
A...
called in the G66 block but rather after G66 All
G66 B...
each tool move following the block. P7000 machines
C...
Cancel with G67. For more
etc.
information, see Macro programming.

Cancels any model macro call initiated


All
G67 by G66. For more information, G67
machines
see Macro programming.

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.

After roughing, finishing can be


performed with this cycle. P is first
block of finishing contour and Q is the G70 [P#] G70 P100 Turning
G70 last block. [Q#] machines
Q250
only
For more information see: G71 Rough
Turning Cycle and G70 Finishing
Cycle.

Rough Turning Cycle

Two block format Roughing cycle. Turning


G71
G71 G71 machines
For more information see: G71 Rough only
Turning Cycle and G70 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.

Generic drilling/boring/tapping canned


cycle. These are used in a generic
way to create compatibility with many
common CNC controllers on the G74 [X#] Milling and
market. They will bring the tool to the [Y#][Z#] G74 Z-20 turning
G74-G75
programmed Z depth. If R is [R#] R1 machines
programmed it will be used as the start only
plane, if not the current Z position will
be used as the start plane. All other
parameters will be ignored.

G76 [X#] Milling


Generic drilling/boring/tapping canned [Y#][Z#]
G76 machines
cycle. See G74-G75 above. [R#] only

G76 Threading Cycle G76 G76 Turning


machines
For more information see: G76 Lathe only
Threading Cycle

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

G81

Basic drilling canned cycle. R is


Milling and
starting plane and Z is total depth. G81 [X#]
Please note that at the end of the [Y#][Z#] G81 Z-6 turning
[R#] R2 machines
cycle, the return position in Z is
only
controlled by G98 and G99.

G82 [X#] Milling and


Generic drilling/boring/tapping canned [Y#][Z#] G82 Z-20 turning
G82-G89
cycle. Same as G74-G76 above. [R#] R1 machines
only

Absolute programming mode.


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

Incremental programming mode.


Distances given will move the tool G91 G91 G00 All
G91
relative to the current position of the Z5 machines
tool.

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

G97 Cancel constant surface speed G97 G97 Turning


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

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.

M01 Unconditional stop (pause). The execution


of the CNC program will pause. Click start
or play to continue. M01 M01 All machines

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

M17 Return from subroutine or subprogram. M17 M17 All machines


More info
M20

M20 All machines


Open machine doors. M20
with doors

M21

M21 All machines


Close machine doors. M21
with doors

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

M97 and M98


M98
Call sub program. Use P for sub program M98 P#
P1000 L1 All machines
number and L for the number of repetitions. L#
More info

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.

$-command Explanation Format


(codes valid from V1.0.6.5)

Puts a workpiece from the


user defined workpiece
registry in the Inventory
Browser (F2) on the machine
table (or in the chuck). The
first number is the registry
$AddRegPart index for the workpiece you $AddRegPart # [#][#][#]
want to place. The three
following numbers are the X,Y
and Z coordinate for where
you want to place the
workpiece. If omitted, it will be
placed at the machine zero.
Puts a workpiece from the
fixed embedded workpiece $AddEmbeddedRegPart # [#][#]
$AddEmbeddedRegPart registry on the table. See [#]
$AddRegPart above for
further explanation.
Put a predefined workpiece
$AddDefinedPart on the table. Use $AddDefinedPart # [#][#][#]
$AddDefinedPart to define
workpieces in the program.
Will block on-screen spindle
rotation. This can be useful in
$BlockSpindleRot the unlimited lathe if visual
rotation of the workpiece is
not desired.
$Inches Enforce the use of Inch units.
(To set millimeters or inches $Inches
units, open the program
settings dialog).
$Millimeters Enforce the use of Millimeter
units. (To set millimeters or $Millimeters
inches units, open the
program settings dialog).
SetView is a special
command to set the 3D-view
during simulation. It should
not be programmed manually
as it contains too many
parameters but rather be $SetView
$SetView created using the menu ################
action Tools – Insert
Command - $SetView.

$Message Displays a message on the $Message $#


3D view during simulation.
First parameter is a text string
of the message to display.
Next parameter is the number
of seconds to show the
message.
Set the solid workpiece
cutting values at run-time in
$Cutting percent. Parameters are $Cutting #####
FromLeft, FromRight,
FromFront, FromBack and
FromTop.
Set workpiece cutting.
To show the whole part, left
should be 0 and Right should
$Cutting be 100.<BR />
The last parameter is 0 to
show the workpiece closed
and 1 to show the
inside.<BR />
$Pause Will pause the simulation for a $Pause #
given number of milliseconds.
Starts the internal stop watch
to measure the time for an
$StartStopWatch operation. Please note that $StartStopWatch
the time measured is
simulation time and not
machining time.
$ShowStopWatch
Stops the internal stop watch
and shows the time that has
elapsed since the $ShowStopWatch
$StartStopWatch command
was executed.

Enforces the use of a lathe


machine. You will see an
$Lathe alarm if you run a program $Lathe
with this command on a non-
lathe machine.
Enforces the use of a milling
machine. You will see an
$Mill alarm if you run a program $Mill
with this command on a non-
milling machine.
This command is used to
directly setup and use a
milling tool without using the
user or embedded registries.
$SetupTool Parameters are: TipAngle, $SetupTool ######
ShaftDiameter, ShaftLength,
ToolDiameter, ToolLength and
ToolTipType (0=Flat, 1=Ball,
2=Pointed)
This special command is
used to override the
resolution setting for the solid
buffer. The value given is the
number of 3D pixels (voxels)
per millimeter. A value of 1 will
make each 3D pixel 1 cubic
millimeter big. A value of 10
will make each 3D pixel 0.1
$OverrideBufferQualitySetting mm3 big. A value of 1 will
create ugly results but will run $OverrideBufferQualitySetting
fast. On the other hand, a #
value of 10 will create high
resolution workpieces but will
run slow. We do not
recommend using values
higher than 10 as you could
easily run out of memory due
to huge material buffer
allocation. Important: this
command must
come before the
$AddRegPart command.
This command is used to
directly setup and use a
milling workpiece without
using the user or embedded
$AddMillPart registries. Parameters are: $AddMillPart #############
SizeX, SizeY, SizeZ, Xpos,
Ypos, Zpos, PartColR,
PartColG, PartColB, TopColR,
TopColG, TopColB,
MaterialStyle
Define a lathe workpiece that
can be fetched by using the
command $AddDefinedPart.
$DefineLatheWorkpiece Parameters are $DefineLatheWorkpiece [$]####
NameAndMaterial, Index,
Length, Diameter, Inner
diameter.
Define a mill workpiece that
can be fetched by using the
$DefineMillWorkpiece command $AddDefinedPart. $DefineMillWorkpiece [$]####
Parameters are:
NameAndMaterial, Index,
SizeX, SizeY, SizeZ
Defines a material to be used
by defined workpieces.
$DefineMaterial Parameters are MatrlName, $DefineMaterial [$]########
Index, PartColR, PartColG,
PartColG, TopColR, TopColG,
TopColB, MaterialStype
$DefineMillTool Defines a milling tool that can $DefineMillTool [$]#######
be fetched by the DT code
letters. Parameters are:
ToolName, Index, TipAngle,
ShaftDiam, ShaftLength,
ToolDiam, ToolLength,
ToolTipType (0=Flat, 1=Ball,
2=Pointed)

Turn on or off the display of


$Toolpaths the tool paths during $Toolpaths #
simulation. (1=on, 0=off).

$SetCuttingWidth Used in cutting machines to $SetCuttingWidth


define the cutting width.
Tells the simulator to override
the material for the workpiece
and use the specified one
$UseMaterial instead. The material must $UseMaterial
exist in the materials registry
in the Inventory Browser (F2)
to avoid an alarm.
Tells the simulator to override
the material for the workpiece
and use the specified
$UseEmbeddedMaterial embedded one instead. The $UseEmbeddedMaterial
material must exist in the
embedded materials registry
to avoid an alarm.
$InvertLathePart

Flips the lathe workpiece in


the chuck to continue $InvertLathePart
machining the other side of it.

Circle and arc centers are


normally entered as
$AbsoluteCenters incremental values. This $AbsoluteCenters
command tells the simulator
to expect absolute circle and
arc center values.

$SetG28pos Set custom position for G28. $SetG28pos{#}{#}{#}

$SetToolChangePos Set custom tool change $SetToolChangePos{#}{#}{#}


position.

$DefineDoffsetDiameter Define a D offset in-program. $DefineDoffsetDiameter{#}{#}

$ReadTasDefinedTool When your program has $ReadTasDefinedTool


defined tools (for example in
programs created by
SimCam), you call these tools
with "DT". Using this
command you can skip the D
and only use T followed by
the tool index number. For
example "T25". The simulator
will treat all T values as
defined tools.
This command rotates the
$RotateWorkpiece workpiece around its Z axis. $RotateWorkpiece

This command sets the


surface color. Any new
surface that gets exposed by
a milling operation will have
this color. The command
expects three parameters:
Amount of Red, amount of
$Color Green and amount of Blue. $Color R G B
Values are giving in the range
0 to 255 where 255 is the
brightest. $Color 0 0 0 will
make the surface black and
$Color 255 255 255 will make
it white. For mixing of other
colors, Google "RGB Color
Picker".
Is used to define temporary
zero points.
Example: $DefineZeropoint
"N:Name" 0 100 100 20
This will define zero point
index 0 to X100 Y100 and
Z20. Index 0 = G54, 1 = G55 $DefineZeropoint[$][#][#][#]
$DefineZeropoint etc. [#]
Index 0 can also be called
with G54.1 P0. After this
command has been used,
all G54-G59 and G54.1 calls
will refer to the defined zero
point and not to the
ones in the zero point registry.
Special command to set titles
of tutorials. You can read
$TutorialLine more about these $TutorialLine[$]
here Creating customized
tutorials in CNCSimulator Pro.
Special command to set titles
of tutorials. You can read
more about these
$Title here Creating customized $Title
tutorials in CNCSimulator Pro.

$PreventEraseOnCutOff By default, the simulator will $PreventEraseOnCutOff


erase everything to the right
when the material has been
cut through to simulate the
part falling down. This
command prevents that from
happening.
When your program wants to
use the simulator embedded
tools, you call these tools with
"ET". Using this command
$ReadTasEmbeddedTool you can skip the E and only $ReadTasEmbeddedTool
use T followed by the tool
index number. For example
"T25". The simulator will treat
all T values as embedded
tools.
This activates an alternative
$UseAltG92method G92 mode so that it makes $UseAltG92method
the current tool position have
the coordinates you specify.
Used by SimCam and by
$DefineLatheTool "Make program portable" to
create in-program lathe tools.

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

Vous aimerez peut-être aussi