0% found this document useful (0 votes)
536 views16 pages

How Subprograms Work: Subprograms in Mastercam Mill and Lathe

This chapter discusses how subprograms work in Mastercam. There are two categories of subprograms: transform and non-transform. Transform subprograms are created using transform toolpaths, while non-transform subprograms are generated as a toolpath option for repetitive motions like depth cuts or drilling. The NCI file writes subprogram information using 1018 and 1019 Gcodes to define the start and end of each subprogram block.

Uploaded by

Hoang Lam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
536 views16 pages

How Subprograms Work: Subprograms in Mastercam Mill and Lathe

This chapter discusses how subprograms work in Mastercam. There are two categories of subprograms: transform and non-transform. Transform subprograms are created using transform toolpaths, while non-transform subprograms are generated as a toolpath option for repetitive motions like depth cuts or drilling. The NCI file writes subprogram information using 1018 and 1019 Gcodes to define the start and end of each subprogram block.

Uploaded by

Hoang Lam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Volume 2 Chapter 2 How Subprograms Work

2 How Subprograms Work

This chapter provides information on subprograms in Mastercam, the NCI file, and the MP language.
Mastercam subprogram support allows repetitive toolpath motion to be output as subprograms. The
toolpath motion must be identical for a toolpath to be considered a subprogram. When determining
how or what to put in a subprogram, Mastercam does not compare separate geometric chains to
determine if the motion is the same as another chain. Numerous options can cause Mastercam to create
separate subprograms, such as work offsets, multiple chains being selected, and multi passes. For more
information on creating subprograms in Mastercam toolpaths, please refer to Mastercam online help.
Mastercam subprograms allow you to create subprograms through depth cuts, drilling, and transform.
You can also create nested subprograms, where a toolpath that includes non-transform subprogram is
transformed with subprograms active. For example, a contour toolpath with depth cuts that are
subprograms could be translated with transform and subprograms active.
Note: If you are using subprograms in Mastercam Wire, see the “Subprograms in Mastercam Wire”
section.

Subprograms in Mastercam Mill and Lathe


In Mastercam, there are two categories of subprograms:
! transform subprograms
! non-transform subprograms

Both categories support motion with either absolute or incremental positioning in the subprogram.

Transform subprograms
Transform subprograms are created by using Transform toolpaths. Each transformation of the selected
toolpaths or source operations is a subprogram.
Transform subprograms cannot be nested in another transform operation that is marked as a
subprogram. However, non-transform subprograms or non-subprogram toolpaths can be nested in a
transform subprogram. For example, a contour toolpath with depth cuts that are subprograms could be
translated and subprograms could be created using transform.
Transform by operation order
Transform by operation order creates a single subprogram with all source operations in the transform
selection included in the subprogram called at each transform location. When the Unique Subprograms
check box is checked in the Mastercam dialog box, a separate, unique subprogram will be created for
each tool change and each will be called in order at each transform location.

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 2-1


Chapter 2 How Subprograms Work Volume 2

Transform by instance
Transform by instance always creates a subprogram for each tool selected and a single tool transform is
assigned. A single tool operation is performed at each location before the next operation is called.
Note: Transform subprograms are available in Lathe for turning operations. Depth cut and drill
subprograms are only available in Mill operations

Non-transform subprograms
Non-transform subprograms are subprograms generated as a toolpath option. These are toolpath
sections that can be identified as repeating patterns and are supported under the Depth Cuts dialog in
Contour, Pocket, Face and Circle Mill toolpaths. When subprograms are activated through the depth
cuts dialog box, matching depth cuts in the XY plane are marked as subprograms.
Note: Tapered walls and islands are not supported in subprograms.

Subprograms in drill operations


