What's new
What's new

M code to instate my G54 work offset

GSMachinist

Plastic
Joined
Jul 27, 2020
I would like to type in an M code and have my G54 work coordinate instated in my Fanuc Oi-MD vertical mill. Example I indicate the center of a part using my dial test indicator, go to Work offset and inter the coordinate under G54, How do I create a program that when I type in a M code it calls up a program and runs it (using macro statements to do this), fdes anyone know of a resource for doing this.
Thank Greg
 
Typically, all you need to do to call any work offset is to just use G54, G55, etc. That will instate that offset. If you are describing your needs accurately, you can specify your own M & G codes (ones that are NOT already used) and assign a program to be run to those M & G codes. It requires the G or M code number to be assigned to a parameter so when that G or M code is used, it will run that program. Check your Fanuc parameter manual. I don't have one near me at the moment.

Paul
 
I would like to type in an M code and have my G54 work coordinate instated in my Fanuc Oi-MD vertical mill. Example I indicate the center of a part using my dial test indicator, go to Work offset and inter the coordinate under G54, How do I create a program that when I type in a M code it calls up a program and runs it (using macro statements to do this), fdes anyone know of a resource for doing this.
Thank Greg

parameters 6071 through 6089 set the m-codes to call programs 9001 through 9029

Hint : 6071 is usually set to 6

you will also have to set parameter 3202.4 to enable editing of 9000 series programs.
 
Perhaps you don't realize that as soon as G54 appears in your program your G54 Work Coordinates are instated. How is it that typing in an M code to bring about a G code is saving you anything? As long as G54 appears in your program before the first move, the machine will move within the confines of the numbers you have set in your G54 Work Coordinate Screen. Besides, most machines default to G54, so it's already active when you turn on the machine.

Others have given you info on creating programs (which can include G codes) called by M code, but unless I'm missing something or you haven't accurately explained your needs, I can't see the reasoning or usefulness behind it.

EDIT ADD: On your Check Screen or one of the screens, I can't remember which, you can see all of the active G and M codes. More likely then not G54 will already be showing there. Meaning it's active and instated.
 
yes I am having trouble explaining my needs. I'll try again, clamp part to table, indicate bore, go to G54 work offset and move cursor to G54 X, input value by pressing "X" then input, then move cursor to G54 Y, input value by pressing "Y" then input. G54 work coordinate is set. Want I want to do is simplify this process by putting a M code statement in the top of the program before program reads any G54. So I am able to eliminate the process of setting the G54 work offset my self.
 
yes I am having trouble explaining my needs. I'll try again, clamp part to table, indicate bore, go to G54 work offset and move cursor to G54 X, input value by pressing "X" then input, then move cursor to G54 Y, input value by pressing "Y" then input. G54 work coordinate is set. Want I want to do is simplify this process by putting a M code statement in the top of the program before program reads any G54. So I am able to eliminate the process of setting the G54 work offset my self.


Sorry, still not quite understanding. You do know, by entering these numbers, you are actually writing to a parameter and a system variable. There is no way to do what you just described. You can, however, use the G10 command to write values to the offsets but somewhere, you still need to enter these manually. The best option in case you haven't thought of this, is to get a probe. Best money ever spent.
 
I really hate telling anyone this, but you could use G92 instead. Put a G92 X0Y0 at the top of the program, indicate the center of your part and press go? I've never done that myself, because I don't like using G92. Someone will chime in and tell me I'm nuts, I'm sure
 
Okay I see. Other then a probe, which are great, I believe there are system variables that always know what the current machine position is. If your machine is ready to make chips at the current position in X and Y, you should be able to read these and apply them to any offset you like with your program heading M code. You could also simply have a subroutine call M98P01 say, at the head of your programs, and store your macro in that sub resident in your program file list. You'll have to dig in the manuals to find the proper system parameters that stores this stuff. I'm not much on writing Macros, but I bet this one would be easy once you knew what the place holder (system variable) numbers were.

Looks like he got it.....
 
Sorry, still not quite understanding. You do know, by entering these numbers, you are actually writing to a parameter and a system variable. There is no way to do what you just described. You can, however, use the G10 command to write values to the offsets but somewhere, you still need to enter these manually. The best option in case you haven't thought of this, is to get a probe. Best money ever spent.


Oh do I wish I had a probe!!!!!!!!!!!!

I did figure this out, So when ever M154 is executed machine will read the following program and set G54 work Coordinate for me. I'll put M154 at the top of the program. it was figuring 6071 parameter would read program O9001.


%
O9001 (M154)
(PROGRAM TO SET G54 USING M154)
(SETTING X G54)
#100=#5021
G10L2P1X#100
(SETTING Y G54)
#101=#5022
G10L2P1Y#101
M30
%
 
I really hate telling anyone this, but you could use G92 instead. Put a G92 X0Y0 at the top of the program, indicate the center of your part and press go? I've never done that myself, because I don't like using G92. Someone will chime in and tell me I'm nuts, I'm sure


Nope, not nuts. I used G92 for many years too. Just do not put any work offset calls like G54 in your program at all.
 
yes I am having trouble explaining my needs. I'll try again, clamp part to table, indicate bore, go to G54 work offset and move cursor to G54 X, input value by pressing "X" then input, then move cursor to G54 Y, input value by pressing "Y" then input. G54 work coordinate is set. Want I want to do is simplify this process by putting a M code statement in the top of the program before program reads any G54. So I am able to eliminate the process of setting the G54 work offset my self.

