Hello Guest it is March 28, 2024, 01:29:16 PM

Author Topic: Mach3, G31 probe on Z axis, and variable 2002  (Read 6649 times)

0 Members and 1 Guest are viewing this topic.

Mach3, G31 probe on Z axis, and variable 2002
« on: April 24, 2020, 07:04:39 PM »
I am new to Mach3, but a programmer in multiple languages, PLCs and motion control systems for many years.  I'm trying to help a friend set up a new (Chinese) CNC Router.  I'm working on a macro in Mach3 to do a simple probe to find the tool length.  When I run g31 with the current position minus one inch, it works fine, it stops (but does not retract any which the specification says it should), and variable 2002 (using GetVar(2002) ) always returns the part offset.  In other words, if G54 is active, with -12.4 in the Z offset, then GetVar(2002) returns 12.4 (positive value of the negative offset.  If I use no offset (offset of 0.0) GetVar(2002) returns 0.0.

What is going on here?
Any machine is a smoke machine if used wrong enough,
Re: Mach3, G31 probe on Z axis, and variable 2002
« Reply #1 on: April 24, 2020, 11:40:28 PM »
Hi,

Quote
When I run g31 with the current position minus one inch, it works fine, it stops (but does not retract any which the specification says it should),

Thats not my understanding.

Quote
The machine will move toward the specified end point, at the same time it is looking for the probe input to be activated. When the probe input is activated the current position is recorded to # variables according to the table below and motion is stopped. The recorded position can then be used to calculate tool offsets, work offsets, measure parts, etc.

It does not say anything about retracting. When you have a probing routine it takes two Gcode instructions, a G31 which
does the probe move per the description above followed by a G0 which retracts the Z axis.

Craig
« Last Edit: April 24, 2020, 11:44:17 PM by joeaverage »
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach3, G31 probe on Z axis, and variable 2002
« Reply #2 on: April 25, 2020, 01:32:32 AM »
Hi,

Quote
When I run g31 with the current position minus one inch, it works fine, it stops (but does not retract any which the specification says it should),

Thats not my understanding.

Quote
The machine will move toward the specified end point, at the same time it is looking for the probe input to be activated. When the probe input is activated the current position is recorded to # variables according to the table below and motion is stopped. The recorded position can then be used to calculate tool offsets, work offsets, measure parts, etc.

It does not say anything about retracting. When you have a probing routine it takes two Gcode instructions, a G31 which
does the probe move per the description above followed by a G0 which retracts the Z axis.

Craig

I think you are missing the point:  First off, I mentioned it only as a side note, but the documentation that came with Mach3, I believe quoted from the NIST standard but also notated by Artsoft, states:
"In response to this command, the machine moves the controlled point (which should be at the
end of the probe tip) in a straight line at the current feed rate toward the programmed point.
If the probe trips, then the probe is retracted slightly from the trip point at the end of command
execution."

My understanding from reading that was that it tries to compensate for overtravel, but again that is a side note.  I of course also do a move afterwards to reposition the probe out of the way when done probing.

The point that you seem to have missed is this, again from the documentation on G31:
"After successful probing, parameters 2000 to 2005 will be set to the coordinates of the location
of the controlled point at the time the probe tripped..."

And in fact several examples of other people's code for probing I have found online use something like:
Code "G90 F4 G31 Z-1.0"
somevar = GetVar(2002)

All the code I saw used the value in 2002, either as #2002 or GetVar(2002) to calculate the trip position, either to set the height of the work piece, or as in my case, to measure the tool length.  But all I get is the current Z work offset set by G54, G55 etc.

That is where I am confused.  I ended up writing a manual routine after the G31 to backoff the Z axis until it is de-asserted, then go in at a very slow feed until it is re-asserted.  For some reason, after backing off the probe, I could not get G31 to work at a very slow feed, (F0.5 or F1.0) so I did it myself in several loops of code. 

So I have working code, but I would like to know why 2002 is not the value I think it should be. 
Any machine is a smoke machine if used wrong enough,

Offline ZASto

*
  •  423 423
    • View Profile
Re: Mach3, G31 probe on Z axis, and variable 2002
« Reply #3 on: April 25, 2020, 04:43:24 AM »
Analyze this code to figure out how touchoff is working.
It does NOT retract automatically after contact.

