Digital Readout Kit for Mills, Lathes, & Grinding
Published

CNC-Related Features of Custom Macro

CNC-related features of custom macro are separated into two topics: system variables and user-defined G and M codes. This column explores both.

Share

Leaders-In background
An operator at a machine control
Photo Credit: Getty Images

Last month’s column described computer-programming-related features of custom macro. This column address CNC-related features of custom macro, which are separated into two topics: system variables and user-defined G and M codes.

System variables are specified with variables numbered 1,000 and larger. Each type of system variable has its own group of system variable numbers. All provide access to CNC functions that are not available in normal G-code programming. This column goes through some of them, not sequentially, but in order of popularity.

It can be difficult to appreciate the importance of system variables and think of implications as to when they can be helpful. Below are a few simple examples, but they just scratch the surface of what’s possible.

Some system variable numbering varies among various FANUC CNCs (especially related to offset registers), so you must reference custom macro documentation for your CNC to determine which system variables are involved. Also, newer FANUC CNCs provide system variable names as well as numbers. We show the numbers since they work on all FANUC CNCs.

Custom macro enables users to write and read to and from offset registers (ranging in the #2000 and #10000 series). With tool length compensation, for example, #2001 provides access to the value stored in tool length compensation geometry offset register number one. #2002 provides access to offset two — and so on.

Consider these commands:

  • #100=#2001 (place the value currently in offset number one in common variable #100)
  • #2001=#101 (overwrite the value in offset number one with the value of #101)
  • #2001=#2001+#101 (modify the value of in offset number one by the value of #101).

An example that sets offsets 1-50 to zero:

  • .
  • #100=1 (counter)
  • WHILE [#100 LE 50] DO 1
  • #[2000+#100] = 0 (set offset register to zero)
  • #100 = #100 +1 (step counter by one)
  • END 1
  • .

Custom macro also provides access to alarm generation and stop with message (#3000 and #3006). Alarm generation gives users the ability to set error traps. Stop with message is like a program stop command (M00), but a message will be displayed to tell the operator why the program has stopped.

  • #3000=100(OFFSET IS NOT SET)
  • #3006=100(TURN PART AROUND IN CHUCK)

The number to the left of the parentheses (100 in our case) is the alarm or message number. This message will be displayed if the alarm or message command is executed. Consider this command:

  • IF[#2001 LT 3.0] THEN #3000=100(TOOL IS TOO SHORT)

The alarm generation command will only be executed if the value in tool length compensation geometry offset register number one is less than 3.0. If true, the machine will go into alarm state and this message will be displayed on the display screen:

  • MC100 TOOL IS TOO SHORT

Users also can access axis position (ranging in the #5000 series). These system variables are read-only, letting you access the current position of each axis in several ways. Here are three ways for the X-, Y- and Z-axes:

  • #5001: X-axis position relative to program zero
  • #5002: Y-axis position relative to program zero
  • #5003: Z-axis position relative to program zero
  •  
  • #5021: X-axis position relative to the reference (home) position
  • #5022: Y-axis position relative to the reference (home) position
  • #5023: Z-axis position relative to the reference (home) position
  •  
  • #5061: X-axis position after skip signal (used with touch probes)
  • #5062: Y-axis position after skip signal (used with touch probes)
  • #5063: Z-axis position after skip signal (used with touch probes)

Example using an edge finder as a touch probe:

  • .
  • G90 G00 X-0.5 Y0.5 (Move edge finder with 0.5-in of the left side of part)
  • Z-0.2 (move edge finder below top of workpiece)
  • #100=0.1 (Edge finder radius)
  • #3006=100(TOUCH LEFT SIDE OF PART IN X)
  • #101=#5021 + #100 (Surface location in X from reference position)
  • G91 G00 X-0.5 (Move away 0.5-in)
  • .

When the machine stops and the message is displayed at the #3006 command, the operator will switch from automatic to handwheel mode, bring the edge finder flush with the left side of the part, reselect the automatic mode and restart the cycle. The surface location will then be stored in common variable #101. This could be the program zero surface which can now be placed in the X-axis register of the fixture offset.

With user-defined G and M codes, users can create new G and M codes or redefine the way current G- and M-codes work. Doing so involves parameter settings, and the involved parameter numbers vary among FANUC CNC models. The user must reference custom macro documentation for their CNC.

In essence, you will be setting up a kind of cross reference table so that when the CNC comes across the user-defined G or M code in a program, it will execute a predetermined custom macro.

Example that redefines the function of the M06 tool change command:

For a popular FANUC CNC model, parameter number 6071 is used to specify the M-code number that will call program number O9001. We will set this parameter to a value of 6. From then on, whenever the CNC reads an M06, it will execute program O9001. Instead of just making a tool change, change the function of M06 so that it first moves the machine axes to the tool change position and orients the spindle:

  • O9006
  • G91 G28 Z0 M19
  • M06
  • M99

User-defined G codes work much the same way, though a different group of parameters and program numbers is involved. With user-defined G codes, you can include arguments in the calling command. You can also create modal user-defined G codes.

What we have shown is basic. You should be starting to see, however, how CNC-related features might help in your own applications.

Techspex
IMTS+
SolidCAM
VERISURF
Hurco
715 Series - 5-axis complete machining
World Machine Tool Survey
Starrett W9400 Touch Screen Indicator
To any Measurement Question there is an Answer
JTEKT
DANOBAT
Paperless Parts

Related Content

5 Reasons Why You Should Know How to Write Custom Macros

Custom macros enhance what can be done in G-code programs, giving users the ability to code operations that were previously not possible.

Read More

Can AI Replace Programmers? Writers Face a Similar Question

The answer is the same in both cases. Artificial intelligence performs sophisticated tasks, but falls short of delivering on the fullness of what the work entails.

Read More
Basics

4 Commonly Misapplied CNC Features

Misapplication of these important CNC features will result in wasted time, wasted or duplicated effort and/or wasted material.

Read More
Measurement

6 Machine Shop Essentials to Stay Competitive

If you want to streamline production and be competitive in the industry, you will need far more than a standard three-axis CNC mill or two-axis CNC lathe and a few measuring tools.

Read More

Read Next

Workforce Development

Building Out a Foundation for Student Machinists

Autodesk and Haas have teamed up to produce an introductory course for students that covers the basics of CAD, CAM and CNC while providing them with a portfolio part.

Read More

5 Rules of Thumb for Buying CNC Machine Tools

Use these tips to carefully plan your machine tool purchases and to avoid regretting your decision later.

Read More

Registration Now Open for the Precision Machining Technology Show (PMTS) 2025

The precision machining industry’s premier event returns to Cleveland, OH, April 1-3.   

Read More
CNC Turnkey Package for Knee Mills and Lathes