91ÊÓÆµÍøÕ¾ÎÛ

Published

Taking Advantage of G-Code Grouping

These preparatory functions make sure your CNC machine does what you want it to do.

Share

Leaders-In background

G codes are at the heart of a CNC program. These preparatory functions commonly set modes, telling the machine how to behave in the current command, and often in upcoming commands as well.

Closely related G codes are placed in G code groups. With FANUC controls, these groups are numbered. Group 01, for example, contains motion G codes G00, G01, G02 and G03 (among others). Group 02 contains plane selection G codes G17, G18 and G19. Group 03 contains positioning mode selection G codes G90 and G91. Reference the list of G codes in your FANUC manual to determine which G codes are in each group, as well as the group number for each group.

(By the way, Group 00 contains non-modal [one-shot] G codes, including dwell commands G04 and G09, reference return commands G28 and G30, and the custom macro calling command G65. This group is not of importance to this discussion.)

A series of custom macro system variables in the #4000 series provides access to the currently instated G code numeric value in every group. To determine the appropriate system variable number that provides access to a given group, add 4,000 to the group number. If the currently instated G code in group No. 2 two is G17, for example, the value of #4002 will be 17.0.

You can use #4000 series system variables to track which G code in a group is currently active and use this to your advantage when programming. Consider this example for tracking positioning mode, specified by G90 (absolute) and G91 (incremental) for FANUC-controlled machining centers. Say you want to write an incremental subprogram or custom macro that will be used by others. You’ll need to ensure that the machine is left in the original positioning mode when your program is finished. 

Positioning mode G codes are in group No. 3, so system variable #4003 provides access to which positioning mode is active. If absolute mode is currently active, the value of #4003 will be 90.0. If incremental mode is active, the value of #4003 will be 91.0. You can place this command at the beginning of your subprogram or custom macro:

#101 = #4003 (Store the current positioning mode G code value)

You can then switch to incremental mode (G91) and write the commands for your subprogram or custom macro. When finished, specify this command:

G#101 (Reinstate the original positioning mode)

You can even test the current G-code value and make the machine behave differently based on which G code is instated. Maybe a series of commands must be executed in the absolute mode. Consider the following commands that test current positioning mode. If absolute mode is not currently selected, an alarm will sound.

IF [#4003 NE 91.0] GOTO 5
#3000 = 101 (Wrong position mode)
N5 (Program continues)

You could even provide two sets of motion commands, one written with absolute positioning and the other with incremental positioning, and determine which set of commands will be executed by testing the current value of #4003.

The same techniques could be used with measurement system modes, using system variable #4006 to determine whether the machine is in the inch or metric mode (G20 or G21).

Implications of having access to current G-code settings may be a little difficult to visualize, but just about every G-code group has its own potential applications. Be sure to give this some thought. The best implications tend to be for applications of multi-purpose programs, typically custom macro programs, and especially when they will be used by several people.

Two more examples:
Inch and metric modes (G20 and G21). You have developed a custom macro that can be used in either measurement system. Speed could be specified in either surface feet per minute or surface meters per minute, depending on the chosen measurement system. Your custom macro can determine which measurement system is being used and apply the appropriate formula to calculate spindle speed in rpm.

Workpiece coordinate system offset selection modes (G54-G59). There are several things your program can infer if it knows which coordinate system offset is currently selected. For a rotary table application, for example, you may be trying to optimize positioning movements to clear obstructions between machined surfaces. When a particular side of the workpiece is facing the spindle, you must retract the tool farther than when another side of the workpiece is facing the spindle. By knowing which program zero point is currently active, your custom macro can determine which side is currently facing the spindle and make positioning movements accordingly. 

 

MMS Leaders in CNC Machining

Related Content

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
CNC Tech Talks

Computer Programming-Related Features of Custom Macro

Custom macro is an interpreter-based language, meaning that all CNC G code and custom macro commands are executed as the CNC comes across them.

Read More
CNC Tech Talks

Strange But True: Odd Things That Happen With CNCs

These oddities in the way a CNC naturally behaves can help explain some rather unusual situations that may occur during machining.

Read More
CNC Tech Talks

Troubleshooting Differences in Programming Methods, Machine Usage

Regardless of the level of consistency among machines owned by your company, you probably have experienced consistency-related issues. Here are some tips to help solve them.

Read More

Read Next

Automation

AMRs Are Moving Into Manufacturing: 4 Considerations for Implementation

AMRs can provide a flexible, easy-to-use automation platform so long as manufacturers choose a suitable task and prepare their facilities.

Read More
Economics

Last Chance! 2025 Top Shops Benchmarking Survey Still Open Through April 30

Don’t miss out! 91ÊÓÆµÍøÕ¾ÎÛ's Top Shops Benchmarking Survey is still open — but not for long. This is your last chance to a receive free, customized benchmarking report that includes actionable feedback across several shopfloor and business metrics. 

Read More
Basics

Machine Shop MBA

  Making Chips and 91ÊÓÆµÍøÕ¾ÎÛ are teaming up for a new podcast series called Machine Shop MBA—designed to help manufacturers measure their success against the industry’s best. Through the lens of the Top Shops benchmarking program, the series explores the KPIs that set high-performing shops apart, from machine utilization and first-pass yield to employee engagement and revenue per employee.  

Read More