Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: PtD on October 30, 2014, 04:09:47 AM

Title: G31 causes an endless loop
Post by: PtD on October 30, 2014, 04:09:47 AM
Hi all,

I am using Digitizing Wizard to extract a 3D model from an object, and I've encountered the following problem: when executing this G-Code sequence

N1 F100
N2 G0X0Y0Z1
N3 G31 Z-10
N4 G0 Z1
N5 G0X1Y0Z1
N6 G31 Z1
N7 G0 Z10
N8 G0X2Y0Z1
...

Mach3 starts looping between lines 2 and 3. It would position at (0,0,1) @ line 2 , then it would probe down to touch the object @ line 3, and then for some reason it returns to execute line 2 again, instead of moving forward to line 4.

I suspected it may have something to do with Safe Z, but it doesn't work with any setup of Safe Z I tried.

What can be the cause of this odd behavior?

(Sorry if this has been answered before).

Thanks in advance.
Title: Re: G31 causes an endless loop
Post by: ger21 on October 30, 2014, 09:08:42 AM
Line 4 is basically the same as line 2. Are you sure it's looping?
What is line 6 supposed to do?
THis is very strange code.
Title: Re: G31 causes an endless loop
Post by: stirling on October 30, 2014, 09:52:39 AM
I think what we have here is a classic case of the code we see is not the code in question - the digitize wizard would not produce that code - but a bad memory and a quick hand might.
Title: Re: G31 causes an endless loop
Post by: PtD on October 30, 2014, 01:59:19 PM
You are correct that this is not the exact code from the Digitizing Wizard. It is a simplified version just to expose the loop. Here is the actual Digitizing Wizard code:

 (Digitize File)
M40
G92X0Y0Z0
F100
 G0X0Y0Z1
 G31 Z-10
 G0 Z1
 G0X1Y0Z1
 G31 Z-10
 G0 Z1
 G0X2Y0Z1
 G31 Z-10
 G0 Z1
 G0X3Y0Z1
 G31 Z-10
 G0 Z1
....

Here the loop happens on lines 5 and 6:
 G0X0Y0Z1
 G31 Z-10

In the "Current Line Number" DRO it goes 5, 6, 5, 6, 5, 6... ad infinitum. The strange thing is that once or twice, with other parameters for height and depth it worked, but I can't reproduce them.

Mach3 version is R3.043.066.
Title: Re: G31 causes an endless loop
Post by: stirling on October 30, 2014, 02:28:47 PM
please post your xml file. That's the file in C:\Mach3 with the same name as your profile with a .xml extension. Make a copy and rename it to Ptd.xml and post it using the forum's full-reply Additional options link.
Title: Re: G31 causes an endless loop
Post by: PtD on October 30, 2014, 02:51:14 PM
Here it is, attached to the post.

Also can be read at https://www.dropbox.com/s/nijslczuy3apqsv/Mach3Mill.xml?dl=0

And here is a video of the loop sequence I shot: https://www.dropbox.com/s/844htm1iilp2wum/MOV_0761.mp4?dl=0

Thanks in advance for your support!
Title: Re: G31 causes an endless loop
Post by: stirling on October 31, 2014, 06:27:08 AM
Everything works fine here with your xml on my R3.042.020.

Best I can suggest is you try a re-install of Mach3 and maybe use a different/earlier version (ftp://ftp.machsupport.com/Mach). I believe Hood is unhappy with 0.66 for all sorts of reasons - personally I've never used it so can't comment.
Title: Re: G31 causes an endless loop
Post by: PtD on October 31, 2014, 07:24:46 AM
I installed R3.042.020. Changed the default configuration just for input signals and motors. Ran the Digitize.tap. Same result - loops over and over between G31 and G0.  :o

Title: Re: G31 causes an endless loop
Post by: PtD on October 31, 2014, 07:42:11 AM
Installed R3.042.020 on another machine - that never had Mach3 before. Configured motors and inputs. Same endless loop.

Is there a debug mode I can turn on so that I can report more information for troubleshooting?
Title: Re: G31 causes an endless loop
Post by: stirling on October 31, 2014, 11:39:15 AM
Just for the hell of it can you remove your license file from the Mach3 folder, move it to the desktop or something - i.e. make sure you have a safe copy somewhere. Restart Mach and check the about box to make sure you're in demo mode and try your wiz code again.

Is there a debug mode I can turn on so that I can report more information for troubleshooting?

All dev and bug fixing has ceased on Mach3.
Title: Re: G31 causes an endless loop
Post by: PtD on October 31, 2014, 04:44:18 PM
I confirm the same behavior both in licensed and demo mode.

I would suspect some quirks with the controller, but I can't see how the controller can cause a step back in the execution order in Mach3...
Title: Re: G31 causes an endless loop
Post by: ger21 on October 31, 2014, 05:48:17 PM
If you're not using the parallel port, many external motion controllers have G31 bugs in their plugins.
Whenever you're using a motion controller, make sure you specify that up front when asking questions, as it can save days of frustration.
Title: Re: G31 causes an endless loop
Post by: PtD on November 01, 2014, 12:42:17 PM
Right. The controller is YooCNC USB motion card (the one from X6-1500GT). What I see is that G31 is correctly executed - it touches probe and then program moves to another step. What could be the reason that G31 command (executed with whatever controller) is making Mach3 go back a line?
Title: Re: G31 causes an endless loop
Post by: ger21 on November 01, 2014, 01:46:28 PM
As I said, it's probably a bug in the plugin for your motion controller.

Report the issue to the developer of the device, and see if they can fix it.
Title: Re: G31 causes an endless loop
Post by: PtD on November 02, 2014, 06:25:27 PM
Follow up: This VB code works fine:

Code: [Select]
For y = 0 To 10
For x = 0 To 10
Code "G0 Z1"
Code "G0 X" & x & "Y" & y
While IsMoving()
Sleep(10)
Wend

Code "G31 Z-10"
While IsMoving()
Sleep(10)
Wend
Sleep(10)
zProbe = GetDRO(2)

Message "x " & x & ", y " & y & ", z " & zProbe
Next
Next

It seems that the problem is related to timing issues. If I omit the sleep(10) before the GetDRO(2) call, I get spurious values for Z.

Based on this VB script, I developed a wizard that does the whole digitizing in VB. I will keep trying to resolve the issue in G-Code.

Thanks for your support.