Subprograms are available in drill toolpaths in two ways:
! You can make a single drill operation a subprogram by checking the Subprogram check box on the
Drill Cycle dialog box. By doing this, the drill cycle will become a unique subprogram.
! You can have multiple drilling operations reference the same drill points. This method allows
multiple drilling operations to use the same points to create a single subprogram. Only the points
after a drill cycle definition are allowed as a subprogram. (These are the 100 Gcodes only.) If a
jump height or any event reintroduces a cycle definition, the subprogram is disabled.
How to create a drilling subprogram using the same drill points
1. Create a drilling operation.
2. From the Toolpaths, Drill, Subpgm Ops menu, enable subprograms.
3. Select the parent drilling operation.
4. Define the drill cycle.
Note: Subprograms are not yet available in Auto Drill or Drill 5-axis toolpaths.

NCI file subprogram concepts


Mastercam writes subprogram information to the NCI file in long code format. All motion code is
written as if subprograms weren’t available. The subprogram information is written to the NCI file
using the 1018 and 1019 NCI Gcode lines. These lines will become a wrapper for the motion that is to
become a subprogram. The MP language processor then reads these NCI lines and, based on the
parameters in these lines, determines whether to:
! Write the initial subprogram.
! Make a call to the subprogram and call the appropriate predefined postblocks inside the post
customization file (.pst).

Subprogram level hierarchy


Subprograms are designed to allow three levels of subprograms:
2-2 Mastercam Version 9 MP Post Processor Reference Guide June 2002
Volume 2 Chapter 2 How Subprograms Work

! The top level is the default NC level. This level is always active if no subs are defined.
! The second level is the transform level. This level is set for all transform subprograms.
! The third level is for all non-transform subprograms. In the absence of the transform level,
third level subprograms are output at the second level.

1018 / 1019 position in the NCI file


The 1018 NCI Gcode defines the start of a subprogram block and the 1019 NCI Gcode defines the end
of a subprogram block. For every 1018 there will be a corresponding 1019. The position of the 1018
and 1019 depend on whether the subprogram being written is a transform or non-transform
subprogram.
With transform subprograms
Transform subprograms position the 1018 directly after the 1020 NCI Gcode line. The 1019 NCI
Gcode then encloses all operations selected for the transform. This output and positioning continues
for each transform location. Like parentheses, these NCI Gcodes must nest any non-transform
subprograms.
With non-transform subprograms
Non-transform subprograms place the 1018 NCI Gcode and 1019 NCI Gcode dependent on the
toolpath type.
A further distinction is made between Drill and Depth Cut subprograms:
Non-transform depth cut subprograms
The 1018 NCI Gcode is placed before the first position to be placed in the subprogram. The 1019 NCI
Gcode is placed after the last position to be placed in the subprogram.
Non-transform drill subprograms
The 1018 NCI Gcode is placed after the cycle definition (81 NCI Gcode). The definition is outside of
the subprogram so repeated points can be called with a different cycle definition. The 1019 NCI Gcode
is placed before the cancel drill cycle NCI line (80 NCI Gcode).
Special Cases – Lathe turning canned cycles
The Lathe canned turning cycle(s) automatically produce a non-transform subprogram for the chain
that was selected as the final profile. All motion from the first point in the chain to the last point in the
chain is included in the subprogram. The numbering procedure used for any other non-transform
subprogram applies and must be included when processing for subprograms. This subprogram is used
internally by the MP language processor and doesn’t follow the normal subprogram output method.
See Volume 2, How Lathe Canned Cycles Work for more information.

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 2-3


Chapter 2 How Subprograms Work Volume 2

Understanding the 1018 and 1019 Gcodes


1018 Subprogram Start Definition
g
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

g 1018 gcode
1 Subprogram number sub_op_id
2 Actual operation id sub_grp_id
3 Transform/non- sub_ref_id 0 Non-transform
tansform indicator
>0 Transform
4 Iteration counter sub_sec_no Transform operations:
<0 = Off
0 = Original
>0 = Copy
Non-transform operations:
<1 = Copy in transform
1 = Original
>1 = Copy
5 Total number of sub_totl_no
instances, 1-based
6 Not used sub_chn no
7 Absolute or sub_inc 0 Absolute
incremental 1 Incremental
8 Transform type sub_trnstyp 0 Mirror
1 Rotate
2 Scale (not used)
3 Translate
9 sub_trnmthd 0 Translate method = Tool plane
1 Translate method = Tool plane with
‘Tool plane origin ONLY’ checked

