Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: joeaverage on January 18, 2023, 05:52:42 PM

Title: How does G30 work?
Post by: joeaverage on January 18, 2023, 05:52:42 PM
Hi,
I have need for G30.  This is from the Gcode manual.

Code: [Select]
G30 – 2nd, 3rd, 4th Zero Return
G30 functions the same way as G28, moving the machine to a zero return point via an intermediate
point. However, instead of sending the machine to the home position, G30 movement ends at a user
definable 2nd, 3rd, or 4th zero return point, specified by P2, P3, or P4 respectively. If P is omitted the 2nd
zero return point is selected. This is handy for tool changers that are not located at the home position
or any number of other applications.
Format: G30 P__ X__ Y__ Z__ A__ B__ C__
The 2nd zero return point is defined by # variables as follows:
Axis P2 # Variables P3 # Variables P4 # Variables
X     5301               5311              5321
Y     5302               5312              5322
Z     5303               5313              5323
A     5304               5314              5324
B     5305               5315              5325
C     5306               5316              5326
The position values in the # variables can be set in a program or in MDI mode

The problem is that no matter what numbers I put into the pound variables the machine always drives to the machine zero (0,0,0) rather than the coordinates
UI have programmed into the pound variables. Does anyone know what I'm doing wrong?.

Craig
Title: Re: How does G30 work?
Post by: joeaverage on January 18, 2023, 07:47:18 PM
Hi,
I've made a few discoveries, one of which appears to be that the Gcode manual is wrong with respect to the pound varibles used.

In particular reading the Gcode manual for G30 suggests that the variable associated with P2 are #5301,#5302,#5303 etc but that is not in fact correct.
The variables associated with P2 are in fact #5351,#5352,#5353 etc.

These are from my own post:
https://www.machsupport.com/forum/index.php?topic=40051.0 (https://www.machsupport.com/forum/index.php?topic=40051.0)
and these values were discovered/evaluated by poppabear:

Quote
G 30 XPOS       5181
G 30 YPOS       5182
G 30 ZPOS       5183
G 30 APOS       5184
G 30 BPOS       5185
G 30 CPOS       5186
WORK SHIFT X       5201
WORK SHIFT Y       5202
WORK SHIFT Z       5203
WORK SHIFT A       5204
WORK SHIFT B       5205
WORK SHIFT C       5206
FIXTURES START       5221       // Fixture start in Parameter list
               Fixture increment is 20, Increment from fixture to fixture. G54 – G59
G 30 P2 XPOS       5351
G 30 P2 YPOS       5352
G 30 P2 ZPOS       5353
G 30 P2 APOS       5354
G 30 P2 BPOS       5355
G 30 P2 CPOS       5356
G 30 P3 XPOS       5361
G 30 P3 YPOS       5362
G 30 P3 ZPOS       5363
G 30 P3 APOS       5364
G 30 P3 BPOS       5365
G 30 P3 CPOS       5366
G 30 P4 XPOS       5371
G 30 P4 YPOS       5372
G 30 P4 ZPOS       5373
G 30 P4 APOS       5374
G 30 P4 BPOS       5375
G 30 P4 CPOS       5376

I have tested them and they are correct namely:

P1 #5181  #5182 #5183 etc
P2 #5351 #5352 #5353 etc
P3 #5361 #5362 #5363 etc
P4 #5371 #5272 #5373 etc

If anyone from NFS is reading this would they please confirm my observations and if they are found correct  then update/correct the gcode manual.

There is more to this yet. As it turns out if you do not include an axis in the G30 block then it will not move nor will it return to the required coordinate.

For example:

G90 G30 P1
will cause no movement what ever. If however you MDI:
G90 G30 P1 X50
then the machine moves to X=50 in work coordinates and then moves to the #5181 but neither of the Y or Z axes move.
I conclude that in order for G30 to work you must include all axes that you wish to move, firstly through the intermediate point in absolute work coordinates and then it will
go to the home location specified by the pound variables locations P1, P2, P3 or P4.

I have yet to do enough experimenting to decide how it works in G91 mode.

Craig
Title: Re: How does G30 work?
Post by: Graham Waterworth on January 18, 2023, 09:21:50 PM
Its a long time since I used G30 but from memory it is used with U,V & W e.g.

