Hello Guest it is October 31, 2024, 07:48:05 PM

Author Topic: (Mach3) Can't figure out issue with G31 Command (Probing)  (Read 58436 times)

0 Members and 1 Guest are viewing this topic.

(Mach3) Can't figure out issue with G31 Command (Probing)
« on: June 13, 2022, 10:43:39 PM »
Hello Mach 3 People!

Recently, I was trying to use the probing feature on Mach3 to do surface leveling, but something strange is happening and I don't know if it is because of something in Mach3 or because of my WiHXC Ethernet motion control card.

The description of the whole thing goes like this:

  • Before I start probing, I open a file with G40 command -> THIS IS OK.
  • When I start probing, everything goes fine, the CNC mill goes to every single point and does its thing with the probe, and the digitizer indicator lights up accordingly as well.
  • The DROs move as they should.
  • I close the file with G41 command.
  • And... when looking at the file, all the points recorded are the same, the X variable across its column has the same number, and the same thing happens with the Y and Z variiables recorded. -> THIS IS THE ISSUE.

After going all over to see where those numbers came from, I saw that what is being recorder are the Work Offsets for every single probed point, which is strange, since G31 is supposed to get the data from the #2000-#2005 variables. The work offsets have to exist, I mean, you are not always going to place your stock at (x0,y0,z0).

So... why could this be happening?

Is it a simple thing due to configurations, or is it due to my motion control card?
« Last Edit: June 13, 2022, 10:54:45 PM by alvaroevc5 »
Re: (Mach3) Can't figure out issue with G31 Command (Probing)
« Reply #1 on: June 14, 2022, 03:31:59 AM »
Please post your code.
Re: (Mach3) Can't figure out issue with G31 Command (Probing)
« Reply #2 on: June 14, 2022, 11:21:02 AM »
Please post your code.

Lil' detail I forgot.

Just to mention, I already tried to add 2002 macro (didn't work), somewhere in the Mch3 forum someone mentioned adding a G49 before G31 to cancel tool length compensation (didn't work, and I don't think it had to do with the problem, but during desperate times, you try anything), I also added #500=#2002 before each G31 (didn't work).

Here is the Gcode file:

Re: (Mach3) Can't figure out issue with G31 Command (Probing)
« Reply #3 on: June 14, 2022, 11:53:28 AM »
Um, as I read your code (and use a search box in edit), I don't see ANY G31 commands?  You need something like this after each XY move:
G31 Z-5 F50
while ismoving wend (waits until the move has stopped)
(then commands to move up to just clear, followed by a repeat G31/while/wend at a slow rate)
Then you read the probed height from the #2002 variable and write it to where you want it
Then lift the probe clear and move to the next XY point.

Re: (Mach3) Can't figure out issue with G31 Command (Probing)
« Reply #4 on: June 14, 2022, 12:00:50 PM »
Um, as I read your code (and use a search box in edit), I don't see ANY G31 commands?

Sorry, I uploaded the wrong file. After fiddling so many times with the code I have too many variants of what I have done.

(then commands to move up to just clear, followed by a repeat G31/while/wend at a slow rate)
Then you read the probed height from the #2002 variable and write it to where you want it
Then lift the probe clear and move to the next XY point.

So it has to be done with a while loop? I read in the official Mach3 documentation that:

 "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 a triplet giving X, Y and Z at the trip will be written to
the triplet file if it has been opened by the M40 macro/OpenDigFile() function (q.v.)
"

So reading the variables and manually writing to the file is not necessary, it's all supposed to be done by the G31 command.


This is the  actual file used:
« Last Edit: June 14, 2022, 12:05:30 PM by alvaroevc5 »
Re: (Mach3) Can't figure out issue with G31 Command (Probing)
« Reply #5 on: June 14, 2022, 12:30:51 PM »
The statement

While IsMoving()       
   Wend

just halts the macro execution while the G31 move is happening.  Once the move is finished and the coords are written to the parameter registers execution can continue.  All the probe routines that I have seen use this construct.  Maybe you aren't giving the system time to finish probing?  Also see this thread:

https://www.machsupport.com/forum/index.php?topic=25414.0

