Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: JeffMach3 on September 17, 2019, 02:00:25 PM

Title: Restart program
Post by: JeffMach3 on September 17, 2019, 02:00:25 PM
Hi I am trying to learn how Mach 4 works.  I am more used to Fanuc.  If I want to run a program a certain amount of cycles I use the Macro B statements.  But I tried using the GOTO command in Mach4 but it just hung there. Do you have any ideas on how to do this?


N10
G0XOYO
...
#100=#100+1
IF[#100LT10]GOTO10
M30
Title: Re: Restart program
Post by: joeaverage on September 17, 2019, 02:33:09 PM
Hi,
Mach4Hobby (or Mach3) does not have MacroB, Mach4Industrial does.

Craig

Title: Re: Restart program
Post by: Ya-Nvr-No on September 17, 2019, 02:39:43 PM
It's just like Fanuc... you have to pay extra for the Macro B option.  :'(

But in Fanuc it was just a parameter change; you just had to know the one.  ;)
Title: Re: Restart program
Post by: JeffMach3 on September 17, 2019, 02:52:37 PM
I guess it is all about what/who you know.    Do you have an idea on how to get the program to auto-restart or loop?   There has got to be a way.
Title: Re: Restart program
Post by: Ya-Nvr-No on September 17, 2019, 02:54:53 PM
M99
Title: Re: Restart program
Post by: JeffMach3 on September 17, 2019, 02:58:44 PM
So would you write it:

O2692
 G0X0
...
M98P2692
Title: Re: Restart program
Post by: joeaverage on September 17, 2019, 03:10:05 PM
Hi,
you can call a subroutine a certain number of times, this is from the Mill Gcode manual that is in the Docs folder that
ships with Mach4:

Quote
M98 – Subprogram Call
Subprograms are external programs referenced by the current running program. When called program execution will continue in the subprogram. This allows the user to reduce program length and complexity by providing the ability to easily repeat sections of code, run the same section of code in multiple locations or in multiple fixture offsets, the possibilities are limited only by the programmer. To call a subprogram command M98 with the program number as shown.
Format: M98 P____ Q__ L__
P specifies the number of the program to be called. This is a four digit integer number. When the M98 is read Mach scans the current file for a block containing the program number in the following form:
Format: O1234
Note that the letter “O” is used to specify the program number 1234, NOT the number “0”.

The arguments Q and L are optional. Q specifies the sequence number in the subprogram to start at. If
Q is omitted then execution will start at the beginning of the sub program; see figure 198-1. L is the
number of repetitions. For example, if L=2 the subprogram is run two times before execution of the
main program continues. If L is omitted the program will run only once.

If you want to use conditionals (IF-THEN-ELSE, DO_WHILE) in Mach4Hobby then you use macros, the macros are coded in Lua.

Craig
Title: Re: Restart program
Post by: JeffMach3 on September 17, 2019, 03:17:01 PM
I read that, was not sure how to apply that to the main program.  I guess you could create the main program as one program name and then use it as a spring board into your sub program that carries your whole program inside.  I have never used it that way but I guess it would work.

(Main Program)
12345
G0G90X0Y0
M98P2692L10
M30

(Sub program)
O2692
G0X20.Y10.
...
M99
Title: Re: Restart program
Post by: joeaverage on September 17, 2019, 04:42:00 PM
Hi,
yes thats how I would apply it.

Craig
Title: Re: Restart program
Post by: JeffMach3 on September 17, 2019, 04:43:10 PM
Thank-you so much!!
Title: Re: Restart program
Post by: Ya-Nvr-No on September 17, 2019, 07:03:01 PM
you could replace any m30 in a program with m99 it will never stop
I use them all the time for warmup routines or checking tool changer issues.
you don't need a m98 just in sub routine calls


Here is a rough example of stepping over and maybe drilling or spotfacing
#100=1
#101=1.5

M98 P1000 L1
M3
M98 P2000 L9
M98 P1000 L1
M5
M30

O1000
G0z1
G0X0Y0
m99

O2000
#100=#100+1
g0 x#100 y#101
g1z-.1f40
g4p1
g0z.1
m99
Title: Re: Restart program
Post by: JeffMach3 on September 18, 2019, 09:02:59 AM
Very helpful, thanks