Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: jelle_bos on June 19, 2019, 09:01:23 AM

Title: Changing G54 inside script
Post by: jelle_bos on June 19, 2019, 09:01:23 AM
Hello, I am retrofitting an machine with multiple tools on the head with mach4. The machine has an head which is mounted to a Z axis. I need to give an offset to each tool on the head. I think the best way is to change the G54 according to the position on the tool on the head. We use g54 standard because our work origin is fixed on the table but it is not directly under the machine zero.  So let's say our x in G54 is 150mm and the tool on the head is -50 in relation to the primairy tool. So I would make the G54 x coordinate 200mm.

Is this possible to do it this way within a script. Or does someone have a better idea on how to achieve the correct x an y offset when a different tool is selected?

Thanks in advance.

Jelle

Title: Re: Changing G54 inside script
Post by: MN300 on June 19, 2019, 10:02:34 AM
Mach4 has 106 fixture offsets, including G54.1 P1 ... G54.1 P100. Your tool change script could change the trailing number in G54.1 Pxx to match the new tool number and select a different fixture offset for each tool.
Title: Re: Changing G54 inside script
Post by: jelle_bos on June 19, 2019, 10:40:48 AM
Mach4 has 106 fixture offsets, including G54.1 P1 ... G54.1 P100. Your tool change script could change the trailing number in G54.1 Pxx to match the new tool number and select a different fixture offset for each tool.

Thanks for the reply I did not see that I think that will be a great solution. To be fair I am not very good in the lua scripting. Do you know how to change these g54.1 pxx to the correct one per tool. I  want to use an if statement which reads the tool and set some parameters for different tools. But how do I say that the machine needs to use an certain g54?

Thanks in advance
Title: Re: Changing G54 inside script
Post by: Chaoticone on June 19, 2019, 11:14:15 AM
Why not just use the X and/or Y offset for each tool? View, tool table, edit, table fields, optional fields.
Title: Re: Changing G54 inside script
Post by: jelle_bos on June 19, 2019, 11:19:51 AM
Why not just use the X and/or Y offset for each tool? View, tool table, edit, table fields, optional fields.

I used that feature. But when try a test code which mills an pocket the head goes down on the original location where the mill would plunge inside the workpiece. After that it slowly moves to the changed ''new'' pocket location.  The feature works for the offsets but has te problem I described.

Maybe you know a way to solve this?
Title: Re: Changing G54 inside script
Post by: MN300 on June 19, 2019, 11:31:56 AM
Your M6 tool change script should already have lines like this,

local inst = mc.mcGetInstance()
local selectedtool = mc.mcToolGetSelected(inst)

Add this at the end to select a tool fixture to match the tool number.

mc.mcCntlGcodeExecuteWait(inst, " G54.1 P" .. tostring(selectedtool))
Title: Re: Changing G54 inside script
Post by: MN300 on June 19, 2019, 11:47:25 AM
Chaoticone's solution does sound easier.

If your change script automatically probes to check the tool length, the X and Y offsets would have to be changed before probing.
Title: Re: Changing G54 inside script
Post by: Chaoticone on June 19, 2019, 12:07:05 PM
Did you set the offset using G43 H(Tool number)?
Title: Re: Changing G54 inside script
Post by: jelle_bos on June 19, 2019, 12:39:56 PM
Did you set the offset using G43 H(Tool number)?

Yes it uses g43 H2 . It does work the offset.  I am using fusion 360 to make the gcode. But when I run the program with x and y offset the tool goes to the workpiece surface fast. and then you can see the position of the pocket change in the toolpath window inside mach4. Then the tool moves to the ''new'' position of the pocket ,which correspondence with the offsets of the tool, with the feedrate for cutting(which is much slower then the normal moving speed above the workpiece) So how can I get mach4 to move quickly above the surface to the ''new'' pocket location without going to the ''old'' location first? Did you have the same problem with the offsets?
Title: Re: Changing G54 inside script
Post by: Chaoticone on June 19, 2019, 01:30:07 PM
It sounds like it is doing exactly what the Gcode is telling it to do. Have you verified that? If not, you need to. Put it in single block and execute one line at the time. Read the line, understand what it is telling the machine to do, watch the machine. If the machine does something contrary to what the Gcode is telling it to do, tell us what that is.
Title: Re: Changing G54 inside script
Post by: jelle_bos on June 19, 2019, 04:51:28 PM
Thanks for the help. I think that is indeed the case. The gcode firsts sends the head down after which it tells the machine to use the tool#2 offsets. I think that when I switch those lines that the machine will work correctly. I will try it as soon as possible. Thanks again, will keep you updated.
Title: Re: Changing G54 inside script
Post by: KatzYaakov on June 19, 2019, 06:17:53 PM
hi jelle ,i did it with G52
ach time i need drill i have the G52 in the script ,but you must not forget reset it when finish the script
good luck
Title: Re: Changing G54 inside script
Post by: Graham Waterworth on June 19, 2019, 06:21:08 PM
If I am understanding your problem right you need to offset the x axis depending on which tool you use.