Re: (Mach3) Can't figure out issue with G31 Command (Probing)
« Reply #6 on: June 14, 2022, 03:42:17 PM »
While IsMoving()       
   Wend

I will try this and see how it goes.

I'll implement it and grind the idea of how exactly that works. I do know how to code, but this Mach3 language and it's functions are new to me. Time to get into it!
Re: (Mach3) Can't figure out issue with G31 Command (Probing)
« Reply #7 on: June 14, 2022, 04:34:04 PM »
I already did:

G31 Z-5 F50
while IsMoving()
wend


No luck, I still get the Work Offset values....

This is stressing me quite bit...  >:(

Why something so simple has to be so complicated?  :-\
« Last Edit: June 14, 2022, 04:40:43 PM by alvaroevc5 »
Re: (Mach3) Can't figure out issue with G31 Command (Probing)
« Reply #8 on: June 15, 2022, 02:28:59 AM »
Doh!  Sorry I've been a bit thick here.  All the probing routines I have used have been MACROS, not .nc files.  That is, they are written in Cypress Basic (CB) (equivalent of Visual Basic).  The "while ismoving() / wend" construct is a CB command.  A probing macro would then include a phrase such as:

Code "G90 G31 Z #1 F" & ProbeFeed1 'Fast probing move
While IsMoving () 'Wait until task has been completed
Wend

Notice that the Code command causes the CB interpreter to issue a G code command to Mach.  In this case it's a G31 in absolute mode (G90) to a level set in variable #1 and at a rate determined by ProbeFeed1.  This comes from a tool height macro which is below.  I guess you are trying to do auto levelling of some sort?  I notice that your code has a lot of XY moves written in-line, if you write it as a macro you can use a couple of for-next loops (or whatever CB calls them) which makes everything much easier.  There are also autolevelling macros around - see for example https://www.autoleveller.co.uk/.

'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 = 38.84 'Touch Plate thickness is set here
ProbeFeed1 = 50 'Fast probing feedrate is set here
ProbeFeed2 = 5 'Slow probing feedrate is set here
SetVar (1, -5) 'Maximum probing distance is set here
SetVar (2, 50) 'Retract height is set here
Code "M5" 'Ensures spindle is not running
Code "G21" 'Ensure metric units are used
Zs = GetOemDRO (61) 'Copy current Z-Scale DRO
Call SetOemDRO (61,1) 'Set Z-Scale DRO to 1
DoOemButton (1010) 'Zero Z-Axis DRO
Code "(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 + 1 'Displace probe position upwards by 1mm
Code "G0 Z" & ProbePos 'Lifts probe 1 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
Call SetDRO (2,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
Code "(Z-Axis is now Referenced.)" 'Message for status bar
Code "F" & CurrentFeed 'Restore feedrate to original setting
If Contact = 0 Then 'Probe reached max travel without touching
Code "(ERROR - Probe did not touch.)" 'Message for status bar
Response = MsgBox ("ERROR - Probe did not touch.",37,"Auto Tool Zero")
End If
Else
Code "(ERROR - Touch Plate is grounded.)" 'Message for status bar
Response = MsgBox ("ERROR - Touch Plate is grounded - Check connection.",16,"Auto Tool Zero")
End If
Call SetOemDRO (61,Zs) 'Restore Z-Scale DRO to original setting
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 
     
Re: (Mach3) Can't figure out issue with G31 Command (Probing)
« Reply #9 on: June 15, 2022, 02:51:41 PM »
That is right, I have been trying to do autolevelling, and the software I am using to do it is precisely Autoleveller.

The file I posted is the PFG probing file for a certain area, so that is the code produced after using the software.

I will test what you posted JohnHaine and see how it goes, this subject is killing me quite a bit to be honest. Out of all the complex features that work, the simplest one is the one giving me a lot of trouble.

Another question arise though. Let's say the probing macro works in my case, but, how could I write the XYZ coordinates to a file?

I thought M40 would only get written to by the G31 command. Does this mean that M40 gets written to after the probe has tripped, regardless of the G31 command being used or not?
« Last Edit: June 15, 2022, 02:59:36 PM by alvaroevc5 »