2 Translate method = Coordinate

10 Transform matrix sub_m1


11 Transform matrix sub_m2
12 Transform matrix sub_m3
13 Transform matrix sub_m4
14 Transform matrix sub_m5
15 Transform matrix sub_m6
16 Transform matrix sub_m7
17 Transform matrix sub_m8
18 Transform matrix sub_m9
19 Transform X data Mirrored data:
X axis mirror, set X axis intersection
Rotated data:
XYZ = center of rotation relative to
current view
Translated data:
XYZ = translation distance relative to
2-4 Mastercam Version 9 MP Post Processor Reference Guide June 2002
Volume 2 Chapter 2 How Subprograms Work
original operation
20 Transform Y data sub_trnsy Mirrored data:
Y axis mirror, set Y axis intersection
Rotated data:
XYZ = center of rotation relative to
current view
Translated data:
XYZ = translation distance relative to
original operation
21 Transform Z data sub_trnsz Rotated data:
XYZ = center of rotation relative to
current view
Translated data:
XYZ = translation distance relative to
original operation
22 First tool in the sub_nxt_t
transform group
23 First head number in sub_nxt_h
the transform group
24 Not used sub_nxt_tid
25 More than one tool in sub_mny_t 0 Only 1 tool used in the transform
transform 1 Multiple tools used in the transform
26 Not used
27 Not used

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 2-5


Chapter 2 How Subprograms Work Volume 2

1019 Subprogram End Definition


g
123456

g 1019 gcode
1 Subprogram number esub_op_id
2 Actual operation id esub_grp_id
3 Transform/non- esub_ref_id 0 Non-transform
transform flag
>0 Transform
4 Iteration counter esub_sec_no Transform operations:
<0 = Off
0 = Original
>0 = Copy
Non-transform operations:
<1 = Copy in transform
1 = Original
>1 = Copy
5 Total number of exub_totl_no
instances
6 Not used esub_chn_no

1018 Interpretation
The post executable uses the 1018 parameters to determine what sub level is being processed. This
level will determine how to set output stream levels. Output can occur at the NC level, transform sub
level or the non-transform sub level. Parameter 1 (subprogram number), parameter 3 (transform/non-
transform indicator), and parameter 4 (iteration counter) trigger the output stream level and are critical
to the basic subprogram functionality.
Note: Subprograms of the non-transform type (sub level) read only the first seven parameters from the
1018 Gcode line.

Subprogram ID (parameter 1)

Parameter 1 (sub_op_id) is the unique subprogram ID and is used to produce the subprogram number.
! In transform subprograms, this value is written to the main_prg_no for output at the transform level.
! In non-transform subprograms, this value is written to the sub_prg_no for output at the non-
transform level.
The unique subprogram ID (sub_op_id) is numbered independently for transform and non-transform
subprograms. In most cases, these are sequentially assigned values for each new pattern. Repeated
patterns then reuse the value assigned to the original pattern.
Subprogram ID assignment exceptions in Mastercam

DRILL (non-transform) – Any point where a drill cycle definition (G81) is cancelled or
assigned a new subprogram ID is assigned and a new unique subprogram is created. This
occurs with jump heights.

2-6 Mastercam Version 9 MP Post Processor Reference Guide June 2002


Volume 2 Chapter 2 How Subprograms Work

ABSOLUTE SUBPROGRAMS (non-transform) – Absolute subprograms are


problematic because the repeat tool motion has to reset the machine coordinates relative to
any XY pattern shift. New subprogram IDs are assigned to patterns even if they are
repeating to simplify processing the NCI when no machine coordinate shift occurs.
NON-TRANSFORM subprograms and NOT NESTED – Depth cuts and drill patterns
work as absolute or incremental because there is currently no XY pattern shift.
SUBPROGRAMS WITH TRANSFORM – Transform subprograms and transform
subprograms with nested non-transform subprograms present many special cases. The
subprogram numbering is influenced by the operation being performed (translate, rotate,
mirror), work origin shifts, and the absolute incremental setting. In any case where it is
determined that the subprogram cannot be repeated, a new subprogram with a unique ID
will be created.

