Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: murilolana on November 08, 2012, 08:01:40 PM

Title: Tool zeroing macro help
Post by: murilolana on November 08, 2012, 08:01:40 PM
Hi everyone,

I need some help on writing a macro for zeroing the tool. I always zero the tool by the center of the work piece, so I touch one side of the piece with the tool or edge finder, then zero it, go to the other side and touch the piece again; then I divide the DRO value by 2 and that's it. same procedure for both x & y axis.
So, here's my idea: a macro that would get the DRO value, divide it by two, move the axis to this new value and zero the tool.
Can anyone help me writing this?

Thanks
Title: Re: Tool zeroing macro help
Post by: JohnHaine on March 15, 2013, 11:09:25 AM
Did you find out how to do this?  Should be very easy, I have written macros to set tool zero using a probe and it's trivial.
Title: Re: Tool zeroing macro help
Post by: murilolana on March 15, 2013, 11:38:18 AM
Did you find out how to do this?  Should be very easy, I have written macros to set tool zero using a probe and it's trivial.

Thank you John.
Hood gave me some help on this. It was a pretty simple code actually. Now I save some time on zeroing.
Title: Re: Tool zeroing macro help
Post by: JohnHaine on March 15, 2013, 12:04:41 PM
OK, glad you're sorted!
Title: Re: Tool zeroing macro help
Post by: eliasagrio on November 01, 2013, 05:47:09 PM
Hello Everyone!!!!
a newbine  here. please help with  script for Autozeroing. my touch plate is .1250 inc.  it was working fine but suddenly stop working now I can't autozero. I thanks a million in advance.
Title: Re: Tool zeroing macro help
Post by: JohnHaine on November 02, 2013, 06:18:34 AM
Can you be more specific?  What script were you using?  What are the symptoms? Can you attach the script? Have you checked the probe input is working using the diagnostics screen?
Title: Re: Tool zeroing macro help
Post by: eliasagrio on November 17, 2013, 05:30:18 PM
hey JohnHaine, thanks so much for your prompt help, I did no answer earlier because I have been too busy at work but anyway.
yes I have tested  and double checked the probe and is working fine, the pin light illuminates when touching the probe to my bit.  this is the original script I was using and the second one I have tried after the first one stop working but also without any positive outcome.
Message ( "Auto zeroing...:)
If  IsSuchSignal (22)Then
code "G31 Z-3 F20"
While IsMoving()
Wend
Call SetDRO( 2, .125)
code "G1 Z1"
End If

and the second one

PlateThickness =GetUserDRO (.125)
If GetOeled (825)<>0 Then
DoOEMButton (1010)
Code "G4 P5"
Code G31 Z-.75 F10"
While IsMoving()
Wend
ZProbePos =GetVar(2002)
Code"G0 Z" &ZProbepos
While IsMoving()
Wend
Call SetDro (.125)
Code "G4 P0. 125"
Code "G0 Z1"
Code"(Z axis is now zeroed)"
Code "(Z-Plate is grounded, check connection and try again)"


I hope that you can help with a good one.   and thanks a million in advance

good luck
Title: Re: Tool zeroing macro help
Post by: JohnHaine on November 18, 2013, 06:54:02 AM
Apart from "it doesn't work", what are the symptoms?  Does it not start when called, or does it not stop when the probe contacts?  I'm happy to send you a copy of my macro (which I know works, or did last time I used it on Saturday!) but the fact that your initial one used to work but doesn't now indicates that something has changed.
Title: Re: Tool zeroing macro help
Post by: eliasagrio on November 18, 2013, 08:20:22 AM
doesn't do anything at all but an script error appears in the status line.
as always!!!!!  thanks a million in advance
 Godspeed
Title: Re: Tool zeroing macro help
Post by: eliasagrio on November 18, 2013, 08:24:57 AM
ohhh, and also I must mention that I have taken my cnc all apart to rebuilded which is now completed however, I'am 100% sure everything was connected in the same way I originally built it meaning that all the pin #s outputs and inputs are the same as in the former cnc.

thanks and
Godspeed
Title: Re: Tool zeroing macro help
Post by: JohnHaine on November 18, 2013, 08:35:47 AM
How do you activate the script?  Is it attached to a button, or is it saved as a macro and called via an "M*********" code in the MDI?  Have you tried re-installing Mach3 (saving your xml file first with the settings), as well as rebuilding the hardware?  I will try to remember to get you a copy of my macro off my controller this evening.  Note that I have given it a macro number and it is assigned to the "Auto Tool Zero" button.
Title: Re: Tool zeroing macro help
Post by: ger21 on November 18, 2013, 09:05:46 AM
The second one is not complete, and appears to be missing quite a few lines.
There's an if statement with no "end if" and the last line is an error message that should have some other code to go with it.
Title: Re: Tool zeroing macro help
Post by: JohnHaine on November 18, 2013, 09:56:13 AM
Gerry - yes indeed!  The first one is rather skimpy too.
Title: Re: Tool zeroing macro help
Post by: eliasagrio on November 18, 2013, 01:32:31 PM
IT IS ATTACHED TO A BUTTON. THE AUTOZERO ONE
Title: Re: Tool zeroing macro help
Post by: JohnHaine on November 18, 2013, 05:02:24 PM
OK, here is my script (attached).  You will need a button script that simply calls this - something like

Code "M900"

should do it I think IIRC.  Save the macro in the "macros" folder - save it as M900 not with my extension _jh.

This macro is based on one from someone else on this forum, but I have extended it somewhat and added many comments.  It works for me, if it still doesn't work for you I suspect you must have a software config problem.

Good luck!

John
Title: Re: Tool zeroing macro help
Post by: JohnHaine on November 20, 2013, 02:33:06 AM
Couple of additional points.  I have made a setting gauge which has an electrically isolated button set at 38.84 mm  above its magnetic base.  The button connects to the probe input.  In use I pop the gauge on the table, position the tool just above the button with the button  connected, click auto tool zero, and the macro then executes, leaving the tool 50 mm above the table surface which is the Z coordinate zero I prefer.  For other touch place thicknesses and desired end points, it's fairly obvious where you modify these numbers.
Title: Re: Tool zeroing macro help
Post by: JohnHaine on November 25, 2013, 06:09:25 PM
Um, did that help?  Hello?
Title: Re: Tool zeroing macro help
Post by: eliasagrio on November 25, 2013, 11:50:58 PM
hey man!!!!!!  I really appreciate your help.  so far, I have not been able to try the las one you sent me due to my job dedication, I work on an adult community and have no help and because of the fall clean ups  most of my time is taken by that; hopefully by the winters' first weeks I will Have a chance to go back to it and I promise I'll keep you posted.


BEST REGARDS:

Elias Agredo
Title: Re: Tool zeroing macro help
Post by: JohnHaine on November 26, 2013, 01:55:11 AM
Ok, good luck, let me know how you get on.

Where are you located?
Title: Re: Tool zeroing macro help
Post by: eliasagrio on November 26, 2013, 08:19:07 AM
Jackson, Nj and yourself?
Title: Re: Tool zeroing macro help
Post by: JohnHaine on November 26, 2013, 09:49:32 AM
I thought you might be East Coast.  I'm near Cambridge, UK.
Title: Re: Tool zeroing macro help
Post by: eliasagrio on November 26, 2013, 03:41:13 PM
uhhhhhhhf
Title: Re: Tool zeroing macro help
Post by: eliasagrio on December 24, 2013, 07:53:57 PM
nope. it  did not work  bro.   any other solution?
Title: Re: Tool zeroing macro help
Post by: JohnHaine on December 25, 2013, 10:12:02 AM
Hard to say not knowing what you mean by "it did not work".  I suspect you have a software config problem.
Title: Re: Tool zeroing macro help
Post by: eliasagrio on December 25, 2013, 10:55:16 AM
well,  I copy the script to the autozero tool button and saved but when tried to use it nothing happened other than a line appearing in the status bar with "script line error "  message.
by the way      MERRY CHRISTMAS!!!!!!!
Title: Re: Tool zeroing macro help
Post by: JohnHaine on December 25, 2013, 05:13:27 PM
Try reading and executing the instructions in my previous post.  You save the macro with a changed extension Iin e macros folder and just have a short "M*********" instruction in the button script.
Title: Re: Tool zeroing macro help
Post by: Kenneth on September 22, 2014, 12:22:31 PM
not my work !
just to update this macro. there were some depreciated statements.
and i changed the z dro to 802. and set inches instead of mm.
have yet to try(waiting on electric for machine)so go slow.

'Tool Height Setting Macro - JLH v1.1 - 4 March 2013
'This version has a 2-phase approach, fast for speed & slow for precision.
CurrentAbsInc = GetOemLED (48) 'Copy current G90/G91 state
CurrentGMode = GetOemDRO (819) 'Copy current G0/G1 state
CurrentFeed = GetOemDRO (818) 'Copy current feedrate
Contact = 0 'Clear the contact flag
PlateThickness =2.178 'Touch Plate thickness is set here
ProbeFeed1 = 12 'Fast probing feedrate is set here
ProbeFeed2 = 3 'Slow probing feedrate is set here
SetVar (1, -2) 'Maximum probing distance is set here
SetVar (2, .75) 'Retract height is set here
Code "M5" 'Ensures spindle is not running
Code "G20" 'Ensure metric units are used
Zs = GetOemDRO (802) 'Copy current Z-Scale DRO
SetOEMDRO (802,1) 'Set Z-Scale DRO to 1
Sleep 2000
DoOemButton (1010) 'Zero Z-Axis DRO
Message "Setting Tool Zero" 'Message for status bar
While IsMoving () 'Wait until task has been completed
Wend
If GetOemLED (825) = 0 Then 'Check to see if touch plate is not already grounded
Code "G90 G31 Z #1 F" & ProbeFeed1 'Fast probing move
While IsMoving () 'Wait until task has been completed
Wend
If GetOemLED (825) = True Then 'Check to see if probe has touched plate
Contact = 1 'Set the contact flag
End If
DoOemButton (1003) 'Clear a possible feed-hold condition
ProbePos = GetVar (2002) 'Exact point probe touched
ProbePos = ProbePos + .25 'Displace probe position upwards by .25mm
Code "G0 Z" & ProbePos 'Lifts probe .25mm above fast feed endpoint
While IsMoving () 'Wait until task has been completed
Wend
Code "G90 G31 Z #1 F" & ProbeFeed2 'Slow probing move
While IsMoving () 'Wait until task has been completed
Wend
If GetOemLED (825) = True Then 'Check to see if probe has touched plate
Contact = 1 'Set the contact flag
End If
ProbePos = GetVar (2002) 'Exact point probe touched
Code "G0 Z" & ProbePos 'Lifts probe to exact touch position
While IsMoving () 'Wait until task has been completed
Wend
SetOEMDRO (802,PlateThickness) 'Set Z-Axis DRO to Touch Plate thickness
Code "G0 Z #2" 'Retract off Touch Plate to the set height
While IsMoving () 'Wait until task has been completed
Wend
Message "Z-Axis is now Zeroed." 'Message for status bar
Code "F" & CurrentFeed 'Restore feedrate to original setting
If Contact = 0 Then 'Probe reached max travel without touching
Message "ERROR - Probe did not touch." 'Message for status bar
Response = MsgBox ("ERROR - Probe did not touch.",37,"Auto Tool Zero")
End If
Else
Message "ERROR - Touch Plate is grounded." 'Message for status bar
Response = MsgBox ("ERROR - Touch Plate is grounded - Check connection.",16,"Auto Tool Zero")
End If
SetOemDRO (802,Zs) 'Restore Z-Scale DRO to original setting
If CurrentAbsInc = 0 Then 'If G91 was in effect before then return to it
Code "G90"
End If
If CurrentGMode = 0 Then 'If G0 was in effect before then return to it
Code "G00"
End If  
      
Title: Re: Tool zeroing macro help
Post by: JohnHaine on September 22, 2014, 03:36:20 PM
Kenneth,  thanks for this - the first time someone has picked up my code and modified it further!  I hope it works for you. 

John.
Title: Re: Tool zeroing macro help
Post by: Kenneth on September 23, 2014, 05:34:31 AM
Thank YOU John for sharing this macro. should have used your name for credit.
right now i can only use it in sim.
you've put a lot of work into it. Thanks again !
Title: Re: Tool zeroing macro help
Post by: dude1 on September 23, 2014, 05:49:59 AM
you need to add retract to it
Title: Re: Tool zeroing macro help
Post by: Kenneth on September 23, 2014, 06:25:35 AM
isn't this the retract ?
but i don't understand the #2. is that SetVar(2 , .75) set at start?

SetOEMDRO (802,PlateThickness) 'Set Z-Axis DRO to Touch Plate thickness
Code "G0 Z #2" 'Retract off Touch Plate to the set height     <-------------------
While IsMoving () 'Wait until task has been completed
Wend
Title: Re: Tool zeroing macro help
Post by: dude1 on September 23, 2014, 06:34:03 AM
I use to use a code without a retract it always had problems.

i use one that includes a retract distance I have been using it for 3 years never had a problem.

I will find it a post it
Title: Re: Tool zeroing macro help
Post by: dude1 on September 23, 2014, 06:40:26 AM
Code: [Select]
this is the code I use



[codeRem Auto Tool Zero Z- Metric Version

DownStroke = -25 'Set the down stroke to find probe
DownFeedRate = 100 'Set the down FeedRate
RetractStroke = 10 'Set the retract Stroke
RetractFeedRate = 300 'Set the retract FeedRate

CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state
CurrentGmode = GetOemDRO(819) 'Get the current G0/G1 state
PlateThickness = GetUserDRO(1151) 'Z-plate thickness DRO

If GetOemLed (825)=0 Then 'Check to see if the probe is already grounded or faulty
DoOEMButton (1010) 'zero the Z axis so the probe move will start from here
Code "G4 P2" ' this delay gives me time to get from computer to hold probe in place
Code "G90 G31 Z" &DownStroke &" F" &DownFeedRate 'probing move
While IsMoving() 'wait while it happens
Wend
ZProbePos = GetVar(2002) 'get the axact point the probe was hit
If Abs(ZprobePos) <= Abs(DownStroke)-0.1 Then 'Check if the probe has been found
Code "G0 Z" &ZProbePos 'go back to that point, always a very small amount of overrun
While IsMoving ()
Wend
Call SetDro (2, PlateThickness) 'set the Z axis DRO to whatever is set as plate thickness
Code "G4 P0.25" 'Pause for Dro to update.
Code "G1 Z" &PlateThickness + RetractStroke &" F" &RetractFeedRate 'retract
While IsMoving ()
Wend
Code "(Z axis is now zeroed)" 'puts this message in the status bar
Else
Code "G0 Z0" 'retract to start pos
While IsMoving ()
Wend
Code "(Z-Plate not found, check connection or stroke and try again)" 'puts this message in the status bar
End If
Else
Code "(Z-Plate is grounded, check connection and try again)" 'this goes in the status bar if aplicable
End If
Code "F" &CurrentFeed 'Returns to prior feed rate
If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
End If
If CurrentGMode = 0 Then 'if G0 was in effect before then return to it
Code "G0"
End If
Exit Sub ]
Title: Re: Tool zeroing macro help
Post by: Kenneth on September 23, 2014, 06:52:07 AM
Thanks Daniel, i'll try both when i get my electricity :)
Title: Re: Tool zeroing macro help
Post by: Kenneth on September 23, 2014, 07:42:23 AM
Daniel, what's the UserDRO(1151) ? is this where i set probe height ?
Thanks
Title: Re: Tool zeroing macro help
Post by: dude1 on September 23, 2014, 04:59:20 PM
yep the code was from a screen someone else made I just got a copy of it. the blue probing screen I use has that dro number if you don't have that dro you will need to add it
Title: Re: Tool zeroing macro help
Post by: Kenneth on September 24, 2014, 05:42:46 AM
John, what's the SetVar 1 and 2 ? can't see where they are used.
and in sim mode, it goes pass the max distant without warning.
maybe it needs a signal to work :)
Thanks

SetVar (1, -1) 'Maximum probing distance is set here
SetVar (2, .75) 'Retract height is set here
Title: Re: Tool zeroing macro help
Post by: dude1 on September 24, 2014, 06:33:31 AM

SetVar (1, -1) 'Maximum probing distance is set here
SetVar (2, .75) 'Retract height is set here

first one how far to go down
second one how far to go back up
Title: Re: Tool zeroing macro help
Post by: Kenneth on September 24, 2014, 06:47:08 AM
Thanks Daniel,
i know WHAT they are, but don't see WHERE they're used.
Title: Re: Tool zeroing macro help
Post by: dude1 on September 24, 2014, 06:52:08 AM
you would have to look up what SetVar 1 and 2 is in the vb script manual
Title: Re: Tool zeroing macro help
Post by: Kenneth on September 24, 2014, 06:56:04 AM
i'm sorry, i'm not being clear.
i know they're variables, but can't see where they are used IN his script.
Thanks
Title: Re: Tool zeroing macro help
Post by: dude1 on September 24, 2014, 06:58:14 AM
I dont know ever
Title: Re: Tool zeroing macro help
Post by: stirling on September 24, 2014, 07:35:29 AM
#1 and #2