Hello Guest it is April 18, 2024, 06:11:25 PM

Author Topic: Ideas for running conditional programs  (Read 1264 times)

0 Members and 1 Guest are viewing this topic.

Ideas for running conditional programs
« on: May 23, 2018, 10:13:08 PM »
Hi everybody. I am working on writing a program for reloading a part in a machine in the case of an error.

I'll just give a little background info so this makes sense. I am making parts with bamboo as the raw material and a pick and place system that loads the bamboo.  Because the bamboo shape and size is extremely variable, it is impossible to avoid the occasional loss of a part from the fixture while it is being machined.

The obvious solution to me is to create a macro that does a quick diagnostic check, loads another piece, and starts the program again.  The tricky part, is that I'd like to control how many pieces are being machined. If there is a loss at 50 out of 100 pieces, the macro will restart the program and I'll end up with 50 more pieces than I intended.
I have thought about doing the entire program inside of a macro, but that doesn't seem like a very elegant solution.

I'd love to hear anyone's advice about this subject and hopefully it will be of some help to others.

David
Re: Ideas for running conditional programs
« Reply #1 on: June 05, 2018, 11:38:15 AM »
Looks like this is not the hot topic I was hoping for  :)

Just in case this helps anyone, I thought I'd share my solution to the problem.

You can't restart or reload g code through a macro because Mach4 won't let you.  This makes sense, however you can put a macro at the beginning of any g code that either allows it to run or stops it.  This can be based on a counter, such as one you might store in the regfile. Then all you need is a g code program that loops indefinitely. You can loop the whole program by putting it in a subroutine and then calling an m99 at the end. This will loop until your macro stops it.  

Here's where it gets really trashy.  You can call an M99 from within a macro. For example:
local gcode = ""   
gcode = gcode .. ("m99\n")            
mc.mcCntlGcodeExecute(inst, gcode)
This will restart the entire program.  This gives you the ability to decide how many times to run a program, and also call a macro that under a given set of circumstances will start the program from the top. Because you have the macro at the beginning of the program to stop it once the counter has reached its limit, the program can restart itself as many times as necessary without running more times than you intended.

I'm not completely sure why this works. Maybe it has something to do with the g code compiler not being able to look ahead and see the M99 in your macro?

If anyone has any better solutions, or opinions on whether this workaround is really as unwholesome as it seems, I'd love to hear from you!!




Re: Ideas for running conditional programs
« Reply #2 on: June 08, 2018, 03:32:47 PM »
Hi,
MacroB has conditional Gcode statements and is included in Mach4 Industrial.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'