Subprogram reference ID (Parameter 3)

Parameter 3 (sub_ref_id) is the subprogram reference ID. This variable is tested to see if it is greater
than zero. If the test is true, the output level is set to transform; otherwise it is set to non-transform.
When a non-transform operation is referenced in a transform operation as a copy, these values will be
signed negative.

Subprogram iterator (Parameter 4)

Parameter 4 (sub_sec_no) is the subprogram iterator and is used to determine what type of output is to
occur.
! At transform level, parameter 4 (sub_sec_no) is checked to see if it is zero. A value of 0 indicates
that the NC code for the actual subprogram is generated and written along with a call to the
subprogram. Any other value only produces a call to the subprogram.
! At non-transform level, parameter 4 (sub_sec_no) is checked to see if it is 1. A value of 1 indicates
that the NC code for the subprogram is generated and written along with a call to the subprogram.
Any other value only produces a call to the subprogram.
The subprogram iterator (sub_sec_no) controls the output of the original subprogram.
! Transform subprograms write the original when 0 is assigned
! Non-transform subprograms write the original when 1 is assigned. This condition should occur
only once for any defined subprogram pattern. If it occurs more than once, the post outputs
duplicates of the same subprogram, which is an error.
Therefore, non-transform subprograms nested in transform subprograms must have the non-transform
subprogram iterator (sub_sec_no) signed negative in transform patterns where they are copies.
Note: Be aware that the original non-transform subprograms may be outside the first transform
operation so the original transform may contain a copy. This design allows hiding the non-transform
subs without losing the iteration number.

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 2-7


Chapter 2 How Subprograms Work Volume 2

Subprogram total count (parameter 5)

Parameter 5 (sub_totl_no ) is the subprogram total count and is used to track the cumulative number of
repeated patterns.
! In transform, subprograms track the cumulative number of repeated patterns relative to each
transform referencing the original operation. The original operation has parameter 5 assigned the
cumulative count of the first referenced transform. This allows the user to find the end of the
current transform when multiple transforms were assigned.
! In non-transform, subprograms track the number of repeated patterns relative to the current
operation. The total does not increase when copied into transform subprograms.
Critical parameters used to control output levels

Transform subs Non-transform subs


Parameter 1 main_prg_no sub_prg_no
sub_op_id If parameter 3 > 0, sub_op_id becomes main If parameter 3 <= 0, sub_op_id becomes
subprogram number. sub subprogram number.
Parameter 3 Transform subprogram if greater than 0. Non-transform sub if less than or equal to
sub_ref_id 0.
Parameter 4 Output subprogram if 0. Any other value Output subprogram if 1. Any other value
sub_sec_no causes only a call to the sub. causes only a call to the sub

1019 Interpretation
The 1019 NCI Gcode parameters are used to return the output stream level to the previous level that
was set prior to 1018 being called. Therefore, 1018 and 1019 are matched pairs and only 'non-
transform' subprograms may nest in transform subprograms. The first six parameters written on the
matching 1018 NCI Gcode line are repeated as the six parameters with the 1019 NCI Gcode line.
Complete 1018 Interpretation

Assoctype.h 1018 Mirror Rotate Translate


sub_idn sub_op_id sub_op_id sub_op_id sub_op_id
sub program id # non_transform id # transform id # transform id # transform id #
op_idn sub_grp_id sub_grp_id sub_grp_id sub_grp_id
operation id # operation id # operation id # operation id # operation id #
op_ref_idn sub_ref_id sub_ref_id sub_ref_id sub_ref_id
operation id # this 0 = non-transform If > 0, this operation If > 0, this operation If > 0, this operation
section references <0 = non-transform is a transform. is a transform. is a transform.
being referenced by
a transform
somewhere else
(copy)
section_n sub_sec_no sub_sec_no sub_sec_no sub_sec_no
current iteration # output sub = 1 output sub = 0 output sub = 0 output sub = 0
of depth cut or iterate from base 1, iterate from base 0, iterate from base 0, iterate from base 0,
xform instance valid > 0, negative valid >=0 valid >=0 valid >=0
2-8 Mastercam Version 9 MP Post Processor Reference Guide June 2002
Volume 2 Chapter 2 How Subprograms Work

