Using the machine's current absolute position in a custom macro

One of the application categories for custom macro is user created canned cycles. In this category, you're creating your own canned cycle. As you know, most control-based canned cycles (like G81 - drilling) can use the machine's current position for certain things within the canned cycle. With G81 for example, if you leave out the X and Y value (hole center position), the machine will assume that the hole will be drilled in the current XY position. With three special system variables, you too can access the machine's current absolute position and use it from within your custom macros.

  • #5001 - current absolute position in axis one (X for machining centers)

  • #5002 - current absolute position in axis two (Y for machining center)

  • #5003 - current absolute position in axis three (Z for machining centers)

Let's look at an example. Here is a custom macro for thread milling:

  • O1000 (Thread milling custom macro)

  • (SET DEFAULT MILLING STYLE TO CLIMB MILLING)

  • IF [#13 NE #0] GOTO 1

  • #13=0

  • (TEST FOR MISSING ARGUMENTS)

  • N1 IF [#24 EQ #0] GOTO 95 (X)

  • IF [#25 EQ #0] GOTO 95 (Y)

  • F [#26 EQ #0] GOTO 95 (Z)

  • IF [#18 EQ #0] GOTO 95 (R)

  • IF [#7 EQ #0] GOTO 95 (D)

  • IF [#20 EQ #0] GOTO 95 (T)

  • IF [#9 EQ #0] GOTO 95 (F)

  • IF [#1 EQ #0] GOTO 95 (A)

  • IF [#17 EQ #0] GOTO 95 (Q)

  • (A MUST BE BIGGER THAN HALF OF T)

  • IF [#1 GT [#20/2 +0.1]] GOTO 2

  • #3000=101(APPROACH RADIUS TOO SMALL)

  • (RAPID TO APPROACH POSITION)

  • N2 G00 X#24 Y[#25 + #7/2 - #1] Z#18

  • (FAST FEED TO STARTING Z POSITION)

  • G01 Z#26 F[#9 * 5] (TEST FOR CLIMB VS CONVENTIONAL)

  • IF [#13 EQ 0] GOTO 10

  • (CONVENTIONAL MILL SETTINGS)

  • #100=[0-1] * [#1 - #20/2]

  • #101=#1 - #20/2

  • #102=2 (Motion type G02)

  • #103=0-1 (Polarity for stepping Z is minus)

  • GOTO 11 (CLIMB MILL SETTINGS)

  • N10 #100=#1 - #20/2

  • #101=[0-1] * [#1 - #20/2]

  • #102=3 (Motion type G03)

  • #103=1 (Polarity for stepping Z is plus)

  • (MOTIONS TO MILL THREAD)

  • N11 G01 X[#24 + #100] F#9

  • #26=#26 + [#103 * #17/4] (Step Z by 1/4 pitch)

  • G#102 X#24 Y[#25 + #7/2 -#20/2] Z#26 R[#1 - #20/2]

  • #26=#26 + [#103 * #17/2] (Step Z by 1/2 pitch)

  • Y[#25 - #7/2 + #20/2] Z#26 R[#7/2 - #20/2]

  • #26=#26 + [#103 * #17/2] (Step Z by 1/2 pitch)

  • Y[#25 + #7/2 -#20/2] Z#26 R[#7/2 - #20/2]

  • #26=#26 + [#103 * 17/4] (Step Z by 1/4 pitch)

  • X[#24 + #101] Y[#25 + #7/2 - #1] Z#26 R[#1 - #20/2]

  • G00 X#24 Z#18

  • GOTO 99

  • N95 #3000=100 (INPUT VALUE MISSING)

  • N99 M99 (End of custom macro)

Again, how this custom macro works is presented in an earlier issue. Please see issue 62 if you want to learn more about it.


With this custom macro in its current form, X and Y are used in the G65 command to specify the hole center. They are currently mandatory variables - an alarm will sound if they are not specified in the G65 command.


Say you want the this custom macro to behave more like a G81 canned cycle. If X and Y are left out of the call statement, you want the custom macro to assume that the hole center in X and Y is at the machine's current XY position. Here is the custom macro again, modified to use #5001, #5002, and #5003 that will do this.

  • O1000 (Thread milling custom macro)

  • (ATTAIN CURRENT XY POSITION)

  • IF[#24 NE #0] GOTO 1

  • #24=#5001

  • N1 IF[#25 NE #0] GOTO 2

  • #25=#5002

  • (SET DEFAULT MILLING STYLE TO CLIMB MILLING)

  • N2 IF [#13 NE #0] GOTO 3

  • #13=0

  • (TEST FOR MISSING ARGUMENTS)

  • N3 IF [#24 EQ #0] GOTO 95 (X)

  • IF [#25 EQ #0] GOTO 95 (Y)

  • F [#26 EQ #0] GOTO 95 (Z)

  • IF [#18 EQ #0] GOTO 95 (R)

  • IF [#7 EQ #0] GOTO 95 (D)

  • IF [#20 EQ #0] GOTO 95 (T)

  • IF [#9 EQ #0] GOTO 95 (F)

  • IF [#1 EQ #0] GOTO 95 (A)

  • IF [#17 EQ #0] GOTO 95 (Q)

  • (A MUST BE BIGGER THAN HALF OF T)

  • IF [#1 GT [#20/2 +0.1]] GOTO 4

  • #3000=101(APPROACH RADIUS TOO SMALL)

  • (RAPID TO APPROACH POSITION)

  • N4 G00 X#24 Y[#25 + #7/2 - #1] Z#18

  • (FAST FEED TO STARTING Z POSITION)

  • G01 Z#26 F[#9 * 5]

  • (TEST FOR CLIMB VS CONVENTIONAL)

  • IF [#13 EQ 0] GOTO 10

  • (CONVENTIONAL MILL SETTINGS)

  • #100=[0-1] * [#1 - #20/2]

  • #101=#1 - #20/2

  • #102=2 (Motion type G02)

  • #103=0-1 (Polarity for stepping Z is minus)

  • GOTO 11

  • (CLIMB MILL SETTINGS)

  • N10 #100=#1 - #20/2

  • #101=[0-1] * [#1 - #20/2]

  • #102=3 (Motion type G03)

  • #103=1 (Polarity for stepping Z is plus)

  • (MOTIONS TO MILL THREAD)

  • N11 G01 X[#24 + #100] F#9

  • #26=#26 + [#103 * #17/4] (Step Z by 1/4 pitch)

  • G#102 X#24 Y[#25 + #7/2 -#20/2] Z#26 R[#1 - #20/2]

  • #26=#26 + [#103 * #17/2] (Step Z by 1/2 pitch)

  • Y[#25 - #7/2 + #20/2] Z#26 R[#7/2 - #20/2]

  • #26=#26 + [#103 * #17/2] (Step Z by 1/2 pitch)

  • Y[#25 + #7/2 -#20/2] Z#26 R[#7/2 - #20/2]

  • #26=#26 + [#103 * 17/4] (Step Z by 1/4 pitch)

  • X[#24 + #101] Y[#25 + #7/2 - #1] Z#26 R[#1 - #20/2]

  • G00 X#24 Z#18

  • GOTO 99

  • N95 #3000=100 (INPUT VALUE MISSING)

  • N99 M99 (End of custom macro)

The highlighted commands provide the desired function. If either or both of X and Y are left out of the call statement, the values of #24 and/or #25 will be set to the machine's current absolute position in X and/or Y.

117 views

Recent Posts

See All
cnc reverse logo.jpg
0

44 Little Cahill Road

Cary, IL  60013

Ph: 847-639-8847

  • Facebook Social Icon