The Use of Variables, Macros and Subroutines and Compatibility With FANUC Parametric Programming ......................... 3
The Use of Variables, Macros and Subroutines and Compatibility With FANUC Parametric Programming ......................... 3
1.1.1 Introduction
The Artisan CNC system supports the use of „variables‟ in CNC programming. Through the use of
variables, great flexibility and power can be built into relatively simple G-Code sequences. Artisan CNC
supports variables in two distinct styles. The first is the style used by the FANUC 6M controller. These
variables are known as „Numeric Variables‟ and are described in an upcoming section. This feature is
provided to support customers‟ pre-existing FANUC 6M programs. The other major style of variables
supported by Artisan CNC are called „Alphanumeric‟ (or simply „Alpha‟) variables. This style of
variables is unique to the Artisan CNC software. Alpha variables allow considerable freedom in
programming and enable G-Code programs of great power to be easily developed.
1.2.1 Introduction
Macros and Subroutines greatly extend the capabilities of the standard G-Code programming
language. In their most basic form, a macro provides the ability to execute a block of G-Code repeatedly,
while only having to write it once. In addition, information known as “parameters” can be communicated
(or “passed”) to a macro or subroutine. These parameters can be acted on by the subroutine in any
manner we wish. This enables us to control the behavior of a subroutine from one execution to the next.
Artisan CNC provides for declaring and executing macros and subroutines in a manner that
provides compatibility with the FANUC 6M controller. In addition, the naming conventions for
subroutines have been extended in a manner similar to the extensions for variable names. The use of
macros with Alpha names (known as „symbolic macros‟) and Alpha variables is known in this guide as
“Ah-ha! style programming”. As we will see, these extensions significantly increase both the ease with
which programs can be written, and the power available to the user.
Please note that, with the FANUC 6M controller, a „macro‟ and a „subroutine‟ have different
definitions. A „macro‟ is defined as a piece of code that is invoked using one technique, and a
„subroutine‟ is invoked using another. Both techniques are supported by Artisan CNC. Since there are no
functional differences between „macros‟ and „subroutines‟ under the Artisan system, the terms „macro‟
and „subroutine‟ are used interchangeably in this guide.
1.2.2 FANUC 6M Compatible Programming
Introduction
Artisan CNC supports a macro capability that is designed to provide compatibility with the FANUC
6M controller. This includes the naming convention for macros, the syntax used to invoke (or „call‟)
those macros from the mainline program, and the syntax used to return control to the main program. At
the time of production of this guide, the major difference between Artisan CNC and the FANUC 6M lies
in the method of entering programs into the control. With the FANUC 6M controller, programs may be
defined in any order desired. On the Artisan CNC system, the mainline program must be defined first,
followed by the macros. Macros may be defined in any order. This limitation stems from the fact that on
a PC-based CNC control, G-Code programs are essentially 1 large text file, with execution starting at the
beginning of the file. For FANUC 6M programs that are pre-existing on magnetic media such as floppy
diskette, a text editor program can be used to move the mainline program to the front of the file such that
it precedes all of the macros. This will enable these programs to execute normally.
The mainline program must be the first routine defined in the G-Code file.
Macros or subroutines must end with an M99 code, whereas mainline programs typically end with
either an M02, M30, or M31.
A short G-Code file with a mainline program and one subroutine might look like this:
Example 1
:0001
N20 T4M06
N22 G80 G90 G40
N24 G01 X-3.0 Y-0.33
N26 M98 P2 L10
N28 M30
:0002
N5 G91
N6 G01 X0.035
N7 G01 Y-0.12
N8 M99
Note the definition of the mainline program as program number 1 (:0001) and the subroutine as
program number 2 (:0002). The steps required to actually call the subroutine and exit from it are
described in the following sections.
A #1 ..................................................................................................... Q #17
B #2 ....................................................................................... ............. R #18
C #3 ....................................................................................... .............. S #19
D #7 ....................................................................................... ............. T #20
E #8 ....................................................................................... ............. U #21
F #9 ....................................................................................... ............. V #22
H #11 ..................................................................................... ............ W #23
I #4 ....................................................................................... ............. X #24
J #5 ....................................................................................... ............. Y #25
K #6 ....................................................................................... ............. Z #26
M #13
From this mapping information, our parameters in the previous example would show up in the
macro in the following way:
The value 1.500, intended to be the X-coordinate of our hole, would be in #1.
The value 0.750, intended to be the Y-coordinate of our hole, would be in #2.
The value 0.3, the depth of our hole, would be in #3.
From here, we could move to our hole‟s X-Y coordinates by issuing something like this:
G00 X #1 Y #2
We should note that the order in which the letter/number pairs appear is not important. We could
have called the macro like this:
G65 P0005 B0.750 C0.3 A1.500
and the result would be exactly the same. If we called the macro like this:
G65 P0005 B1.500 C0.750 A0.3
the 1.500 would now show up in the macro in variable #2. The value 0.750 would now be in
variable #3, and the value 0.3 would now be in variable #1.
Example 3
Use of Numeric Variables in a FANUC-style macro
O0001
#100=1
#101=3.0
#102=1.5
#103=0.5
#104=400
#105=3.5
#106=3.
#107=2.0
G90 G54 S #104 M03
G00 X #101 Y #102
G43 H #106
G01 Z0.1
G01 Z -#103 F [ #105 / 2]
Y [#102 + #107 / 2 - #100 / 2]
G02 J -[ #107 / 2 - #100 / 2]
G01 Y #102
G00 Z0.1
M30
Example 4
A macro written in the Ah-ha! Programming Style
O %MAC1
%V100 = 1.0
%V101 = 3.0
%V102 = 1.5
%V103 = 0.5
%V104 = 400.0
%V105 = 3.5
%V106 = 3.0
%V107 = 2.0
G90 G54 S %V104 M03
G00 X %V101 Y %V102
G43 H %V106
G01 Z0.1
%FEED = %V105 / 2.0
G01 Z -%V103 F %FEED
%YCOORD = %V102 + %V107 / 2.0 - %V100 / 2.0
G01 Y %YCOORD
%JVECT = - (%V107 / 2.0 - %V100 / 2.0)
G02 J %JVECT
G01 Y %V102
G00 Z 0.1
M30