Assoctype.h 1018 Mirror Rotate Translate


if copy in a
transform
section_total sub_totl_no sub_totl_no sub_totl_no sub_totl_no
total # of iterations Total number of Total number of Total number of Total number of
instances, 1-based instances, 1-based instances, 1-based instances, 1-based
chain_n sub_chn_no sub_chn_no sub_chn_no sub_chn_no
chain number chain number not used not used not used
im_dead ONLY SOURCE ONLY SOURCE ONLY SOURCE ONLY SOURCE
0=ok to convert to
ascii, 1=don't output
unused_1 ONLY SOURCE ONLY SOURCE ONLY SOURCE ONLY SOURCE
unused_2 ONLY SOURCE ONLY SOURCE ONLY SOURCE ONLY SOURCE
unused_3 ONLY SOURCE ONLY SOURCE ONLY SOURCE ONLY SOURCE
inc sub_inc sub_inc sub_inc sub_inc
0=absolute 0=absolute 0=absolute 0=absolute 0=absolute
1=incremental 1=incremental 1=incremental 1=incremental 1=incremental
xf_type sub_trnstyp sub_trnstyp sub_trnstyp sub_trnstyp
0=mirror, 1=rotate, not used 0=mirror 1=rotate 3=translate
2=scale, 3=translate
xf_method sub_trnmthd sub_trnmthd sub_trnmthd sub_trnmthd
not used 0=X axis, 1=Y axis 0=Tplane, 0=Tplane,
2=entity 1=Tplane origin 1=Tplane origin
only only
2=coordinates 2=coordinates
xm.matrix_33 sub_m1 to sub_m1 to sub_m1 to sub_m1 to
sub_m9 sub_m9 sub_m9 sub_m9
not used mirrored matrix rotated matrix translated matrix
xm.p_3d[X] sub_trnsx sub_trnsx sub_trnsx sub_trnsx
not used Y mirror, X inter. X center rotation X translate relative
to origin
xm.p_3d[Y] sub_trnsy sub_trnsy sub_trnsy sub_trnsy
not used X mirror, Y inter. Y center rotation Y translate relative
to origin.
xm.p_3d[Z] sub_trnsz sub_trnsz sub_trnsz sub_trnsz
not used not used Z center rotation Z translate relative
to origin
next_tool_n sub_nxt_t sub_nxt_t sub_nxt_t sub_nxt_t
next tool # (-1 if no not used first tool in group first tool in group first tool in group
tools are next)
next_head_n sub_nxt_h sub_nxt_h sub_nxt_h sub_nxt_h
next head # not used first head in group first head in group first head in group
next_tool_idn sub_nxt_tid sub_nxt_tid sub_nxt_tid sub_nxt_tid
next tool id number not used not used not used not used
(internal id)
June 2002 Mastercam Version 9 MP Post Processor Reference Guide 2-9
Chapter 2 How Subprograms Work Volume 2

Assoctype.h 1018 Mirror Rotate Translate


tc_in_xf sub_mny_t sub_mny_t sub_mny_t sub_mny_t
1 = if this transform not used 0=one tool 0=one tool 0=one tool
contains multiple 1=more than one 1=more than one 1=more than one
operations with tool tool tool
different tools
wire2 ONLY SOURCE ONLY SOURCE ONLY SOURCE ONLY SOURCE
wire3 ONLY SOURCE ONLY SOURCE ONLY SOURCE ONLY SOURCE
pad[22] ONLY SOURCE ONLY SOURCE ONLY SOURCE ONLY SOURCE

Processing subprograms in the MP language


