Hello Guest it is March 29, 2024, 08:38:05 AM

Author Topic: Mach3 g-code "if" conditional?  (Read 10894 times)

0 Members and 1 Guest are viewing this topic.

Mach3 g-code "if" conditional?
« on: April 28, 2009, 05:13:01 AM »
Is there a way to implement an "if" conditional in G-code?

I found there are conditionals for other engines' versions of G-code, but I didn't see one in the manual.  At one point it does say that "conditional branching is not permitted".

At best I kinda thought of:

"if integer #5>0 then O100"

#10=[FIX[#5+0.1]/#5] (gives 1 for any positive nonzero integer)
M98 P100 L#10

Which should work, but it does kinda end up high in the running for Most Obfuscated Solution.

vmax549

*
Re: Mach3 g-code "if" conditional?
« Reply #1 on: April 28, 2009, 09:25:02 AM »
Sorry , there is NO conditional branching in MACH Gcode (;-(

(;-) TP
Re: Mach3 g-code "if" conditional?
« Reply #2 on: April 28, 2009, 02:18:28 PM »
You can do conditional IF/THEN/ELSE and WHILE in a macro.
Re: Mach3 g-code "if" conditional?
« Reply #3 on: April 28, 2009, 02:25:22 PM »
You can do conditional IF/THEN/ELSE and WHILE in a macro.


Could you give an example of this?
I saw this on some random examples on the Net, but it's not in the core G-code specification.   I tried to create it but couldn't get Mach3 to parse it.  I assumed Mach3 did not implement IF/THEN/ELSE and WHILE.

I may have failed to grasp the "macro" aspect.  Is it a preprocessor thing?  And thus unable to control the flow at runtime?
« Last Edit: April 28, 2009, 02:29:42 PM by MechanoMan »
Re: Mach3 g-code "if" conditional?
« Reply #4 on: April 28, 2009, 04:51:02 PM »
Ok, just off the top of my head here is a simple one. Set a variable and run a piece of code that many times.

#500 = 5
O20
routine 1 here
#500 = #500-1
M500
M98 P#502
O30
G code routine 2

M500.m1s file goes in macros/your profile and contains

Sub main ()
a = GetVar (500)
If a > 0 Then GoTo set20
SetVar(502,30)
GoTo set30
set20:
SetVar(502,20)
set30:
End
End Sub
Re: Mach3 g-code "if" conditional?
« Reply #5 on: August 26, 2012, 09:31:14 PM »
Hi everyone, I need some help.
I want to have an output activated in certain x,y coordinate and deactivate in another point without interrupt movement. how can I do that, is there a possibility to have the output activated and timed while the movement keep going? I'll appreciate any help.
thanks
Darli