G21 G40 G00 G80 (start block)
G91 G28 U0 V0 W0 (got to machine home)
G30 U0 V0 W0 P1 (go to stored position)
G50 X250. Y150. Z296.185 (set datum position)
G00 X200. Y200. Z150. (go to safe position)
G50 X200. Y200. Z150. (make this the new datum)
M1

N1 T01 M6
Etc.
Title: Re: How does G30 work?
Post by: joeaverage on January 18, 2023, 09:53:16 PM
Hi Graham,
I think I've got it sorted.

It appears that G30 will move ONLY the nominated axes, that is to say the axes listed in the G30 block. The numeric component of each axis,
say X10, is the location of the intermediate point, and then the machine linearly interpolates from the intermediate location to the stored point.

If you wish for the machine to go direct to the stored point then you use a G91 mode with zero moves in each of the applicable axes. Thus:

G91 G30 P1 X0 Y0 Z0

will cause the machine to go direct from its current location to the stored point P1, with P1 being in machine coordinates.

Conversely a:

G90 G30 P1 X0 Y0 Z50

will cause the machine to rapid to X0,Y0 and Z=50mm, so 50mm above the work zero and from there linearly interpolate to the stored P1 location.

So after some experimentation I think I have got it sorted out. There is a fault in the documentation though, the # variables listed in the Gcode manual
do match those that are actually used.

Craig
Title: Re: How does G30 work?
Post by: thosj on January 19, 2023, 08:37:19 AM
I've been using this for a while with the Fusion 360 post, wonder where I got the pound variables? My guess is Chad Bird!! Somehow he/we figured it out a few years ago when working on Fusion posts:)
Title: Re: How does G30 work?
Post by: Cbyrdtopper on January 19, 2023, 10:10:11 AM
Yeah.  I asked Autodesk to add the G30 as an option for safe retracts.  They obliged. 
I went digging in some old fanuc manuals and did some testing with the Macro Variables (Pound Variables) and found the appropriate ones.  I think I had Newfangled update their manuals to match my findings; but that's been a few years.  I modified the Fusion post to allow the use for a G30P2 for a tool change position.

Use G30 like G28
G91 G30 X Y Z
G90

or 

G91 G30 P2 X Y Z
G90
Title: Re: How does G30 work?
Post by: joeaverage on January 19, 2023, 03:26:03 PM
Hi,
I've started using the Machining Extensions of Fusion and for rotary four axis tool paths the more normal Clearance Height optin in the Fusion post no longer works.
G30 is the other good option, but I've never used it before and was struggling to understand how it works. I am reasonably happy about how
it works now but still need to use it properly.

I have used the G30 option in the Fusion post, and now I understand how G30 works its doing exactly as required and as coded. Thus I can have
no complaints about the Fusion post.

I understand I can put the machine coordinates of the safe location in the P1 variables, and that would be fine for say a tool changer which never varies
however I'm trying to replicate a Clearnce Height option For this I would require the Z axis to retract say 50mm above the external diameter of the part.
The X, Y location could be just its current X,Y location......ie
G91 G30 P1  Z10 would work. My understanding is that this would leave the X,Y location unchanged, the Z axis would retract upward by 10mm and then drive to the
Z coordinate of the P1 location. This would be fine.

This is the final few lines of code of a Gcode file produced by Fusion with rotary toolpaths:

Code: [Select]
M9
G30 G91 Z0.
G90
G0 A0.
G30 G91 X0. Y0.
G90
M30

Excepting that the Z axis does not retract to an intermediate point this combination works just fine....IF.....I program P1 location properly.

My plan is to write a small macro which would populate the P1 location in # variables, and that data could be derived from the existing G54.....or whatever
work coordinate set is in use. I cannot find a way for a macro to interrogate Machs core to provide the current work coordinate set. Can anyone think of a means to do so?
I'm thinking something like:

local CurrentSet= mc.mcGet????(inst)     --CurrentSet is an integer describing the current work coordinate offsets in use, eg '54' for G54, '55' for G55 etc

The remainder of the macro would extract the work offsets from the current set, and then apply at least the X and Y offsets directly to the P1 location and the Z offset
would be augmented by some reasonable value for clearance, say 50mm, and that applied to the Z coordinate of the P1 location.

If I can achieve this then I think I could put a macro call into the Gcode file produced by Fusion and it would automatically populate the P1 location and would
require no editing of the existing Fusion code.