The MP language can direct NC code output to the sub files based on the order and level of the
1018/1019 NCI Gcode lines. This is termed automatic subprogram even though the postblocks and
appropriate subprogram code must be added to the post customization file to get specific output for a
machine control. Contact your dealer for cost and additional information.

Related post variables not read from the 1018 Gcode


Sub_level
The predefined variable sub_level is used to enable automatic subprograms and to control how the
output levels are reassembled. By initializing the variable to 1 or 2 (sub_level : 1), automatic
subprograms are enabled.

sub_level value Result


1 Causes the calling level ( NC level) to be written to the NC file.
2 Outputs the calling level (NC Level) to the alternate file (.ext), which allows using
the MP file merge commands to control how the output levels are reassembled.
See Volume 1, File Manipulation for more information.
-2 Disables automatic subprograms. By setting sub_level to – 2, subprograms will be
disabled and long code output will occur.
-1 Disables a single subprogram for long output. Assign sub_level to –1 (sub_level =
–1) in the postblocks psub_call_m, psub_call_mm, or psub_call_s. This prevents the
current output level from switching, and also prevents calls to psub_st_m,
psub_st_mm, psub_end_m, psub_st_s, and psub_end_s. After the location of the
normal end code, the automatic subprogram routine is restored. Logic must be
applied in psub_call_m, psub_call_mm, and psub_call_s to skip the subprogram calls in
the post.
Sub_out
The predefined variable subout sets the alternate file that the code being output will be written to.
Four files are available - NC, SUB, AUX, and EXT. This variable is set automatically for automatic
subprograms. The subout setting is determined by the value of sub_level.
See Volume 1, File Manipulation for more information.
2-10 Mastercam Version 9 MP Post Processor Reference Guide June 2002
Volume 2 Chapter 2 How Subprograms Work

Progno
The predefined variable progno contains the program number for the call level (NC).
Main_prg_no
The predefined variable main_prg_no contains the transform level subprogram ID. The value in
sub_op_id is written to main_prg_no.

Sub_prg_no
The predefined variable sub_prg_no contains the non-transform level subprogram ID. The value in
sub_op_id is written to sub_prg_no.

Merge commands
Mergesub, mergeaux and mergeext are used to combine all the alternate output files into one file.
See Volume 1, File Manipulation for more information.
Clear commands
Clearsub, clearaux and clearext are used to clear the alternate output files.
See Volume 1, File Manipulation for more information.
absinc
The predefined variable absinc controls absolute or incremental subprogram output (0=absolute,
1=incremental). For subprograms, the absinc value is read from the sub_inc parameter on the 1018.
The sub_inc parameter is set from inside the Mastercam settings in the subprogram dialog box. For the
call level (NC), absinc must be set in the post or through some user input. It is not done automatically
based on the settings in the subprogram dialog box. Normally this is done through the use of a
miscellaneous integer.

Predefined postblocks for calls and labels on the 1018 NCI Gcode
Psub_call_m
Psub_call_m is a special postblock used to output the subprogram call to the main level output file. This
postblock is called when:
! 1018 is encountered
! and the command word c_msng is found in the post
! and the transform operation has one tool change in it.

It is desirable to output the tool before the main call at the NC level so the current tool is not called
again.
sub_mny_t
The variable sub_mny_t is read from the NCI to determine if more than one tool is contained in a
transform operation. It is set to 1 when more than one tool is present.

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 2-11


Chapter 2 How Subprograms Work Volume 2

Psub_call_mm
Psub_call_mm is a special postblock used to output the subprogram call to the main level output file.
This postblock is called when:
! 1018 is encountered
! and the command word c_mmlt is found in the post
! and the transform operation has two or more tool changes in it.

It is desirable to output the tool inside the main program (level 1) allowing the tool to be called
repeatedly.
The variable sub_mny_t is read from the NCI to determine if more than one tool is contained in a
transform operation. It is set to 1 when more than one tool is present.
Psub_call_s
The psub_call_s postblock outputs the subprogram call to the sub level. This postblock is called when a
1018 is encountered and non-transform subprograms are active (sub_ref_id <= 0).
Psub_st_m
The psub_st_m postblock outputs the main program number (main_prg_no) and header to the transform
level. This postblock is called after the main level call (psub_call_m or psub_call_mm).
Psub_st_s
The psub_st_s postblock outputs the sub program number (sub_prg_no) and header to the sub level.
This postblock is called after the sub level call (psub_call_s).