Code: [Select]
Sub Main() 'made it a sub, so you can return on "show stopper" errors
'Option Explicit 'Written by Big-Tex Dec 26 2010 Updated Jun 3 2014
'Mod pb 11dec10

Dim ZNew, Zplate, Zrestposition, ZMaterialmachcoord, ZPlatejobcoord, Zplatetomaterial
Dim xjobcoord, yjobcoord, xmachcoord, ymachcoord, zmachcoord
Dim xprobeloc, yprobeloc, xtoprobe, ytoprobe, PlateOffset
Dim CurrentFeed, Zretract
Dim CurrentAbsInc

xjobcoord = GetDRO(0) 'get current job coordinate for X
yjobcoord = GetDRO(1) 'get current job coordinate for Y
xmachcoord = GetOemDRO(83) 'get current machine coordinate for X
ymachcoord = GetOemDRO(84) 'get current machine coordinate for Y
zmachcoord = GetOemDRO(85) 'get current machine coordinate for Z
xprobeloc = GetUserDRO(1100) 'get X machine coordinate location of the touch plate
yprobeloc = GetUserDRO(1101) 'get Y machine coordinate location of the touch plate
xtoprobe = (xprobeloc - xmachcoord + xjobcoord) 'calculate the X move from the current location to the touch plate
ytoprobe = (yprobeloc - ymachcoord + yjobcoord) 'calculate the Y move from the current location to the touch plate
PlateOffset = GetUserDRO(1151) 'get plate offset DRO
CurrentFeed = GetOemDRO(818) 'get the current feedrate to return to later
Zretract = GetOemDRO(1202) 'get Z tool change location
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state

'//////// the block below will set all your reusable vars depending on Inch or mm.
'//////// this sets the vars so you only need ONE large block of probing code.

If GetOEMLED(801) Then 'ON = English Measure INCH
FirstProbeDist = 6.0 'first probe travel
FirstRetractDist = 0.1 'first probe retract travel
SecProbeDist = 0.25 'second probe travel
FirstProbeFeed = 10 'First Probe Feed Speed
SecondProbeFeed = 2 'Second Probe Feed Speed
Else 'OFF = Metric Measure MM
FirstProbeDist = 150.0 'first probe travel
FirstRetractDist = 3.0 'first probe retract travel
SecProbeDist = 6.0 'second probe travel
FirstProbeFeed = 300 'First Probe Feed Speed
SecondProbeFeed = 50 'Second Probe Feed Speed
End If

'//////// Error Condition checking code

If GetOemLED(16)<>0 Then 'Checks for machine coordinates
Code "(Please change to working coordinates)"
Exit Sub 'ERROR! exit the macro
End If

If GetOemLED(825)<>0 Then
Code "(Z-Plate Grounded Check connection and try again)"
Exit Sub 'ERROR! exit the macro
End If

'//////// Start Probing Code, Probe In -Z direction.MOVABLE PROBE PLATE
'//////// The vars will be Inch or Metric from above if/else statment

sleep(1000) 'pause 1 seconds to give time to position probe plate
Code "F" & FirstProbeFeed 'slow down feedrate to 10 ipm
ZNew = ( GetDro(2) - FirstProbeDist ) 'probe move to current z - 6 inches
Code "G90 G31Z" & ZNew
While IsMoving() 'wait for probe move to finish
Wend
ZNew = GetVar(2002) 'read the touch point
Code "G0 Z" & ( ZNew + FirstRetractDist ) 'move back to hit point incase there was overshoot +.1
While IsMoving ()
Wend
Code "F" & SecondProbeFeed 'slow down feedrate to 2 ipm
ZNew = ( GetDro(2) - SecProbeDist ) 'probe move to current z - .25 inches
Code "G90 G31Z" & ZNew
While IsMoving() 'wait for probe move to finish
Wend
ZNew = GetVar(2002) 'read the touch point
Code "G0 Z" & ZNew 'move back to hit point incase there was overshoot
While IsMoving ()
Wend
Call SetDro (2, PlateOffset) 'set the Z axis DRO to plate thickness
sleep(250) 'pause for Dro to update.
Code "G53 G0 Z" & Zretract
While IsMoving ()
Wend
Code "F" & CurrentFeed 'returns to prior feed rate

'//////// End Probing Code,