Thats  the theory......what is actually practical remains to be seen!

Craig
Title: Re: How does G30 work?
Post by: Cbyrdtopper on January 19, 2023, 03:37:39 PM
Craig, can you just set the #5351,#5352,and #5353 variables right from the G Code Program? 
I'm not quite sure I understand what you are asking for; if it is to get the current location for X and Y, then use the following resource.
https://www.machinetoolhelp.com/Applications/macro/system_variables.html
Look here at starting at #5021 and #5041.  These are the system variables for where the machine is currently at (machine position as well as work coordinate positoin)
Just use these to set your positions for X Y. 
You can access these from a macro or from the program you are running. 
You should be able to set the position from the program itself.... exp:  #5351 = #5021

I rarely use Mach 4's api calls for getting positions, I always find the System Variable it is stored in and I use it. 

As far as I know, I have only ever used the Machine position for G30... not the work coordinate system I'm currently in....

Are you wanting to add this to the Fusion post?
let me know what you come up with. 
Title: Re: How does G30 work?
Post by: joeaverage on January 19, 2023, 04:06:34 PM
Hi,

Quote
Craig, can you just set the #5351,#5352,and #5353 variables right from the G Code Program?

Yes, that can be done, and it would work. What I want to do is automate it. I would prefer to use the Fusion generated Gcode file without alteration,
excepting the addition of one macro call, say m450(), for instance.

The purpose of the macro is to populate the  #5351,#5352,and #5353 variables. For this I would require the machine coordinates of the work zero,
that would suffice for the X and Y axis and the Z axis zero plus 50mm say. The most convenient place to get that data is as you say the system variables,
but I'd like to be sure that I'm using the variables that correspond to the work coordinate offset set that is actually in use.

Lets imagine for instance that the machine is in G55 mode and yet my macro causes the #5351,#5352,and #5353 to be populated but from the G54 set,
that would not end well.

That's why I would like to be able to interrogate Mach's core for the current G54, G55, G56 etc.....so that the macro can select the correct data set,

Craig
Title: Re: How does G30 work?
Post by: joeaverage on January 19, 2023, 04:15:25 PM
Hi,

Quote
As far as I know, I have only ever used the Machine position for G30... not the work coordinate system I'm currently in....

When I was experimenting with G30 yesterday I found the the intermediate point is described in the current work coordinate system but the final
location is described in machine coordinates.

For instance
G90 G30 X50 Y50 Z50

will cause the machine to drive to 50,50,50 in the current work coordinate system and then drive to the final location described by P1, P2, etc in machine coords.

Or alternately
G91 G30 X50 Y50 Z50

will cause the machine to drive an additional 50mm in X, 50mm in Y and 50mm in Z from its current position and thereafter drive to its final location described by P1, P2 etc in machine coords.

Craig

Title: Re: How does G30 work?
Post by: Cbyrdtopper on January 19, 2023, 04:49:35 PM
Doing some testing just now; starting at Variable #5041, they change when I change the work coordinate system. 
I set my work offsets as G54 X, Y, and Z as 1.00, G55 all 2.00, G56 all 3.00.  It updates the #5041-#5043 appropriately. 
Check and see if you get the same results.

Also, I've never used G30 with a G90, so I had no idea that it would work with G90 nor did I know the behavior (obviously); that's pretty cool.

How are you liking the extensions?  I have little need for them.  The only one that looked interesting to me was Rotary. 
Title: Re: How does G30 work?
Post by: joeaverage on January 19, 2023, 05:00:48 PM
Hi,
I had been doing some testing also and like you I had populated the fixture table:

G54 x=1 y=1.1 z=1.2
G55 x=2 y=2.1 z=2.2
G56 x=3 y=3.1 z=3.2

And like you I found that the #5041, #5042 and #5043  reflect the current position in work coords and that they changed whenever the current (G54, G55,G56...) work
coord set changes.

So I confirm the same stuff that you have found. What it does not do is tell me which G54,G55, G56 .....is active at the current time even though #5041-#5043 reflect
the current G54,G55 etc.