Hello GSMachinist,
Your program example in your Post #9 will only set Offset G54. The following shows/explains how any Workshift Offset from G54 to G59 can be set by just editing the "S" argument value in the call program.

You need to write a Macro program and have it called via a Custom M Code. Following is an example.

1. Indicate the part so that the X/Y axes slides are at the work piece X/Y Zero.

2. Select the program that contains the following, program O1000 for example:

O1000
M111 S1
M30

Where:
M111 is your Custom M Code. In the following example "111" is registered in parameter 6080 so as to call program number O9020

and

S_ = The Workshift Offset Number 1 to 6 corresponding to G54 to G56 respectively, where _ = numbers 1 to 6.

3. Edit the "S" argument to represent the Workshift Number.

4. Execute the above program which will in turn, execute the following program.

O9020
IF [[#19 EQ #0] OR [#19 LE 0] OR [#19 GT 6]] GOTO 900 (ERROR TRAP FOR ARGUMENT OUT OF RANGE)
#[5201 + 20 * #19] = #5021 (REGISTER CURRENT X MACHINE POSITION INTO G54 TO G56)
#[5202 + 20 * #19] = #5022 (REGISTER CURRENT Y MACHINE POSITION INTO G54 TO G56)
M99
N900 #3000 = 1 (OFFSET NUM RANGE ERROR}
%


Regards,

Bill
 
Last edited:
GSMachinist,

Yes, I believe what you would like to do, is possible.
Or I should say, it would be possible on a standard "i" series Fanuc (ie. 18i/21i/31i).
I have never had any exposure to an 0i controller.

Basically, this would be similar to what a probe does, electronically/automatically, only you would be manually finding your position, and using your custom M-code to capture your location.
Pretty much what you described in your post.

The system variables that you will want to review and use for your macro program will be the #5021-#5028 Current Position - Machine.
I would also want to look at the #5081-#5088 system variables, which are for the Tool Length Offset.
You will then want to transfer the values from these system variables, into the Workpiece Coordinate Variables #5201-#5328.

The macro program number will need to be O9020-O9029, in order to be used as a custom M-code.
With this series of custom M-codes, you could also take your macro program one step further, and vary which Work Offset you want to save the current position to.

If you are not familiar with Macro B programming, here is a some good reference material:
https://sovathrothsama.files.wordpress.com/2016/03/fanuc_cnc_custom_macros.pdf

Macros can be very useful, but sometimes very trying to develop!

Very gratifying, when you get them to work like you want!

Hope this helps!

Good Luck!
 
Hello GSMachinist,
Your program example in your Post #9 will only set Offset G54. The following shows/explains how any Workshift Offset from G54 to G59 can be set by just editing the "S" argument value in the call program.

You need to write a Macro program and have it called via a Custom M Code. Following is an example.

1. Indicate the part so that the X/Y axes slides are at the work piece X/Y Zero.

2. Select the program that contains the following, program O1000 for example:

O1000
M111 S1
M30

Where:
M111 is your Custom M Code. In the following example "111" is registered in parameter 6080 so as to call program number O9020

and

S_ = The Workshift Offset Number 1 to 6 corresponding to G54 to G56 respectively, where _ = numbers 1 to 6.

3. Edit the "S" argument to represent the Workshift Number.

4. Execute the above program which will in turn, execute the following program.

O9020
IF [[#19 EQ #0] OR [#19 LE 0] OR [#19 GT 6]] GOTO 900 (ERROR TRAP FOR ARGUMENT OUT OF RANGE)
#[5201 + 20 * #19] = #5021 (REGISTER CURRENT X MACHINE POSITION INTO G54 TO G56)
#[5202 + 20 * #19] = #5022 (REGISTER CURRENT Y MACHINE POSITION INTO G54 TO G56)
M99
N900 #3000 = 1 (OFFSET NUM RANGE ERROR}
%


Regards,

Bill

This, as usual, is complete. I, in order to add some additional "intuitivity", would instead of using S1-S6 arguments, use S54-S59 for G54-G59.
"
O1000
M111 S54
M30

Where:
M111 is your Custom M Code. In the following example "111" is registered in parameter 6080 so as to call program number O9020

and

S_ = The Workshift Offset Number 54 to 59 corresponding to G54 to G59 respectively, where _ = numbers 54 to 59.

3. Edit the "S" argument to represent the Workshift Number.

4. Execute the above program which will in turn, execute the following program.

O9020
IF [[#19 EQ #0] OR [#19 LE 53] OR [#19 GT 59]] GOTO 900 (ERROR TRAP FOR ARGUMENT OUT OF RANGE)
#[5201 + 20 * [#19-53]] = #5021 (REGISTER CURRENT X MACHINE POSITION INTO G54 TO G59)
#[5202 + 20 * [#19-53]] = #5022 (REGISTER CURRENT Y MACHINE POSITION INTO G54 TO G59)
M99
N900 #3000 = 1 (OFFSET NUM RANGE ERROR}
%
 
Yes, glad you agree it’s bad to post a link to someone’s copyrighted material. Wonder why you did it if you think it bad? I doubt that Mr Smid appreciates folks doing that too.

Odd question but.... If I already own the book, would/should I feel bad about downloading a copy of the .PDF?

I didn't, and I won't, just a thought experiment.
 








 
Back
Top