What's new
What's new

# Macro Programming Fundamentals

#### PROBE

##### Hot Rolled
The technical facts should be described as clearly as possible, specially if statements are made be forum leaders like Bill and Sinha. To clarify the G31/G53 buffering preventing ability, here is excerpt from my post not long time ago.

Quote from B-63944EN/03 Fanuc 30/31/32 manual, page 556, paragraph 16.8:
"At the blocks containing M00, M01, M02 or M30, blocks containing
M-codes for which buffering is suppressed by setting parameters Nos.
3411 to 3420 and No.3421 to 3432, and blocks containing prevention
buffering G codes such as G31 or G53, the CNC stops to preread the
NC statement after that
. Then, the stop of the macro statement
execution is guaranteed until such M codes or G codes complete its
execution."

In simple words: The buffering preventing starts AFTER the block containing G31 is executed.

Let's assume following sequence:
N1 G31 X10. F10
N2 #100=#5061

The NC statement after G31 is X10. F10. Block N2 is not buffering prevented, and #100 is loaded with arbitrary value of #5061. The correct syntax of the sequence should be:
N1 G31 X10. F10
G53
N2 #100=#5061
Now N2 is buffering prevented by G53, and correct value of #5061 is loaded to #100.

Stefan
Cogito Ergo Sum

#### angelw

##### Diamond
In simple words: The buffering preventing starts AFTER the block containing G31 is executed.

Let's assume following sequence:
N1 G31 X10. F10
N2 #100=#5061

The NC statement after G31 is X10. F10. Block N2 is not buffering prevented, and #100 is loaded with arbitrary value of #5061. The correct syntax of the sequence should be:
N1 G31 X10. F10
G53
N2 #100=#5061
Now N2 is buffering prevented by G53, and correct value of #5061 is loaded to #100.

Stefan
Cogito Ergo Sum

Hello Stefan,
That is simply not correct. Both examples will have the exact same result.

Purely as a method of halting buffering, where you don't want the program to actually halt, which would be the case if M00 is used, either G31 or G53 can be used.

In your examples above, you're using G31 in the way it was designed for and that is to skip to the next block if a Skip Signal is detected.

There are some Positioning System Variables that can and can't be read during movement. The following picture, copied from a Fanuc Manual, is unambiguous as to which can and can't be read during movement.

In the following example of reading the Machine Coordinate System for the Z axis, which can't be read during movement:

G43 Z10.0 H01
#1 = #5023

assuming the axis movement is starting from the Z Reference Return Position, the System Variable #5023 would be read within milliseconds of the command being executed and #1 would take on a value of probably only circa -0.010mm or so.

G43 Z10.0 H01
G31 (or G53)
#1 = #5023

will result in #1 taking on the value of #5023 after the command block G43 Z10.0 H01 has completed its movement.

In your following example:

N1 G31 X10. F10
N2 #100=#5061