If GetOEMLED(801) Then 'ON = English Measure INCH
Code "(Z axis is now zeroed in English Units)" 'puts this message in the status bar
Else 'OFF = Metric Measure MM
Code "(Z axis is now zeroed in Metric Units)" 'puts this message in the status bar
End If

If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
End If

Make no mistake between my personality and my attitude.
My personality is who I am.
My attitude depends on who you are.

Offline Graham Waterworth

*
  • *
  •  2,668 2,668
  • Yorkshire Dales, England
    • View Profile
Re: Mach3, G31 probe on Z axis, and variable 2002
« Reply #4 on: April 25, 2020, 07:24:45 AM »
Do you have a length offset active, if so that will be included in the #2002 value you could do a G49 before you do the G31 G91 Z-1. move
Without engineers the world stops
Re: Mach3, G31 probe on Z axis, and variable 2002
« Reply #5 on: April 25, 2020, 05:13:03 PM »
Analyze this code to figure out how touchoff is working.
It does NOT retract automatically after contact.

Code: [Select]
Sub Main() 'made it a sub, so you can return on "show stopper" errors
'Option Explicit 'Written by Big-Tex Dec 26 2010 Updated Jun 3 2014
'Mod pb 11dec10

Dim ZNew, Zplate, Zrestposition, ZMaterialmachcoord, ZPlatejobcoord, Zplatetomaterial
Dim xjobcoord, yjobcoord, xmachcoord, ymachcoord, zmachcoord
Dim xprobeloc, yprobeloc, xtoprobe, ytoprobe, PlateOffset
Dim CurrentFeed, Zretract
Dim CurrentAbsInc

xjobcoord = GetDRO(0) 'get current job coordinate for X
yjobcoord = GetDRO(1) 'get current job coordinate for Y
xmachcoord = GetOemDRO(83) 'get current machine coordinate for X
ymachcoord = GetOemDRO(84) 'get current machine coordinate for Y
zmachcoord = GetOemDRO(85) 'get current machine coordinate for Z
xprobeloc = GetUserDRO(1100) 'get X machine coordinate location of the touch plate
yprobeloc = GetUserDRO(1101) 'get Y machine coordinate location of the touch plate
xtoprobe = (xprobeloc - xmachcoord + xjobcoord) 'calculate the X move from the current location to the touch plate
ytoprobe = (yprobeloc - ymachcoord + yjobcoord) 'calculate the Y move from the current location to the touch plate
PlateOffset = GetUserDRO(1151) 'get plate offset DRO
CurrentFeed = GetOemDRO(818) 'get the current feedrate to return to later
Zretract = GetOemDRO(1202) 'get Z tool change location
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state

'//////// the block below will set all your reusable vars depending on Inch or mm.
'//////// this sets the vars so you only need ONE large block of probing code.

If GetOEMLED(801) Then 'ON = English Measure INCH
FirstProbeDist = 6.0 'first probe travel
FirstRetractDist = 0.1 'first probe retract travel
SecProbeDist = 0.25 'second probe travel
FirstProbeFeed = 10 'First Probe Feed Speed
SecondProbeFeed = 2 'Second Probe Feed Speed
Else 'OFF = Metric Measure MM
FirstProbeDist = 150.0 'first probe travel
FirstRetractDist = 3.0 'first probe retract travel
SecProbeDist = 6.0 'second probe travel
FirstProbeFeed = 300 'First Probe Feed Speed
SecondProbeFeed = 50 'Second Probe Feed Speed
End If

'//////// Error Condition checking code

If GetOemLED(16)<>0 Then 'Checks for machine coordinates
Code "(Please change to working coordinates)"
Exit Sub 'ERROR! exit the macro
End If

If GetOemLED(825)<>0 Then
Code "(Z-Plate Grounded Check connection and try again)"
Exit Sub 'ERROR! exit the macro
End If

'//////// Start Probing Code, Probe In -Z direction.MOVABLE PROBE PLATE
'//////// The vars will be Inch or Metric from above if/else statment