Predefined postblocks for sub-level returns from on 1019 NCI Gcode


Psub_end_m
The psub_end_m postblock is called when returning from the transform level to the NC level.
Returning from the transform level to the NC level always restores the output stream to the default NC
level.
Psub_end_s
The psub_end_s postblock is called when returning from the sub level. Returning from the sub level to
the main level restores the output stream to the condition it was in when the main level called the sub
level.

Posting process for subprograms


Variables and postblocks
sub_level
The sub file and aux file are enabled at when sub_level=1 (open new and append). As automatic
subprogram processing continues, sub_level is set to the current sub level where:
! 0 is the calling level (nc)

2-12 Mastercam Version 9 MP Post Processor Reference Guide June 2002


Volume 2 Chapter 2 How Subprograms Work

! 1 (sub) is the main or transform level


! 2 (aux) is the sub or toolpath level
The value in sub_level is returned to subout variable internally to control the output stream.
As repeat patterns are read from the NCI for subprograms, the output stream is disabled until the return
to the calling level is reached. The calling level, sub_level=0 , (NC) is always output.
For the main level (sub_level =1) with tranform, output only occurs when sub_sec_no is 0. This is the
original pattern for the transform.
For the sub level (sub_level =2) with non-transform toolpaths, output only occurs when sub_sec_no is
one.
progno
The variable progno is used for the call level 0 (nc) program number. The variable main_prg_no is used
for main level 1 (sub) program number and is taken from the sub_op_id. The variable sub_prg_no is
used for sub level 2 (aux) program number and is also taken from the sub_op_id.
psub_call_m and psub_call_mm
psub_call_m or psub_call_mm are postblocks for output of the call to the main or transform level. These
special postblocks are called when the command words c_msng or c_mmlt are found in the post.
The variable sub_mny_t is read from the NCI to determine if more than one tool is contained in a
transform operation. It is set to 1 when more than one tool is present.
The postblock psub_call_m is called when command word c_msng is found in the post and the
transform operation has one tool change in it. It is desirable to output the tool before the main call so
that the current tool is not called again.
The postblock psub_call_mm is called when command word c_mmlt is found in the post and the
transform operation has two or more tool changes in it. It is desirable to output the tool inside the main
program (level 1).
After the main level call (psub_call_m or psub_call_mm), the stream is switched to the main level and
postblock psub_st_m is used for output of the main program number.
psub_call_s
The psub_call_s postblock outputs the call to the sub level. The stream is then switched to the sub level,
and postblock psub_st_s is used to output the sub program number and header.
psub_end_m and psub_end_s
Return from the main or transform level calls postblock psub_end_m and return from the sub level calls
postblock psub_end_s. Returning from the main level always restores the output stream. Returning
from the sub level to the main level restores the output stream to the condition it was when the main
level called the sub level. Returning to the NC level always restores the output stream.

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 2-13


Chapter 2 How Subprograms Work Volume 2

Merging
The user must add the sub merge commands if combining all output into the one NC file. Remember
to merge at the NC level, subout set to 0.

Absolute/incremental switching (absinc)


Automatic absolute and incremental switching is applied to subprograms from the Mastercam settings
for the main and sub levels. The user-defined variable absinc found in many Mastercam posts has been
converted to a pre-defined variable.
The post must assign the NC level absinc condition. absinc values are:
! 0 for absolute
! 1 for incremental

Just before the internal call to psub_st_m, psub_st_mm and psub_st_s, the absinc variable is set to the
subprogram setting.
Just before the internal call to psub_end_m, and psub_end_s, the absinc variable is set to the return level
subprogram setting.
Note: If automatic subs are not used, sub_level returns as -1 and the output stream is not switched. The
calls are performed to the predefined postblocks as in automatic processing. Code must be present in
your post for subprogram output to occur.