Craig
Title: Re: How does G30 work?
Post by: Cbyrdtopper on January 19, 2023, 05:04:15 PM
There is a variable that tells you which work offset is active…. It is modal information. Look at #4000-#4025 or so. It may be listed as 1 for 54 and 2 for 55 etc…. Currently headed home from work so I can’t check in Mach.
Title: Re: How does G30 work?
Post by: joeaverage on January 19, 2023, 05:23:50 PM
Hi,

Quote
It is modal information. Look at #4000-#4025 or so. It may be listed as 1 for 54 and 2 for 55 etc…. Currently headed home from work so I can’t check in Mach.

Bloody magic....thanks.

Craig
Title: Re: How does G30 work?
Post by: joeaverage on January 19, 2023, 05:31:27 PM
Hi,

Quote
How are you liking the extensions?  I have little need for them.  The only one that looked interesting to me was Rotary.

Well, that's a bit of a question. Autodesk really did sort of pursue me to get me to buy the extensions. Even the introductory offer was $1900NZD ( about $1200USD)
at the time. In reality I have not used them for several months.......which is just plain stupid of me.....I've paid big dollars for extra capacity and then not used it?

I set up fourth axis with a stepper, but the stepper was inclined to stall and was pretty slow. I've just bought, taken delivery and installed a new servo for the fourth axis,
and now it performs really well. It has taken some months for me to put aside the money for the upgrade out of personal funds, and really I cannot burden the business
with this expense as I have yet to prove that it will be a money maker....yet.

Anyway the upshot is that I'm starting to use it now. That's why I've suddenly started asking questions about G30, as I need to understand it to use the Fusion post.

The first thing that I've noted is that you have to be quite considered when you CAD your part. It may make sense to have the coordinate system oriented in one direction
and fixed at a particular vertex lets say only to find that when you go to CAM the part that the coordinate orientation or vertex location introduces some mind bending
complexities. As it turns out, just like using regular 3 axis CAM Fusion can accommodate those sorts of things....but it takes some time to discover all those procedures.

All-in all I am pretty happy with what I've seen. The toolpath editing functions are something that I'm likely to use. The question remains can I either generate a business case
for renewing the subscription, especially now that the introductory offer has been used, or alternately save the money out of personal finances before the subscription renewal
middle-end of July?

Craig
Title: Re: How does G30 work?
Post by: joeaverage on January 19, 2023, 05:42:52 PM
Hi,
the answer is #4014.

With G54 active #4014=54
With G55 active #4014=55
With G56 active #4014=56    etc.

There's still some coding to do but I think now I have all the bits and pieces I need to be able to automate the clearance.

Thanks  Cbyrdtopper, as always, a pleasure to correspond.

Craig
Title: Re: How does G30 work?
Post by: Cbyrdtopper on January 19, 2023, 06:06:39 PM
Good stuff Craig! 
I couldn’t remember which variable it was nor could I remember what it output. I’ve used it a bit for making macro programs, I will probably update a couple of probing macros tomorrow with this refreshed knowledge haha.
I do a lot of 4th axis work with Fusion. I don’t use the extensions at all. I get by without them (also, I had no idea they cost that much).
You just need to be sure that you set your WCS at the center of rotation. My z and y offsets never change on my machines, just the x for part location.   So that is pretty easy.   I’ve played with rotary when it was in preview and used it a couple of times.  Pretty handy. But I’m not paying that price tag for it. I’ll get by without it.

Servos are for sure the way to go, we use steppers for applications where I don’t need to worry about high speed, but here lately, everything I need done needs to be done relatively quickly… so servos it is.  But it is a business expense fortunately for me so no personal funds for that.
Title: Re: How does G30 work?
Post by: joeaverage on January 19, 2023, 06:50:31 PM
Hi,

Quote
I’ve played with rotary when it was in preview and used it a couple of times.  Pretty handy. But I’m not paying that price tag for it. I’ll get by without it.

If I'm not mistaken you can still use four axis, indexing only, with the basic subscription.

I make parts for automotive instruments and my CNC mill is invaluable, I'd go broke for sure without the ability to make the parts I do. Some of the parts
I use, particularly for speedometer cables, are now almost impossible to source new, and even those that are available are all from overseas suppliers.
If COVID has taught us anything is that its extremely important to retain as much capability in-house, or at least locally. For this reason if I can add
four axis capability, it's not so much that there is the volume of work to make money, but rather if I  retain capability, which in turn allows me to continue
whereas I'd be watching money making jobs going begging for lack of capability.

Craig