Simulator Tutorials
Simulator Tutorials
Simulator tutorials are built in tutorials that you can run directly in the simulator 3D window. You find them under the
help menu item Run Tutorial.
When you start a simulator tutorial you will see messages and questions at the bottom of the 3D view. You will also see
contour lines, arrows and a grid coordinate system. Be careful to read the instructions for each tutorial so you
understand what to enter.
This tutorial is made in millimeters, so the first thing we have to do is to ensure we have millimeters set as units in the
program settings. Click Settings Settings from the main menu.
While we are at it, set all other settings like in the picture above. Click OK.
Now what we have to do is to load a machine for the project. Click on the Open Machine button
Machine dialog. You can also click File Load Machine from the main menu.
Uncheck the Open demo checkbox and click on the Turning Center machine button.
This is how your CNCSimulator Pro window should look like now.
OK, now we need to create a workpiece for your project. Press F2 to open the Inventory Browser where we keep all our
tools, workpieces, materials and offsets.
Click the Lathe Workpieces tab.
If you have not previously created any workpieces, this is what you will see.
As you can see on the blue bar below the workpiece picture, our index for this workpiece is one. Yours might be another
index if you already had workpieces stored.
OK great, now let's start writing the CNC program!
We start with a special CNCSimulator Pro command to put the workpiece we just created in the chuck. It is called
$AddRegPart. You can either type in the command by hand followed by the index number for the workpiece or take a
shortcut by clicking the Insert at cursor button. This button will automatically put the command in the editor.
Put the cursor at the end of the first line and press enter. This is to ensure that the next command we insert will end up
on a new line.
Next step is to select a tool to use for our rough cuts.
Press F2 again to open the Inventory Browser. This time we are going to stay on the first page (Tools) and click on the
Embedded lathe tools option.
We are going to use one of the fixed embedded tools that come with the CNCSimulator Pro. Actually, we are going to
use the first one so you could just go ahead and click the Insert at cursor button again.
Either type 6 or select M06 from the list by using the mouse or the arrow keys on the keyboard.
OK, by now we are all set to start cutting the workpiece.
Click the Reset View button to zoom in on the workpiece.
Zoom in a bit further by clicking in the 3D view and rolling the mouse wheel away from you.
Click the Start Simulation button to execute the commands we have entered so far.
As you can see, the workpiece that we made and the tool we selected are in place.
Let's move the tool in position for the first rough cut by using the G00 code.
Important! The CNCSimulator Pro does automatically put the zero point at the right plane of the jaws. The distance from
the plane to the spindle is 23 millimeter. That means that the right end of our 100 mm long workpiece is at (100-23) 77
in the Z axis. This rule goes for all lathes in the CNCSimulator Pro. Always take the 23 millimeters into account!
We want to take away 10 millimeter from the diameter per cut (5 mm material) so we should put the tool on 40 as our
initial diameter is 50. Let us also put the tool on Z 80 so we have some space (3 mm) between the tool and the
workpiece end plane.
Type G00 X40 Z80 and press Enter.
Fine, now let's take the first actual cut.
Type G01 Z50 F250 S1000 M04 M08 and press Enter.
If you move the mouse over the codes in the block above, you will see tooltip windows explaining what they do.
OK, now we back out the tool a bit before going with fast traverse back to Z80.
Type X44 Z52 and press Enter.
Note that we did not have to write G01 again as it is already activated. The code is modal.
To help us see clearly the tool moves we do, we can turn on the toolpath display. Click on the glasses button and check
the Feeds and Fast Traverses checkboxes.
Now, if you simulate you will see feed movements (G01-G03) in green and fast traverses (G00) in red.
Without pressing Enter, write M06 to execute the tool change, then press Enter.
After a tool change, the tool is at the tool change position of the machine and we need to go back to the workpiece.
We will now take the tool back from the tool change position and place it in the center of the workpiece.
Type G00 X0 Z80 and press Enter.
We are going to use a canned drilling cycle to make the hole.
Type G81 Z60 R78 and press Enter.
Type G00 X100 Z200 and press Enter.
Type M30 to end the program and press Enter.
Excellent! We are done. Simulate the program and then click the cutting (knife) button.
M30
First of all, we need to set millimeters as units and load an appropriate machine for our project.
In the dialog that shows, please deselect Open demo. Then click on the Milling Center button.
Fine, now let's get started by defining our workpiece. Press F2 on the keyboard to open the Inventory Browser.
Click on the Mill Workpieces tab at the top of the dialog.
Click on the green plus button to add a new workpiece.
In the Workpiece Name field, enter a name for your new workpiece, let's call it Tutorial1.
Ignore the rest of the settings and click OK to close the Inventory Browser.
Now we need to call up our new workpiece from the program. We do that by using the command $AddRegPart followed
by the workpiece index number (we use 1) and the table displacement values.
We are going to put our new workpiece 30 millimeter from the machine zero in both X and Y. The machine zero is placed
near the lower left corner of the machine table and it is marked by a cross symbol (could be somewhat hard to spot).
To call up our workpiece number one (or your index number if different) on X30 Y30 from the machine zero, we write
($AddRegPart 1, 30, 30)
Now you can go ahead and click on the Play button
table.
In the lower toolbar, click this button
At this moment, please note that you can click in the simulation window with the left mouse button and drag the mouse
around to rotate the view. If you click with the right mouse button and drag you will pan the view. Also please note that
you can roll the mouse wheel to zoom in and out.
OK, let's get started with the actual CNC program!
As we moved the workpiece in on the machine table and away from the machine zero our lower left corner on the
workpiece now is at X30 Y30. That is not very practical so let's move the programming zero point to X30 Y30 Z20. This
will result in a zero point in the upper (Z) lower left corner (XY) of the workpiece.
We move the programming zero point by using the G-code G92. (This can also be done from a zero point registry using
G54 to G59 but that is out of scope of this tutorial).
Type G92 X30 Y30 Z20 in the editor.
Click on the Play button again and note how the zero point moves to the corner of your workpiece.
Now, we need tools to mill the 10 mm wide slot and drill the diameter 10 mm holes.
Again, press F2 on the keyboard to open the Inventory Browser (or select Settings Inventory Browser from the main
menu).
In this tutorial, we assume you have no previous custom made tools, if you do, please add these two new tools at the
end of your list and use the tool index you get.
Select My milling tools and click on the button with the green plus icon, the Add button.
First we will add the tool to mill the slot. Select a flat tool tip, enter 10 as diameter and 50 as length. Enter the name of
the tool Tutorial1 flat mill. Ignore all other settings and click OK.
In our case, this new tool will get tool index number 1 (take a note of yours).
Now, we repeat the procedure adding the drilling tool. Click the Add button again.
This time, select a pointed tool tip and enter diameter 10, length 50 and tip angle 80 degrees. Name it Tutorial1 drill.
Click OK.
Click on the X in the upper right corner of the Tool Browser to close it.
Congratulations! Now we have a workpiece and tools and can start programming the rest of our part.
To call up our new milling tool we use T1 (or your tool index number) followed by M06 to tell the virtual machine to go
to its tool change position and execute the tool change.
T1 M06
Next, let us move the tool to the start position. We have decided to use the lower left corner of the slot as the start
where we will drill down into the material.
We use G-code G00 to move with rapid speed to the position stopping 2 mm over the workpiece.
G00 X15 Y15 Z2
Now, press Play to see that the positioning works.
We now enter the G-code G01 for feed movement down to working depth. We also need to start the spindle (M03) and
set the Feed rate (F) and spindle RPM (S).
G01 Z-5 F250 S2000 M03
Now we will move the mill to the start point of the arc, there is no need to type G01 in this block as the code is modal
meaning it will remember the G01 code from the previous block (block = line).
Y70
From now on, feel free to click the Play button at any time to check the simulation.
Now, let's program the clockwise arc movement. To do so, we use the G02 code followed by the X/Y coordinates of the
endpoint and the I/J coordinates of the relative center point (I stands for incremental distance from starting point to
center in X and J is the same in Y).
Great! Let's enter the rest of the blocks to finish the slot.
G01 X85
Y15
X15
How about that? We are back to where we started. Let's go up in Z to a safe position and then change tool for the
drilling.
G00 Z2
T2 M06
Make sure you use your tool index after T for the drilling tool we created.
Now we can come back from the tool change position and put the drill over the first hole.
G00 X30 Y30 Z2
Next, we will start a drill cycle. We only need to start it and then it will drill on each position we program until we tell it
to stop. For this we use a common drill G-code called G81. We tell the cycle to drill to a total depth of 15 mm and a start
depth of 1 mm above the workpiece. As we have changed tool, we need to start the spindle again (M03). This time, let
us also use coolant water (M08) to not overheat the tool.
G81 Z-15 R1 M03 M08
Now we can just position over each hole center and the drilling will start automatically.
Y70
X70
Y30
Now we need to end the drilling cycle using the G80 code.
G80
Finally we go up in Z and the write M30 to end the program.
Z50
M30
Congratulations! You have done your first CNC program in the famous CNCSimulator!
The complete program:
$AddRegPart 1, 30, 30
G92 X30 Y30 Z20
T1 M06
G00 X15 Y15 Z2
G01 Z-5 F250 S2000 M03
Y70
G02 X30 Y85 I15 J0
G01 X85
Y15
X15
G00 Z2
T2 M06
G00 X30 Y30 Z2
G81 Z-15 R1 M03 M08
Y70
X70
Y30
G80
Z50
G codes
Codes and commands
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
G00
Go rapidly (with
G00 [X#][Y#][Z#]
maximum traverse rate)
to the X/Y/Z position.
This code is used for
position and not for
actual machining.
G00 Z100
All
machines
G01
G01 X2.5
Y4.1 F200
All
machines
G02
XY-machines
Circular/Helical
G02[X#][Y#][Z#]
G02 X10
Interpolation clockwise. [I#][J#][K#][R#][F#] Y10 I10 J0
It causes a clockwise
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 well (see G17G19). The center of the
arc or circle is
programmed using the
I, J and K letters (R can
also be used).
All
machines
All
machines
Lathe
G03
XY-machines
G01
[X#][Y#][Z#][F#]
Lathe
G04
Dwell in milliseconds.
G04 P#
This will keep the axes
unmoving for the period
of time specified by the
P number.
G09
G12
G12 X0 Y0 Milling
Z-20 R2 Q5 machines
SA0 AS36
only
RA30 H10
G17
G17
Milling
machines
only
G18
G18
Milling
machines
only
All
machines
G19
G19
Milling
machines
only
G20
Enforce use of
inches units.
G20
G20
All
machines
G21
Enforce use of
millimeter units.
G21
G21
All
machines
G28
G28 Z10
Milling
and
turning
machines
only
G40
Cancel cutter
compensation
previously activated by
G41 or G42.
G40
More info
All
machines
except
the 3D
Printer
G41
G41
More info
All
machines
except
the 3D
Printer
G42
G42
More info
All
machines
except
the 3D
Printer
G43
G43 H2 Z2
More info
Milling
machines
only
G40
G43[H#][P#][Z#]
G49
G49
G49
Milling
machines
only
G53
G53 [X#][Y#][Z#]
G53 X0 Y0
Z100
All
machines
G54-G59
G54.1
G54.1 P10
(Use work
offset 10)
All
machines
G61
G61
G61
All
machines
G64
G64
G64
All
machines
G70
Finishing Cycle.
G70 [P#][Q#]
G70 P100
Q250
Turning
machines
only
G71
G71
G71
Turning
machines
only
G73 Z-20
Milling
R1 Q1 P100 and
turning
machines
only
G74-G75
Generic
G74
drilling/boring/tapping [X#][Y#][Z#][R#]
canned cycle. These are
used in a generic way 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.
G74 Z-20
R1
G76
Generic
drilling/boring/tapping
canned cycle. See G74G75 above.
Milling
machines
only
G76
Threading Cycle
Turning
machines
only
Milling
and
turning
machines
only
G80
G81
G82-G89
Generic
drilling/boring/tapping
canned cycle. Same as
G74-G76 above.
G82
[X#][Y#][Z#][R#]
G82 Z-20
R1
Milling
and
turning
machines
only
G90
Absolute programming
mode. Distances given
will move the tool
relative to an absolute
zero.
G90
G90 G00
X10 Y10
All
machines
G91
Incremental
programming mode.
Distances given will
move the tool relative
to the current position
of the tool.
G91
G92
G92 X20
Y20 Z10
All
machines
G94
G94
Milling
machines
G95
G95
Milling
machines
G96
G96 S300
Turning
machines
G97
G97
Turning
machines
G95
G80
Milling
and
turning
machines
only
G98
G99
Let's start with G71. This cycle is programmed by using two blocks.
Example:
N10 G71 U2 R1
N20 G71 P8 Q9 U0.4 W0
The parameters of the first block are:
U: The depth of cut during the cycle.
R: The retraction height for each completed cut.
The parameters of the second block are:
P: Start block number for the contour.
Q: End block number for the contour.
U: Finishing allowance in the X-axis.
W: Finishing allowance in the Z-axis.
If you load the turning center machine and then open the demo files, there is an example called:
Sample3_G70_G71_unit.CNC that you can try to see the cycle in action.
The G70 block at the end of the example is the Finishing Cycle. It simply repeats the blocks used in the G71 cycle but
instead of doing rough cuts it does a contour cut removing the material left from the finishing allowances.
Threads can be done externally or internally with this two-block threading canned cycle. Here is a brief explanation of
the cycle and its parameters.
F: Thread pitch.
Note! The CNCSimulator Pro simplifies the threading process by ignoring some of the parameters, as for the simulation,
it is not important to take every parameter literary. The important parameters for the simulator are the following:
The Q parameter in the first block tells the simulator how much to take for each cut.
The X and Z values of the second block tells the simulator where to end the thread.
The F parameter of the second block tells the simulator the pitch of the thread.
There is an example among the demo programs called Sample4_G76_Threading_unit.cnc that you can run to see the
cycle in action
Other codes interpreted by the simulator
Format
Example
Code
Explanation
Absolute or
X#
incremental X
axis value used in
canned cycles
and codes like
G00-G03.
X2.43
Absolute or
Y#
incremental Y
axis value used in
canned cycles
and codes like
G00-G03.
Y1.16
Absolute or
Z#
incremental Z
axis value used in
canned cycles
and codes like
G00-G03.
Z-3.2
Represents the
I#
center in X in G02
and G03 circle/
arc commands.
G02 X34
Z106.867 I4.8 K0
Represents the
J#
center in Y in G02
and G03 circle/
arc commands.
G02 Y0 J-20
Represents the
K#
center in Z in G02
and G03 circle/
arc commands.
G02 X34
Z106.867 I4.8 K0
Selects a tool
from the user
defined tool
T1 M06
T#
registry in the
Inventory
Browser (F2).
M06 is used to
execute the
actual tool
change.
ET
Selects a tool
from the fixed
embedded tool
registry. M06 is
used to execute
the actual tool
change.
ET#
ET9 M06
DT
Selects a
DT#
predefined
milling tool. The
tool must first
have been
defined using the
$DefineMillTool
command. M06
is used to
execute the
actual tool
change.
DT3 M06
Defines spindle
rotation in
revolutions per
minute (RPM).
S2000
F240
Used in M98 to
P#
define a sub
program number.
Also used as
dwell time in
canned cycles.
M98 P1001 L1
Used in M98 to
define the
number of
repetitions.
M98 P1001 L1
Sub program
O#
number. Should
be the first line of
every sub
program.
S#
L#
G73 Z-20 R2 Q5
P100 F350
(Drilling sub
program 1)
O1000
Reference or
starting plane in
canned cycles. R
R#
G81 Z-20 R2
is 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 Circular
drilling cycle.
G12 X0 Y0 Z-20
R2 Q5 SA0 AS36
RA30 H10
G12 X0 Y0 Z-20
R2 Q5 SA0 AS36
RA30 H10
( and )
Used for
(text)
comments. G and
M codes inside
parenthesis will
not be executed.
$-commands will
be executed even
when inside the
parenthesis.
(Drilling sub
program 1)
Used for
comment out
one or several
lines. G, M and $commands will
not be executed.
Block number.
N#
N500