Hello Guest it is March 29, 2024, 11:36:54 AM

Author Topic: Mach3 not executing code in order  (Read 2650 times)

0 Members and 1 Guest are viewing this topic.

Mach3 not executing code in order
« on: September 08, 2016, 08:32:30 PM »
Am hoping someone has an idea why this is happening - and a solution.
Here is a snippet of the code from a job file:

Basically, M17 raises the cutting head to lift to an absolute position of 1.5" above the table
The next line of code rotates the head
M16 then lowers the cutting head to a position entered in a DRO on the screen
The problem I'm having is line N0520 is executing before line N0510,


N0500 G03 X3.4222 Y0.4292 A-88.8756 I1.1670 J1.6746
N0510 G00 M17
N0520 A162.7067
N0530 M16

Just for information:

Macro M16 is:
Offset1=GetUserDRO (1031) 'Set Cut Height
code "G53Z" & Offset1
While IsMoving
Wend
code "G90"

Macro M17 is:
code "G53Z1.5"
While IsMoving
Wend
code "G90"
Re: Mach3 not executing code in order
« Reply #1 on: September 08, 2016, 09:43:04 PM »
As I recall, user defined macros should use a number higher than 100.  "M" codes lower than 100 should be considered "reserved".  Try renaming these to M106 and M107 and see if that makes a difference.

Also, just a side note:  G53 is non-modal meaning that is is not remembered from one block to the next so the G90 statement is not necessary.  G53 must be explicitly stated for each block you wish to have executed in Machine Coordinates and then reverts to the previous modal mode.  So if you were operating in G90 prior to this macro running, G90 would still be in effect throughout the macro except for the one line that executes the G53 command.  Even worse, putting the G90 in the macro could cause unexpected results if you were in G91 prior to running the macro and the remaining code after the macro expects to be in that mode instead.

When writing macros, I generally do not rely on the machine being in a specific state so if I'm going to set a mode (e.g. G90/91 or G20/21) during the running of a macro I will first store the current mode to a variable and then restore the mode from that variable at the end of the macro.  Since your macro does not set a mode other than this closing G90 statement, this is not necessary and neither is the G90 itself.

Hope that helps,

Stephen "Highspeed" Kruse

P.S.  If I'm remembering incorrectly about the macro numbers, someone please chime in here and correct that statement.
Re: Mach3 not executing code in order
« Reply #2 on: September 08, 2016, 09:56:39 PM »
Thanks for the G90 info. I wasn't sure if it was needed, so added it just in case.
I've used M16/M17 before on other systems and they worked OK - no issues.
In this case, the M16 and M17 macros work, just seem to be executing out of order.
Re: Mach3 not executing code in order
« Reply #3 on: September 09, 2016, 03:44:16 PM »
Yep, not being familiar with everyone here I want to make sure all information I can think of is shared.

Since you've had it working on another system (I'm assuming not Mach3) it's still possible that Mach3 has different requirements for user macro numbering.  Could you try using a different pair of numbers to see if that would make a difference?  Just some troubleshooting steps.  I also see in line 510 that you are using a G0 without movement and calling the M17 in the same block.  Not sure this is an issue but perhaps try putting the M17 on a different line so that the G0 can take effect since it is a modal command.  Perhaps setting the machine to an expected state for the macro.  So line 510 would become simply G0 with a new line 515 for the M17 command.

That's all I really see that comes to mind.

Highspeed
Re: Mach3 not executing code in order
« Reply #4 on: September 09, 2016, 05:23:48 PM »
Actually the other system was Mach3 as well.

Had an epiphany today.
The system involved is an ultrasonic blade cutter.
I had been trying to run standard SheetCam posted files and use a tangential selection button on my operator screen to run the A axis in tangential mode.
After dealing with the Mach3 tangential mode issues, I switched to a modified version on the tangential post for Mach that is included with SheetCam.
I had left the tangential button selected on the operator screen - figuring it couldn't do any harm
Apparently it can. I switched it of and now the file runs correctly, with the Z command code executing before the A axis command code.
Re: Mach3 not executing code in order
« Reply #5 on: September 09, 2016, 05:58:41 PM »
Awesome!  Glad you got it figured out.  Wish I could have been more help.

Highspeed