why not set up a sub routines for each tool with a G52 x-50 or what ever you need the offset to be and another sub with G52 x0 in it to call to cancel that offset. You can also set the Y and Z for each tool this way.

All the subs could be coded into your cad system or stored in Machs subs folder.

So your code would look along these lines
%
M98 P251(CALL TOOL 1)
G00 X150 Y20.
G01 ETC.
M98 P250 (CANCEL OFFSET)

M98 P252 (CALL TOOL 2)
ETC.
M98 P250 (CANCEL TOOLS)
ETC.
M30

Subs would be
O250
T0 M6
G52 X0
M99

O251
T1 M6
G52 X-50.
M99

O252
T2 M6
G52 X-100.
M99
%

Title: Re: Changing G54 inside script
Post by: jelle_bos on June 20, 2019, 04:39:40 PM
Hello, I tested the program when I changed the order of the mill going to the pocket location and the tool g43 offest to use. Indeed the machine works great with the x and y offset in the tool table. Like Chaoticone suggested

I tried it with different tools and added the x an y offsets in the tool table. It works great with all the tools. The only problem I have now is that fusion 360 always puts the location of the milling feature before the g43 offset.
I am not very experienced in gcode writing and reading. So does anyone know how to change the order fusion 360 puts out the code? If possible at all?

Otherwise I need to change the order of the code manually for every gcode I make.

Thanks in advance
Title: Re: Changing G54 inside script
Post by: KatzYaakov on June 20, 2019, 07:42:35 PM
jelle i think you waste time with try use with tool table
dont forget you have many other cycle to run ,not only move axis
run the motor,drill head down,bit drill down(in many case need more then 1 )
if horizontal need also add more
so i think you batter think about M function with G52 inside
similier as Garham suggest
yaakov
Title: Re: Changing G54 inside script
Post by: KatzYaakov on June 20, 2019, 07:43:53 PM
i forget also you need look for sensors like horizontal driil up,or drill head up
Title: Re: Changing G54 inside script
Post by: Chaoticone on June 20, 2019, 10:40:15 PM
Hello, I tested the program when I changed the order of the mill going to the pocket location and the tool g43 offest to use. Indeed the machine works great with the x and y offset in the tool table. Like Chaoticone suggested

I tried it with different tools and added the x an y offsets in the tool table. It works great with all the tools. The only problem I have now is that fusion 360 always puts the location of the milling feature before the g43 offset.
I am not very experienced in gcode writing and reading. So does anyone know how to change the order fusion 360 puts out the code? If possible at all?

Otherwise I need to change the order of the code manually for every gcode I make.

Thanks in advance

Sounds like you could tweak your Post processor and get the Gcode output as you want it. Maybe there is a different post processor already that will do what you want? Have you asked Autocad? Fusion support? I would think they have a forum too but I could be wrong. Most post processors are editable but I have never messed with fusion or any CAM used with it much at all.

Code: [Select]
I am not very experienced in gcode writing and reading.
No, I'm not great myself. CAM makes it easy to skip that step but if you are going to run the machine much, do yourself a favor and learn some of it. The best way I can put it is folks using CAM software with no knowledge of Gcode would be the same as someone using a calculator with no knowledge of math. So, learn the basics at least. If you need the equivalent of a scientific calculator in Gcode, you can do that too. Gcode is pretty powerful and the only language your machine understands. If you can't speak some Gcode it would be like going to a foreign land and hiring folks to build you a house that you can't talk to. The machine (if built right) is a very reliable helper that will do exactly what you tell it to every time. Take advantage of that. I keep Peter Smids CNC Programming Handbook at arms reach for reference. I don't try to remember it all. If I can just remember where I put that book I impress myself  :D and in pretty good shape. You might like this link.

http://eng-serve.com/cnc/gcode_comment.html
Title: Re: Changing G54 inside script
Post by: KatzYaakov on June 21, 2019, 03:33:30 AM
chaoticone
jelle machine is not typical cnc to engraving
its cal PTP and its use in furniture industry
and gcode much more complicate ,also have many I/O need control while run
program mostly come as close file that we have label on part .scan the barcode and run
and second option its by parametric programs that just change parts size and all machining change according
there also issiue there about right side and left side(mirror) so i think your
suggest its just in time
and its will be very hard to write gcode by hand
must have some cad cam
Title: Re: Changing G54 inside script
Post by: Hayley664 on June 22, 2019, 04:33:14 AM
Your tool change script could change the trailing number in G54.1 Pxx to match the new tool number and select a different fixture offset for each tool.
Title: Re: Changing G54 inside script
Post by: KatzYaakov on June 23, 2019, 01:32:21 PM
Hayley664
its not good solution for his specific machine
because he must have at least 2 "homes" right and left(most have 4 ,but 2 its must)
so he cant block his homes acording tool number
i think only solution for him its G52
and create m function ,and inside make the table with offset per drill bit