sleep(1000) 'pause 1 seconds to give time to position probe plate
Code "F" & FirstProbeFeed 'slow down feedrate to 10 ipm
ZNew = ( GetDro(2) - FirstProbeDist ) 'probe move to current z - 6 inches
Code "G90 G31Z" & ZNew
While IsMoving() 'wait for probe move to finish
Wend
ZNew = GetVar(2002) 'read the touch point
Code "G0 Z" & ( ZNew + FirstRetractDist ) 'move back to hit point incase there was overshoot +.1
While IsMoving ()
Wend
Code "F" & SecondProbeFeed 'slow down feedrate to 2 ipm
ZNew = ( GetDro(2) - SecProbeDist ) 'probe move to current z - .25 inches
Code "G90 G31Z" & ZNew
While IsMoving() 'wait for probe move to finish
Wend
ZNew = GetVar(2002) 'read the touch point
Code "G0 Z" & ZNew 'move back to hit point incase there was overshoot
While IsMoving ()
Wend
Call SetDro (2, PlateOffset) 'set the Z axis DRO to plate thickness
sleep(250) 'pause for Dro to update.
Code "G53 G0 Z" & Zretract
While IsMoving ()
Wend
Code "F" & CurrentFeed 'returns to prior feed rate

'//////// End Probing Code,

If GetOEMLED(801) Then 'ON = English Measure INCH
Code "(Z axis is now zeroed in English Units)" 'puts this message in the status bar
Else 'OFF = Metric Measure MM
Code "(Z axis is now zeroed in Metric Units)" 'puts this message in the status bar
End If

If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
End If


Nicely written code, and I thought I was being careful about dim'ing everything and testing everything before and during the routine!  Good ideas here, I will be learning from this.

I see you using, as I have seen others do, the form
Code "(yada yada yada)"
which I found did not work I had to use
Message "(yada yada yada)"
although I see no mention of it in the documentation, is the parenthesis surrounding the text what makes it print to the message line?  I can't test for a few days until I'm back at the machine.

This is not unlike what I did for my first tries, but when I did the G31, GetVar(2002) always returned the current Z axis part offset, I never got that to work right.  Also, the docs say that it is an error to run G31 with a value less than 0.1 inch, but I was seeing it fail to move with a distance of 0.2 inches.  The guy I am writing the routine for wants it to run pretty fast, so backing up an inch or more to then run at F1 is a no-go.  I ran out of patience, and didn't test if it would work at 0.5, I just gave up and wrote my own code ignoring G31 after the first touch-off. 

My routine seems to be accurate to -0.001+0.0 or so to calculate tool length, so after fussing with g31 for a few hours I called that a win.  I still want to know why #2002 is holding the wrong value!
Any machine is a smoke machine if used wrong enough,

Offline Graham Waterworth

*
  • *
  •  2,668 2,668
  • Yorkshire Dales, England
    • View Profile
Re: Mach3, G31 probe on Z axis, and variable 2002
« Reply #6 on: April 25, 2020, 05:28:13 PM »
Have you got an active tool offset?
Without engineers the world stops
Re: Mach3, G31 probe on Z axis, and variable 2002
« Reply #7 on: April 25, 2020, 05:34:49 PM »
Do you have a length offset active, if so that will be included in the #2002 value you could do a G49 before you do the G31 G91 Z-1. move
Since what I am doing is measuring the tool length, and putting it into the tool table, I first tried using "IncludeTLOinZFromG31()" to test and make the operator deselect that option before running.  However, even with it unchecked, G31 used the Tool offset.  So I concluded I don't understand what "TLO" is.  So now I just zero out the tool length at the start (setOEMDRO(42, 0.0)) and upon successful completion, load the new value in.

In any case that would not explain the behavior.  No matter what value the tool offset was set to, if a tool touched off from the sensor, or if I hit the sensor my self when the tool was 6 inches away, 2002 would always show the part Z offset.  Weird.
« Last Edit: April 25, 2020, 05:39:43 PM by CoreyCoop »
Any machine is a smoke machine if used wrong enough,
Re: Mach3, G31 probe on Z axis, and variable 2002
« Reply #8 on: April 25, 2020, 05:37:15 PM »
Analyze this code to figure out how touchoff is working.
It does NOT retract automatically after contact.

Yes, I know, my side question about that is why does Artsoft specifically mention that it does retract back to the 2002 position, when in fact it does not?
Any machine is a smoke machine if used wrong enough,

Offline Graham Waterworth

*
  • *
  •  2,668 2,668
  • Yorkshire Dales, England
    • View Profile
Re: Mach3, G31 probe on Z axis, and variable 2002
« Reply #9 on: April 25, 2020, 05:47:06 PM »
The same reason why it says G73 retracts, the documentation is wrong.
Without engineers the world stops