the Skip Signal Work Coordinate System for X (#5061) will be the position value when the Skip Signal is detected and won't vary by executing any delay, or any other Buffering Halt function post the Skip Signal. Accordingly, both of your examples will net the same result.

Regards,

Bill

#### sinha

##### Titanium
I have not actually tested, but I believe Bill is correct.
Both the examples of Probe should give the same result.
Look at the explanation copied from a Fanuc manual:

In the first case, the macro statement next to the G31 block is evaluated only after execution of G31 is complete. The second case is different because G31 or any other buffering-preventing function has not been used.

#### PROBE

##### Hot Rolled
Bill and Sinha,
Unfortunately the examples which you brought from Fanuc manuals are completely irrelevant to the case we are dealing with, as the block following the G31 in this examples does not include any data based on probing result. I do not know how to paste the picture copied from the manual to this text, but I can quote the statement from page 555 of the FANUC-30i-63944EN operating manual, which appears immediately after explanation brought by Sinha:
CAUTION
In case that you need to execute the macro
statement after completing the block just before the
macro statement, specify M code or G code that is
not buffered just before the macro statement.
Specially, in case of reading/writing the system
variables to control signals, coordinates, offset
value, etc., it may different system variable data by
the timing of the NC statement execution. To avoid
this phenomenon, specify such M codes or G
codes before the macro statement, if necessary.

I believe there is no need for more detailed directive and explanation of the necessity of using buffering prevention code (G53 or any other) between the G31 move command and the following macro statement.

Stefan
Cogito Ergo Sum

#### sinha

##### Titanium
Probe,
Your highlighted statements do not contradict what I stated.
G53 and G31 both prevent buffering. Therefore, if G31 has been used, there is no need for G53.

How do you explain the example-1?
The control does not process N2 till N1 is completed.
It is shown graphically also.
Therefore, whether N2 has #5061 or anything else, is hardly important.
The control will never know it because it will not read it till N1 is complete.
Please conduct a small experiment and share the results.

#### angelw

##### Diamond
Bill and Sinha,
Unfortunately the examples which you brought from Fanuc manuals are completely irrelevant to the case we are dealing with, as the block following the G31 in this examples does not include any data based on probing result.

Hello Stefan,

Sinha and I were making comments in reply to the OP's Post regarding the different results achieved when not using and using a code to halt buffering, when reading the System Variables for Program Numbers. The OP used G53 in his example, I stated that G31 could also be used.

With regards to timing, Feed Rate makes a difference to the actual position registered in the Skip Function System Variable (also varied by the Skip Function Used - High Speed or not), but it does not affect the value read from the Skip Function System Variables after the Skip Function has been executed. There may be a different value in the Skip Function Variable due to the precise moment when the Skip Function was executed, but definitely not to the value read from that Variable after the Skip Function.

Regards,

Bill

#### tteitgen

##### Aluminum
Probe,
Your highlighted statements do not contradict what I stated.
G53 and G31 both prevent buffering. Therefore, if G31 has been used, there is no need for G53.

How do you explain the example-1?
The control does not process N2 till N1 is completed.
It is shown graphically also.
Therefore, whether N2 has #5061 or anything else, is hardly important.
The control will never know it because it will not read it till N1 is complete.
Please conduct a small experiment and share the results.

Running the above examples in my Fanuc simulation software, the G31 is buffering the statement as expected. The Fanuc manual states:

#### PROBE

##### Hot Rolled
1. Sinha,
I have experienced this phenomenon so many times, no need to run it once more.

2. Bill, tteigen,
I would read very carefully the content of the CAUTION remark, included in tteigen post. I emphasized for you the important topics:

CAUTION
In case that you need to execute the macro
statement after completing the block just before the
macro statement, specify M code or G code that is
not buffered just before the macro statement.
Specially, in case of reading/writing the system
variables to control signals, coordinates, offset
value, etc., it may different system variable data by
the timing of the NC statement execution. To avoid
this phenomenon
, specify such M codes or G
codes before the macro statement, if necessary.

It says, it is not happening always, but it may happen. Therefore the necessity is obvious. The tools to prevent it (G53 for example) are given. The investment and/or effort to implement them are negligible. For me good engineering means make any effort to avoid problems. And it means - use these tools.

Stefan
Cogito Ergo Sum

#### sinha

##### Titanium
Please explain example-1
What does the graphic mean?

#### PROBE

##### Hot Rolled
Hi Sinha,
You and Bill explained in excellent way the Fanuc graphics. I couldn't add anything. Unfortunately, these graphics have nothing to do with our case, as the macro expression in block N2 (#1=100.) is not using any variables, and content of the #1 will always be 100, no matter if buffered or not. Fanuc have been aware about this problem and added in CAUTION remark: ... specify M code or G code that is not buffered just before the macro statement. Specially, in case of reading/writing the system variables to control signals, coordinates, offset value, etc.
Interesting is, that in previous revisions of Fanuc operating manuals this remark appeared under NOTE title. Seems that the importance of the issue caused them to change the title to !CAUTION, emphasized by exclamation mark.

I do believe that you yourself, Bill and, with all humbleness, me myself, our role is to be mentors to forum members, each of us in field of his expertise. I am always giving my best effort to explain to my audients what is a good, correct practice in engineering. In this particular case using the G53 statement in block immediately following the G31 statement costs nothing, but avoids potential serious problems. And that's what GOOD PRACTICE is all about.

Stefan
Cogito Ergo Sum

#### angelw

##### Diamond
1. Sinha,
I have experienced this phenomenon so many times, no need to run it once more.

2. Bill, tteigen,
I would read very carefully the content of the CAUTION remark, included in tteigen post. I emphasized for you the important topics:

CAUTION
In case that you need to execute the macro
statement after completing the block just before the
macro statement, specify M code or G code that is
not buffered just before the macro statement.
Specially, in case of reading/writing the system
variables to control signals, coordinates, offset
value, etc., it may different system variable data by
the timing of the NC statement execution. To avoid
this phenomenon
, specify such M codes or G
codes before the macro statement, if necessary.

It says, it is not happening always, but it may happen. Therefore the necessity is obvious. The tools to prevent it (G53 for example) are given. The investment and/or effort to implement them are negligible. For me good engineering means make any effort to avoid problems. And it means - use these tools.

Stefan
Cogito Ergo Sum

Stefan,
You're missing the point that G31 is one of those Codes that are NOT buffered. The G31 function will complete before the Skip Function System Variable is read if its the next block after the Skip Function. The Caution above does NOT apply to the G31 Skip Function, for it is NOT buffered.

Like you, I've executed Skip Function code many times but without any error. Unlike you, I carried out Sinha's test some years back and Posted the result here on this Forum and I did it again today, with the result Posted below.

I apologize for the poor quality pictures; they were taken with the only mobile phone that was available and the camera resolution is rubbish.

For clarification of the simple program, the code for with and without G53 is shown in Text following:

Without G53 included after the Skip Function

O6014
(BUFFER HALT TEST)
N1 G17 G21 G40 G49 G80 G90 G94
G91 G28 Z0.0
G28 X0.0 Y0.0
G90 G00 G54 X-246.0 Y170.0
G43 Z50.0 H08
G91 G31 X50.0 F500
G65 H01 P#100 Q#5061 (COMMON VARIABLE #100 ACCEPTS THE VALUE)
G91 G00 X-10.0
G91 G28 Z0.0
G28 X0.0 Y0.0
M30
%

With G53 included after the Skip Function

O6014
(BUFFER HALT TEST)
N1 G17 G21 G40 G49 G80 G90 G94
G91 G28 Z0.0
G28 X0.0 Y0.0
G90 G00 G54 X-246.0 Y170.0
G43 Z50.0 H08
G91 G31 X50.0 F500
G53 (G53 ADDED)
G65 H01 P#101 Q#5061 (COMMON VARIABLE #101 ACCEPTS THE VALUE)
G91 G00 X-10.0
G91 G28 Z0.0
G28 X0.0 Y0.0
M30
%

The result of executing the two programs above is shown below, with Common Variable #100 and #101 reading the value of System Variable #5061 without and with, receptively, G53 included immediately after the G31 Function.

An additional Buffering Halt Code is NOT required after a G31 Skip Function, when the Next Block, or one following soon after is to read the Skip Function System Variable.

The timing issue does NOT apply to the G31 Skip Function when reading the data from the Skip Function System Variable, because the value is secure in the System Variable before the program Skips to the next Block. The Value in the Skip Function System Variable may vary due to timing, but it will be the same value when read by the next, or subsequent Blocks. This has Zero to do with Buffering when related to the G31 Skip Function.

Regards,

Bill

#### angelw

##### Diamond
Hi Sinha,
You and Bill explained in excellent way the Fanuc graphics. I couldn't add anything. Unfortunately, these graphics have nothing to do with our case, as the macro expression in block N2 (#1=100.) is not using any variables, and content of the #1 will always be 100, no matter if buffered or not.

I have no idea what you're talking about. In this recent discussion with tteigen, it's been about reading System Variables and he has discovered that the halt of Buffering is sometimes required.

You started your recent involvement with tteigen's Post with:

The technical facts should be described as clearly as possible, specially if statements are made be forum leaders like Bill and Sinha. To clarify the G31/G53 buffering preventing ability, here is excerpt from my post not long time ago.

The fact is, your description of the requirement of Buffer Prevention after a G31 Ship Function and before reading from the associated Skip Function System Variable, is not technically or otherwise correct.

I don't disagree with including code for safety sake; all of the programs I wright myself have much code that many may consider superfluous, but each tool operation is able to stand as a stand alone program; accordingly, when having to repeat an operation (for whatever purpose), its difficult to go wrong. But I balk at placing a sting of code that effectively has the same purpose, that is, having numerous Buffering Prevent codes following one another as in the case of G53 following G31. Sure, it won't hurt, but for accuracy sake for those that are learning, its NOT required.

Regards,

Bill

#### PROBE

##### Hot Rolled
Hi Bill,
Seems that now we are facing the problem of interpretation of written text. Although, contrary to you, English is not my mother tongue, I believe that I understand quite well written text, specially if it is in my fields of interest (thanks God, not engineering only).
The example given in Fanuc manual is very clear and straight forward.
N1 G31 X100.0
N2 #100=1
Simple and conforms with your theory.

But if so, why Fanuc decided to place framed remark in bolt text under !CAUTION title, elaborating that In case that you need to execute the macro statement after completing the block just before the macro statement, specify M code or G code that is not buffered just before the macro statement. Specially, in case of reading/writing the system variables to control signals, coordinates, offset value, etc. Apparently it seems to them too, that it is not so simple when values like probing results are evaluated. Now, let's try to understand the Japanese English: In my opinion they clearly say, that you have to put the buffer preventing G or M function "after completing the block just before the macro statement", i.e. G53 or stand alone G31 or dedicated M between the G31 move block.

Stefan
Cogito nErgo Sum

#### sinha

##### Titanium
Probe,

Nobody is contradicting what is written as Caution.
This applies when buffering-preventing code is not used.
Since G31 prevents buffering, no additional buffering-preventing code such as G53 is needed.

To repeat what I said earlier, and as CLEARLY explained in graphic in Fanuc manual, the code next to G31 block is NOT read by the control till G31 is complete. Therefore, it is hardly important what is contained in the block following G31 block. It will not be read till G31 is complete.

The thing is, both you and the Fanuc manual cannot be correct at the same time.

But, I do agree that inserting an additional buffering-preventing code, G53, after G31 block, will do no harm.

Note: There are some mistakes in Fanuc manuals also. I did discuss a few things with Fanuc Japan, long time back, and they admitted the mistakes. Therefore, there is a possibility that you may have found that G53 after G31 is needed in some cases, which Fanuc does not know.

#### PROBE

##### Hot Rolled
Therefore, there is a possibility that you may have found that G53 after G31 is needed in some cases, which Fanuc does not know.

Hi Sinha,
I am not a sort of Don Quijote fighting with wind mills. The problem exists. Not me only is aware about that. In many of Renishaw, Marposs and Blum known to me measuring programs for Fanuc the "additional" G53 is used.

Having debate with Fanuc ? Not me. These guys (and not they only) "per defintio" never fail. I as engineer am obliged to discover the problem, understand its cause and find the solution. And I did.

Stefan
Cogito Ergo Sum

#### PROBE

##### Hot Rolled
Excerpt from Blum Inspection:
%
O9704(MEASURE)
(V2AC 23.02.07 DJ COPYRIGHT BLUM-NOVOTEST GMBH 2007)
IF[[#130AND16]EQ0]GOTO1
G53
IF[#1013NE1]THEN#121=30
(IF[OUT3NE0]THEN#121=30)
IF[#1012NE1]THEN#121=30
IF[#121EQ0]GOTO1
M[99]
N1IF[#26NE#0]GOTO2
IF[#17GT#[#135+0]]THEN#17=#17-#[#135+0]
N2G53
#1=#5041
#2=#5042
#3=#5043-[#122*[[#130AND32]/32]]
IF[#24EQ#0]THEN#24=#1
IF[#25EQ#0]THEN#25=#2
IF[#26EQ#0]THEN#26=#3
#21=0
N3#27=#24-#1
#28=#25-#2
#29=#26-#3
#14=SQRT[[#27*#27]+[#28*#28]+[#29*#29]]
#4=#24+[#17*#27/#14]
#5=#25+[#17*#28/#14]
#6=#26+[#17*#29/#14]
IF[#127GT[200./#131]]GOTO50
G31X#4Y#5Z#6F[#128*0.3]
G53
#7=#5061-[#[#135+4]*#27/#14]
#8=#5062-[#[#135+4]*#28/#14]
#9=#5063-[#122*[[#130AND32]/32]]-[#[#135+4]*#29/#14]
#30=#5061-#4

Stefan
Cogito Ergo Sum

#### tteitgen

##### Aluminum
Since we are on the topic of buffering. Can I place a 9 in parameter #3412? Could this be used as dual-purpose M code. Turn coolant off and prevent buffering.

#### angelw

##### Diamond
Excerpt from Blum Inspection:
%
O9704(MEASURE)
(V2AC 23.02.07 DJ COPYRIGHT BLUM-NOVOTEST GMBH 2007)
IF[[#130AND16]EQ0]GOTO1
G53
IF[#1013NE1]THEN#121=30
(IF[OUT3NE0]THEN#121=30)
IF[#1012NE1]THEN#121=30
IF[#121EQ0]GOTO1
M[99]
N1IF[#26NE#0]GOTO2
IF[#17GT#[#135+0]]THEN#17=#17-#[#135+0]
N2G53
#1=#5041
#2=#5042
#3=#5043-[#122*[[#130AND32]/32]]

IF[#24EQ#0]THEN#24=#1
IF[#25EQ#0]THEN#25=#2
IF[#26EQ#0]THEN#26=#3
#21=0
N3#27=#24-#1
#28=#25-#2
#29=#26-#3
#14=SQRT[[#27*#27]+[#28*#28]+[#29*#29]]
#4=#24+[#17*#27/#14]
#5=#25+[#17*#28/#14]
#6=#26+[#17*#29/#14]
IF[#127GT[200./#131]]GOTO50
G31X#4Y#5Z#6F[#128*0.3]
G53
#7=#5061-[#[#135+4]*#27/#14]
#8=#5062-[#[#135+4]*#28/#14]
#9=#5063-[#122*[[#130AND32]/32]]-[#[#135+4]*#29/#14]
#30=#5061-#4

Stefan
Cogito Ergo Sum

Hello Stefan,
The above program proves nothing, other than it may be the policy of the company, or the style of the programmer; it doesn't make it right. Certainly the code shown in Red should be preceded by a Buffer Prevention Code, but its unnecessary following the G31 Skip Function. I can post many examples of genuine Renishaw Programs that contain the G31 Skip Function where there is no other Buffer Prevention Code separating the G31 Block and a Block where the Skip Function System Variable is read.

Neither G31 nor G53 were designed to be stand alone Buffer Prevention Codes. In early days, G04 or a number of EOBs were specified in the Fanuc Manual for that purpose. The use of G31 and G53 for this purpose came about through dumb luck, where someone stumbled onto the fact that either of these codes could be used to Prevent Buffering and eventually, accepted by the factory.

Following is an example where a "G" Code that is not Buffered can still work to Prevent Buffering even when used for it's design purpose, one that you're familiar with, G53.

The following pictures show a simple program that includes G53 to position the X and Y axis at the Machine Coordinate Position specified in the G53 Block. The Block includes the Block Delete symbol so that the program can be executed with and without the G53 Block being executed to demonstrate that the Buffer Prevention still occurs even though G53 is being used for its design purpose.

Firstly, my apologies for the rubbish picture quality.

Again for clarity a Text copy of the simple program shown in the picture follows:

O6015
(BUFFER HALT TEST)
N1 G17 G21 G40 G49 G80 G90 G94
G91 G28 Z0.0
G28 X0.0 Y0.0
G90 G00 G54 X-246.0 Y0.0
/G53 X-50.0 Y0.0
G65 H01 P#100 Q#5021 (COMMON VARIABLE #100 ACCEPTS THE VALUE)
G91 G28 X0.0 Y0.0
M30
%

The following picture shows the result when the above program was executed with the Block Delete Switch turned ON:

The above picture shows that a value of -1.2mm being read due to no Prevention of Buffering occurring prior to the Read Macro Statement and represents the value read after a time period of circa 7.2ms after the Cycle Start Button was pressed. This is totally understandable, for the #502_ System Variables can't be read during movement; this is clearly spelt out in all Fanuc Manuals

The following picture shows the result when the above program was executed with the Block Delete Switch turned OFF:

The above picture shows that a value of -50.0mm being read due to Prevention of Buffering occurring prior to the Read Macro Statement. This represents the value read after the G53 Function had completed.
The exact same scenario occurs when G31 is executed in the manner it was designed for, that being to detect a Skip Signal and skip to the next block in the program. Just like the G53 example above, it also acts to Prevent Buffering even when being executed in it's design capacity.

By your reckoning, the program code would have to be as follows:

/G53 X-50.0 Y0.0
G53
G65 H01 P#100 Q#5021

Not so.

Today, I also took the matter up with resident Japanese, factory trained, Fanuc control and programming expert and he confirmed that G31 and G53 will prevent buffering irrespective of whether they are being used as a stand alone "G" code, or being executed for their design purpose.

When asked about the Caution Posted earlier in this Thread, he simply replied "translation" and reiterated that G31 requires no further Buffer Prevention code to follow it.

Regards,

Bill

#### sinha

##### Titanium
Since we are on the topic of buffering. Can I place a 9 in parameter #3412? Could this be used as dual-purpose M code. Turn coolant off and prevent buffering.

Yes.
Any number in the range 0-255 can be specified, including pre-defined codes, which will then serve dual purpose.
M00, M01, M02, M30 always prevent buffering, even if not specified in these parameters.

#### PROBE

##### Hot Rolled
Hi Bill,
1. First of all I wish to emphasize: I WAS WHITNESSING THIS BUFFERING PROBLEM AFTER G31 STATEMENT MANY TIMES, STAND ALONE G53 IN G31 FOLLOWING BLOCK WAS THE ULTIMATE ANTIDATUM.
Renishaw programs are not consistent regarding the use in standalone G53. Some do, some don’t. I experienced many times the problems with “G53 lacking” programs. As preemptive action I edited accordingly each and every program I dealt with, and spared to myself the necessity to deal with it in the field.

2.
The above program proves nothing, other than it may be the policy of the company, or the style of the programmer; it doesn't make it right .
Blum deals with nothing but probing. Maybe it is the matter of the temper of each of us, but I certainly would never undermine their programming staff’s skills and ability to understand the problem. They decided to use the G53 for a reason, technical reason.

3.
Today, I also took the matter up with resident Japanese, factory trained, Fanuc control and programming expert and he confirmed that G31 and G53 will prevent buffering irrespective of whether they are being used as a standalone "G" code, or being executed for their design purpose.
With all respect to this expert, your expertise, as well as mine, are as good as his. Facts count only. You say you never witnessed this phenomenon, I say I experienced it many times. Assuming that we both say truth, logically the problem exists.

4.
When asked about the Caution Posted earlier in this Thread, he simply replied "translation" and reiterated that G31 requires no further Buffer Prevention code to follow it.
This is very poor explanation. Translation ??????? We both, as well as all Fanuc users, are entitled to something much better.
For me, by the way, the directives of the CAUTION are clear. What bothers me is its last sentence: "To avoid this phenomenon, specify such M codes or G codes before the macro statement, if necessary."
The words if necessary have no place in technical language and any engineering document. Either it is imperative or not needed. No other option exists. Otherwise the bridges are falling, the buildings are crushing and probes are smashed.

Regards,
Stefan

Replies
7
Views
309
Replies
15
Views
360
Replies
36
Views
1K
Replies
8
Views
365
Replies
35
Views
1K