Hello Guest it is March 28, 2024, 05:58:55 PM

Author Topic: Gcode to zero Z axis during run  (Read 11283 times)

0 Members and 1 Guest are viewing this topic.

Gcode to zero Z axis during run
« on: April 13, 2014, 02:11:26 PM »
I may be over complicating this; I think what I want to do is to zero my Z axis in code...

I have code that moves my Z axis until a moveable limit switch is tripped (G00 Z40000; ie a figure so large that it ensures the switch will always be tripped at some point.) When this happens, I want the machine to treat this position as Z0, until the end of the file. All other axes will remain as they are. At the end of the file, the next file will be called and run automatically from within the current file, and so a new Z0 position will need to be found... (at least that's what I intend.)

I looked through a post from 2007 entitled 'Gcode to re-zero Z axis', which appears to be about the same kind of thing.

Poppabear suggested a user defined DRO, which passes a value to a macro:-

'G90 G17
G28.1
M700
(the rest of code here)

Here is the Macro:

'M700.m1s  'metal thickness offset macro

z=GetUserDro(1100)     'get the value of your metal thickness from the dro.
Code "G0 Z" & z        'This moves to the new Z position that you put in the dro.
While IsMoving
WEnd'


I may be misunderstanding what the OP wanted; but I think in order to do what I want, I would need to rewrite as:-

G90 G17
G28.1     'only Z would be enabled for this in my soft limits config?
M700
(the rest of code here)

'M700.m1s

z = GetUserDro(1100) 'get value from my DRO
Code "G52 Z" & z
WhileIsMoving
WEnd

Am I right in thinking that this would move my Z axis until the switch trips, then Z stops moving, and mach sets the current Z position as Z0?
Or is there a function in mach that does that anyway? Can't test this for a few days now, which bugs me.
Re: Gcode to zero Z axis during run
« Reply #1 on: April 13, 2014, 02:33:41 PM »
Can you not just use work Offsets to deal with the different thickness, or are you feeding random work thicknesses in for the same job?
Re: Gcode to zero Z axis during run
« Reply #2 on: April 13, 2014, 03:46:07 PM »
My setup isnt a milling machine, its a plotter. Part of its operation is an extruder pump driven by the Z drive. It picks up a syringe of paint, (which may have a plunger height of 1/4 inch to 3 inches), it then advances the Z drive until it trips the pressure switch (wired as a limit switch currently) that tells it to stop advancing because it's made contact with the back of the plunger. As all plungers are a different height, I need to zero Z 'on the fly' so to speak, as the main code always starts from Z0. At the moment, I just zero it myself at the keyboard, but it needs to happen without my intervention.

So I'm not really sure what offsets are in this context;- I kind of thought that was what I was doing. I may be wrong, probably am...
« Last Edit: April 13, 2014, 03:48:08 PM by moorea21 »

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Gcode to zero Z axis during run
« Reply #3 on: April 13, 2014, 03:57:01 PM »

G28.1 Z3.000
G92 Z0.000

That should do it but it assumes that the Z homes towards the plunger. It will move OUT to Z3.250 (max plunger height 3 +  .250 " Clearance) Then home towards the plunger until it trips THEN resets Z to Zero.

Re: Gcode to zero Z axis during run
« Reply #4 on: April 13, 2014, 04:31:08 PM »
Thanks BR549.

My code should withdraw the Z (plunger driver) fully at the end of the previous file, and set Z to zero there, so I don't need to withdraw at this stage in the code.

Can I just use the second line on its own to achieve the zeroing? Or use my original exaggerated move , as below? And yes, Z homes towards the plunger.

G28.1 Z40000    'ensures pressure switch wired as Z home trips regardless of length of plunger
G92 Z0.000       'sets Z to zero from its current value
« Last Edit: April 13, 2014, 04:43:31 PM by moorea21 »

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Gcode to zero Z axis during run
« Reply #5 on: April 13, 2014, 04:54:36 PM »
You can use the G92 to reset the Z to any value you wish anytime you wish.

IF you have reset the Z before this routine then use

G28.1 Z0.000
G92

Remember with the G28.1 command the Z call is the goto position BEFORE it starts the home routine. It does NOT limit the total travel of Z as it homes.

IF you need a saftey there then consider using the G31 routine. It will travel until it trips OR runs out of travel as defined by the call.

G31 Z 4.000  (moves to trip OR end of travel)
G92 Z0.000   (Reset Z to Zero or value of overtravel of the switch)

It will move in the direction of travel UNTIL it trips OR it gets to Z4.000 then it stops.  Then it resets the Z to Zero

(;-) TP
Re: Gcode to zero Z axis during run
« Reply #6 on: April 13, 2014, 05:01:52 PM »
I think that's clear, G31 sounds like it does what I need done. I'll re read this again tomorrow, along with relevant bits of the manual, and make sure I know what to expect before I run this. Thanks again.
Re: Gcode to zero Z axis during run
« Reply #7 on: April 14, 2014, 01:12:41 PM »
Okay, it makes sense, apart from the fact that I can't see a way (in the manual) of getting mach to ignore the fact that the Z home switch will be permanently tripped for the rest of the file. This is necessary, as the switch remains depressed by the pushing action of the Z axis during printing. I achieve this manually at the moment, and I could ( I suppose) send the switches signal through external logic that tells it to do the same thing automatically, but is there a way mach could do this on it's own?

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Gcode to zero Z axis during run
« Reply #8 on: April 14, 2014, 02:11:56 PM »
If it's only defined as a Home switch, then mach3 will ignore it at all times except when homing.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: Gcode to zero Z axis during run
« Reply #9 on: April 14, 2014, 02:25:21 PM »
That's good news! No complicated hacks needed.
Thanks Gerry.

So I can use G28.1 or G31?
« Last Edit: April 14, 2014, 02:27:01 PM by moorea21 »