G Code Groups What Use Are They?

G Code Groups What Use Are They?

G Code Groups, every G code is in a group and I remember looking at G codes for years thinking why on earth do they do that?

I thought it was just to satisfy the geeks, it gave them more bullshit to talk about.

Anyway now I’m all grown up, I know exactly why G Codes are in groups.

The good news is today I am going to tell you why and….. I am going to give you a practical example.

Here is a list of G codes and the group that they are in

G Code
G Code List with Groups

Hass G Code Groups do vary a little.

Now I know this is boring but please try to keep focused it gets exciting soon honestly. If you are loosing the will to live already then off you go, this video is amazing.

I know it’s only two of us now but I will carry on. I wrote this article a bit back about macro for the over 18’s.

When you start to write serious macros you need to write alarms to protect the opeator just incase he types in bollocks instead of an R number or some such thing.

Anyway there is a thing I call tidying up after youself. This is not like when you cook a meal and your ungrateful girlfriend expects you to tidy up the kitchen just because it looks like a post war bombsite.

I made cheese on toast and I must say it tasted great. Cooking’s got to be easier than this G Code shit.

What this is about is putting things back as they were. So the G Codes that were in use before going into your macro need to be restored before coming out.

For example most machines when you issue an M6 command jump into a macro program. See this article

The macro program might look something like this.

09101                           (TOOL CHANGE MACRO)
G80G40G49             (CANCEL ACTIVE G CODE) 
M9                               (COOLANT OFF)
G28 G91 Z0              (SEND TOOL BACK TO ZERO)
M19                             (SPINDLE ORIENTATION)
M6                               (TOOL CHANGE)

What this macro actualy does is all the crap you can’t be arsed with.

In your main program you would have to do all this every time you want a tool change. You don’t see any of this because the program is not visble. The M6 aliases program 9101.

So when you program M6 you get program 9010 running behind the scenes.

So as I said your an advanced G Code programmer now so I expect a bit more from you. “What me” you say. “Yes you” I saw it on your CV.

Oh and you just swapped the control into G91 in the macro above (you naughty boy)

So for example if the machines was in rapid G0 and absolute G90 the guy who called the tool-change will expect it to stay that way.


So when the control comes out of your tool change macro it’s in G91, not good.

This could easily cause a collision. You say “ah but the programmer should use G90 when he states the first position”.

Right, We Need To Talk

As I said you are an adult now and in the adult world of Macro programming you tidy up and you take responsibilty for the G code you change.

I’ll be honest with you now, lots of people who should know better don’t do this. A good example are probing programs.

Anyway what shall we do about it?

We Do This

#1=#4001                  (STORES ACTIVE G CODE IN GROUP 1)
(G0 1 G2 G3)

#3=#4003                (STORES ACTIVE G CODE IN GROUP 3)
(G90 G91)

#14=#4014             (STORES ACTIVE G CODE IN GROUP 14)
(G54 G55 G56 G57 G58 G59)

G80G40G49             (CANCEL EVERYTHING) 
M9                               (COOLANT OFF)
G28 G91 Z0              (SEND TOOL BACK TO ZERO)
M19                             (SPINDLE ORIENTATION)

G#1 G#3 G#14            (RESTORE G CODES)

OK What’s Going On Here

(G0 1 G2 G3)

(G90 G91)

#14=#4014(STORES G CODE GROUP 14)
(G54 G55 G56 G57 G58 G59)

The lines above take the G codes from three groups.

  • G0 G1 G2 G3
  • G90 G91
  • G54 G55 G56 G57 G58 G59

It stores those values in #1 #3 and #14

So if the machine were in feed (G1) it would store 1 in #1

If the machine were in absolute (G90) it would store 90 in #3

And if the machine were in work offset G59 it would store 59 in #14

The four thousand system variable looks into the various G code goups.

Now Let’s Magic Them Back

Magic Back The G Codes

Restore The G Code Groups

At the end of the program we have

G#1 G#3G#14

Which is the same as.

G1 G90 G59

This would depend on the state of the machines before you went into the macro.

So what we have done is restore the G codes back to their original values before we started tampering with them.

That way if the machine crashes you can say “look mate I never touched a thing”


Log out of this account

Leave a Reply

WP to LinkedIn Auto Publish Powered By : XYZScripts.com