Additional Information
Disabling long output
A subprogram can be disabled for long output by assigning sub_level to -1 in the postblocks
psub_call_m, psub_call_mm, or psub_call_s. This prevents the current output level from switching and
prevents calls to psub_st_m, psub_st_mm, psub_end_m, psub_st_s, and psub_end_s. After the location of
the normal end code, the automatic subprogram routine is restored

Updating variables
The following variables are updated to their previous setting when returning from a transform sub to
the NC level, which allows the initialized value to be restored:

! sub_trnstyp
! sub_trnmthd
! sub_trnsx
! sub_trnsy
! sub_trnsz
! sub_nxt_t
! sub_nxt_h
! sub_nxt_tid
! sub_mny_t
Note: Do not update these values because they won't restore properly!

2-14 Mastercam Version 9 MP Post Processor Reference Guide June 2002


Volume 2 Chapter 2 How Subprograms Work

Initializing sub_trnstyp
sub_trnstyp is initialized internally to –1. Do not initialize in the post because an error will be generated.

Non-transform subprograms and Gcode1018


Subprograms of the non-transform type (sub level) read only the first seven parameters from the 1018
Gcode line.

Alternate output files


Automatic subprograms use the MP alternate files (.sub, .aux, .ext). The user should not use these files
with a post using subprograms.

Suppressing output
When the output stream is suppressed:
! The NCI is processed internally.
! Debug (bug2 and/or bug4) forces output of all levels.
! Error messages and leader and trailer code are output.
! All file-merging operations are output to the current level.
! Hexadecimal output is not suppressed.

Subprograms in Mastercam Wire


Mastercam Wire does not support subprograms in the same manner as Mill and Lathe. Please see
Mastercam online help for information regarding subprograms in Wire.

Gcode 1015 support


There is no 1018/1019 support in Mastercam Wire. Wire subprograms are supported through the 1015
NCI Gcode line. The 1015 NCI Gcode line is output prior to the 1016 line and the format is shown on
the next page.

Variables
There is no standard for subprogram support in a Wire post customization file. How subprograms are
supported is left entirely up to the post writer. The following is a list of variables that may be used for
Wire subprogram support.
! Subtype is a NCI variable that holds the subprogram flag set by Mastercam.
! Subno is a NCI variable that holds the subprogram number.
! Skimpass is a NCI variable that holds the skimcut parameter.
! Subout is a post switch variable that determines what alternate file (.nc, .sub, etc) the NC code is
written to.
See Volume 1, File Manipulation for more information.on using subout and the alternate output files.
See Volume 3, Numeric Variables for more information on all predefined variables.

June 2002 Mastercam Version 9 MP Post Processor Reference Guide 2-15


Chapter 2 How Subprograms Work Volume 2

1015 – Subroutine Parameters (Wire)


g
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

g 1015 gcode
1 Subroutine type settings subtyp 0 Not a subroutine
1 Write subroutine
2 Call subroutine only
2 Subroutine number subno
3 Thread/Cut flag td_ct_flg 0 No thread or cut
(Not used) 1 Allow thread the wire
in V8.1 2 Allow cut the wire
4 Tab Cut tabcut 0 No tab cut
1 Tab cut
2 Contour with tab cut
5 Wire Trim (wtrim): 0 Trim in control
1 Trim in computer
2 3D tracking
6 Skimcut options skimpass 0 No skimcut
+1 First skimcut pass on a
contour
-1 Subsequent skimcut pass
on a contour
-2 Last skimcut pass on a
contour.
7 Wire cut position X cutx
8 Wire cut position Y cuty
9 XY trimming plane trimplane1
10 UV trimming plane trimplane2
11 register value 1 reg1
12 register value 2 reg2
13 register value 3 reg3
14 register value 4 reg4
15 register value 5 reg5
16 register value 6 reg6
17 register value 7 reg7
18 register value 8 reg8
19 register value 9 reg9
20 register value 10 reg10

2-16 Mastercam Version 9 MP Post Processor Reference Guide June 2002

You might also like