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

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.

OASIS Inspection Systems
High Accuracy Linear Encoders
Koma Precision
CHIRON Group, one stop solution for manufacturing.
Kennametal
Techspex
Gardner Business Intelligence
VERISURF
Gravotech
World Machine Tool Survey
IMTS 2024
DN Solutions

Related Content

SPONSORED

How this Job Shop Grew Capacity Without Expanding Footprint

This shop relies on digital solutions to grow their manufacturing business. With this approach, W.A. Pfeiffer has achieved seamless end-to-end connectivity, shorter lead times and increased throughput.

Read More

Tips for Designing CNC Programs That Help Operators

The way a G-code program is formatted directly affects the productivity of the CNC people who use them. Design CNC programs that make CNC setup people and operators’ jobs easier.

Read More

When to Use Custom Macros With a CAM System

Custom macros can offer benefits even when using a CAM system to prepare programs – but must be implemented with the right considerations.

Read More
Basics

7 CNC Parameters You Should Know

Parameters tell the CNC every little detail about the specific machine tool being used, and how all CNC features and functions are to be utilized.

Read More

Read Next

Vertical Machining Centers

The Cut Scene: The Finer Details of Large-Format Machining

Small details and features can have an outsized impact on large parts, such as Barbco’s collapsible utility drill head.

Read More
Basics

Obscure CNC Features That Can Help (or Hurt) You

You cannot begin to take advantage of an available feature if you do not know it exists. Conversely, you will not know how to avoid CNC features that may be detrimental to your process.

Read More

3 Mistakes That Cause CNC Programs to Fail

Despite enhancements to manufacturing technology, there are still issues today that can cause programs to fail. These failures can cause lost time, scrapped parts, damaged machines and even injured operators.

Read More
CNC Turnkey Package for Knee Mills and Lathes