Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Cbyrdtopper on November 20, 2017, 12:49:35 PM

Title: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 20, 2017, 12:49:35 PM
I've never used Macro B Programming, so I have a few questions about it.  Being able to use loops in G Code could really help us out on a project.  Can Macro B Read inputs to exit a loop?  If not, can you run an M Code in the loop that can read the input and then translate that into a #VAR to exit the loop?
Title: Re: Can you use Inputs with Macro B Programming.
Post by: a3dcreator on November 20, 2017, 01:15:06 PM
what kind of inputs? do you mean like lets say a switch? or an electrical signal?
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 20, 2017, 01:20:40 PM
Yes.   A signal from our measuring device.  A mapped input into Mach4.
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on November 20, 2017, 02:22:06 PM
Have a look at http://www.machinetoolhelp.com/Applications/macro/macro_variables.html  It is kind of a cheat sheet on Macro B.

When referring to those variables, we use Tool Compensation Memory type C.  Like a Fanuc 21i.  

Specifically, the answer to your question is yes.  See the top of this page: http://www.machinetoolhelp.com/Applications/macro/system_variables.html  Input signals are mapped to #1000-1015.  However, we do extend that to #1000-1031 to cover the input signals INPUT #0 to INPUT #31.  The input signals WILL need to be mapped to valid device inputs.  

And you can turn on outputs signals too.  With #1100-1131

Those pages also have some examples of Macro B (loops, etc...) and how to use them.  But for the quintessential reference, Peter Smid has a book called "Fanuc CNC Custom Macros" that covers the subject.

Steve
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 20, 2017, 02:40:37 PM
Awesome!  This should work nicely then.  My dad started the thread for the While Loops in a macro, not updating the screen while it is running.  We may very well be able to use this instead.  It would be a lot simpler.  Thanks for the info, I'm sure more questions will pop up.  I will try to keep this thread posted on my progress as well.  Thanks for the resources Steve.
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 20, 2017, 05:36:08 PM
Another Question
Is there a #VAR for DRO's?  I need to read a few DROs for Rough Inc., Finish Inc., Spark Outs, Etc...
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on November 20, 2017, 05:56:42 PM
I can't find your dad's post.  :(

There are no #vars for DROs.  However, DROs can read/write any #var you choose.  Obviously, you don't want to step on #vars that do something important, so keep that in mind.  You accomplish this by using the DRO's Parameter property.  Enter 500 for #500, etc...  The DRO would then display whatever is in #500 and when you edit it, it would change the value of #500.

You would typically use a #var if you also want to make that information available to G code.  If you don't need that, then using a register as the backing store for the DRO would be better. 

Steve
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 20, 2017, 06:02:56 PM
Here is his post.
http://www.machsupport.com/forum/index.php/topic,35666.0.html

I want this information to be used in the G Code.  For example, I can set DRO 500 to be my Rough Inc. at .002".  In my G code I use #500 to link it to the DRO?
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on November 20, 2017, 06:07:01 PM
Yes. 

Steve
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 20, 2017, 06:13:15 PM
Okay.  That's great. 
Here is a very VERY rough idea of what we want to accomplish. 
Is this the right track at all?

O1000
#YAxis
#XAxis
#100 = GrindToDimension
#101 = Rough Increment 1
#102 = Rough Increment 2
#103 = Finish Increment
#104 = Spark Outs
#105 = X Start
#106 = X End
#107 = Feed Left
#108 = Feed Right
#109 = Grind Feed

M3 (Spindle On)
M8 (Coolant On)

(Rough Grind until the first switch.)
WHILE [#1000 NE 1] 
DO
G91G01 Y [#101] F [#109] (Feed in the Rough 1 Increment amount.)
G90G01 X [#106] F [#107] (Feed XStart to XEnd)
G90G01 X [#105] F [#108] (Feed XEnd to XStart)
END

(Rough Grind until the second switch.)
WHILE [#1001 NE 1]
DO
G91G01 Y [#102] F [#109] (Feed in the Rough 2 Increment amount.)
G90G01 X [#106] F [#107] (Feed XStart to XEnd)
G90G01 X [#105] F [#108] (Feed XEnd to XStart)
END

(Finish Grind until the third switch.)
WHILE [#1002 NE 1]
DO
G91G01 Y [#103] F [#109] (Feed in the Finish Increment amount.)
G90G01 X [#106] F [#107] (Feed XStart to XEnd)
G90G01 X [#105] F [#108] (Feed XEnd to XStart)
END

M5 (Spindle Off)
M9 (Coolant Off)
M30 (End Program)
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on November 20, 2017, 06:55:03 PM
That looks like it might just do the trick.  :)

Ok, I read your dad's post.

When a script is run from a screen control or G code via mcGcodeExecute/Wait(), it will lock the GUI for the duration of the script.  Why?  Because the button click event is the action that causes the script to run.  And it needs to complete.  The application event loop only processes one event at a time.  Screen updates are also events. 

Say you are the application event loop and I am the user of the machine control.  I'm not telling you to do anything at the moment, so you are spending your time running around the screen and updating DROs and such.  But all of a sudden, I press a button that basically says "Cbyrdtopper, go do this script task".  So you go running off to do the script.  So who is updating the DROs now?  Nobody. 

So what mechanism(s) can we use to make this better? 

1) Use the PLC script.  Most buttons scripts should be short and sweet without loops or calls to code that has loops in it.  If a long running task is needed it is better to just set a variable to initiate the action in the button script.  Then a state machine (that watches that variable) can be implemented to process the task in the PLC script. 

2) Hand the action off to the interpreter.  An example of this is the MDI.  You type some G code in and hit cycle start.  The cycle start button just starts the interpreter and comes back immediately.  So the GUI is functional and screen updates happen.  But the state of the machine has changed from idle to MDIrunning.  So you can now wait on the state to transistion back to idle.  The other use of the interpreter is to let it do the complete action (via Macro B), as you are discovering. 

Otherwise, you will need to get into advance LUA programming and use coroutines.  That isn't a road that is easily traveled.  :(



Title: Re: Can you use Inputs with Macro B Programming.
Post by: joeaverage on November 20, 2017, 08:16:33 PM
Hi,
fascinating thread....smurph, you certainly know how to engage ones grey matter!

Craig
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 20, 2017, 09:02:59 PM
That is a great explanation.   It makes a lot of sense.   
I was playing with the DRO Variables and was able to get the GCode variables to work with them.   So that was exciting.   I'm going to play around more in the morning with this and do some more research on the loops.   
Title: Re: Can you use Inputs with Macro B Programming.
Post by: joeaverage on November 21, 2017, 01:36:20 AM
Hi smurph,
I've been reading up on Macro B and now start to understand how it can be used.

It is included in Industrial. Is there any particular reason or rationale that prevents it being implemented in Hobby?

Craig
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on November 21, 2017, 01:46:43 AM
Well...  It is something that is more for industrial types of environments.  And it wasn't in Mach3.  So they sales dept. decided it was to be an industrial feature.  I'm not sure if it can be "added on" with another license or not.  I'll check. 

Steve
Title: Re: Can you use Inputs with Macro B Programming.
Post by: joeaverage on November 21, 2017, 02:05:05 AM
Hi smurph,
my head spins with the features of Hobby let alone the added power of Macro B. I was wondering whether Macro B required some fundemental
ability that is in Industrial but not Hobby?

Craig
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 21, 2017, 10:52:09 AM
So, I'm going to start testing this Macro B Programming.  I need to purchase an industrial license.  However, I don't really like the layout of the Industrial Screen.  Can I use the Hobby Screens on the industrial version?
Title: Re: Can you use Inputs with Macro B Programming.
Post by: a3dcreator on November 21, 2017, 10:58:09 AM
Let me know if you figure this out. I got the industrial and i felt the same way.
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on November 21, 2017, 11:24:38 AM
Yes, you can use a Hobby screen set with an Industrial license.  Just not the other way around. 

Steve
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Steve Stallings on November 21, 2017, 11:53:51 AM
Note: If you do use a Hobby screen set with an Industrial license, you
may need to be sure that the Use Advanced GUI Controls option is turned
off  on the General tab under Config > Mach dialog. Having advanced GUI
controls enabled can cause colors to display in a strange fashion when
running a Hobby install with an Industrial license, and may do the same
when running a Hobby screen with and Industrial install.

Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 21, 2017, 12:10:30 PM
Okay thanks for the update and the info.  Getting ready to try this Macro B Programming out on a little setup.
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 21, 2017, 12:53:36 PM
I've run into a problem.

I'm trying to link the DRO to a #VAR.  On the hobby version I can change the DRO's "Parameter" and it updates the #VAR. 

In the industrial version I change the same settings and it does not change the #VAR. 

I've been starting at #500 on the Hobby version.  On the industrial I've tried several ranges and no luck. 
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on November 21, 2017, 01:12:47 PM
Same build number for both Hobby and Industrial? 
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 21, 2017, 01:31:41 PM
Yes.  3481.  Downloaded it about an hour ago. 11-21-17
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on November 21, 2017, 01:58:39 PM
Should work the same then.  There really is no different in the GUI between Hobby and Industrial other than industrial features are turned on in the Demo mode. 
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 21, 2017, 02:15:39 PM
Here is something weird.  I can manually change the numbers in the Reg File and it updates the DRO, but not the other way around.  In the industrial version.
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 21, 2017, 02:48:49 PM
I went back and double checked that the hobby version #VARS were updating with the DRO, as expected. 

I jump into the Industrial version and it is not working correctly.  I again tried several ranges of #VARS with no change.  But again, I could changed the #VAR in the Reg Diagnostics and it would update the corresponding DRO.

For a bit of good news.  I got the Loops working in Macro B like I need them to.  I can post the code when I get more accomplished.
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 21, 2017, 05:35:01 PM
In this snippet of code; the first Rough Grind operates as expected.  But then the Rough Finish Grind will sometimes not continue to the next operation.  It stops on the M98 line.

(Rough Grind)
WHILE [#5042 GE [#100 + [#101 + .001]]] DO 1
G90 G01 X 0.0 F #105 (Traverse Start to End)
G91 G01 Y -[#101] F #104
G90 G01 X 0.5 F #106 (Traverse End to Start)
M98 1
END 1

(Rough Finish Grind)
WHILE [#5042 GE [#100 + [#102 + .0005]]] DO 2
G90 G01 X 0.0 F #105 (Traverse Start to End)
G91 G01 Y -[#102] F #104
G90 G01 X 0.5 F #106 (Traverse End to Start)
M98 2
END 2

Any ideas why it is doing this?
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on November 21, 2017, 06:35:35 PM
Remove the M98s.  END 1 and END 2 should be sufficient. 

M98 will return you to the specified N label (which you don't have).  Unexpected results should be expected.  :)

N1 WHILE [#5042 GE [#100 + [#101 + .001]]] DO1
G90 G01 X 0.0 F #105 (Traverse Start to End)
G91 G01 Y -[#101] F #104
G90 G01 X 0.5 F #106 (Traverse End to Start)
END1

(Rough Finish Grind)
N2WHILE [#5042 GE [#100 + [#102 + .0005]]] DO2
G90 G01 X 0.0 F #105 (Traverse Start to End)
G91 G01 Y -[#102] F #104
G90 G01 X 0.5 F #106 (Traverse End to Start)
END2

Steve
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on November 21, 2017, 06:44:26 PM
Technically, the numbers for the DO and END is all you need. 

WHILE [condition] DOx
...
ENDx

Where x is a unique number.
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 22, 2017, 08:19:09 AM
I checked the code this morning.  If I don't have the M98 in the loop, it doesn't go back to check the condition, it does the loop infinitely.

But I put the M98 back in the loop and it ran through the code just fine.  That's what's so strange about it, most of the time it works, but sometimes it hangs on that M98 line.
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on November 22, 2017, 08:38:30 AM
Going back through the Hobby Version, running some tests.  My DRO's and #VARS are not linked anymore.  They were working fine yesterday, this morning they stopped working correctly.

The Industrial version, the DRO's and #VARS still do not work together properly.
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on December 07, 2017, 11:53:35 AM
The Mach Support team is now aware of this issue.  I did have 1 DRO working correctly so I just copied it a bunch of times.  I got the Macro B Programming working nicely as well.  Thanks to Steve for pointing us to this book, we purchased the "Fanuc CNC Custom Macros" By Peter Smid, A wonderful book to learn how to write custom macros.
I got my issues fixed with the While Loops as well, a mistake on my end.  I took the loop out of the main program and put the loop in a Sub Program and it worked as expected.

Some things that I learned:
ORGANIZATION!!
In the book Peter Smid says to have a detailed plan laid out.  A very helpful tip.  Our plan was already laid out in Mach3 format, so I had to transfer that info from VB Script into Macro B.  Having it detailed and organized to begin with saved a lot of time. 
I did re-organize some sections to improve work flow, but again, I did it to start out to make my life easier.

Take/Make Notes in the Code.
When creating new variables (#VARS) or "N" lines, put it at the top of your code as a reference to keep track of what has been used and for what purpose.
I Made several notes in each section of the code.  Better to overstate what you did or are doing rather than question what you did a week or year later.

Work on a piece at a time.
I'm really bad at trying to cram in as much work at one time.  With this project, I took my time.  I first worked on the most basic function we use, the Grind to Dimension section of code first.  I got it working the way I wanted and moved on to Plunge Grinding.
This made it easy to re-use the Heart of the grinding code over and over in one sub program. 

Tidy Everything Up
Once I was happy with my first draft of fully finished code, I went through the entire code, made note of #VARS and "N" lines I missed.  Cleaned up some notes and cleaned up the Code. 
I sorted it out into sections, this made making further changes a breeze.

I took a quick video of Dad running the code on the machine.  It took about 2 hours to install Mach4 and get it running this new code. 
We are very pleased at the functionality of this Macro B Programming.  It is very powerful and it seems, so far, to be very reliable with Mach4.
Thanks for all who helped me out in this project.
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on December 07, 2017, 02:11:13 PM
https://www.youtube.com/watch?v=gf8KETp5PCY
Here is a link to the video I took this morning.
Mach4 Macro B Programming.

Move to the left side of what is to be ground.  This is to Check our "Left End" Position
We touch off the part. 
Grind to Final Dimension + .0015"
Check the Dimension, and adjust the Y Position if necessary
Type in final dimension in the "Grind to Dimension" DRO.
Grind
Check the dimension. 
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on December 07, 2017, 03:59:52 PM
Nice job!  That is a perfect use for Macro B.

Steve
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on December 07, 2017, 05:20:20 PM
Thanks, Steve.
It was a lot of fun learning and writing this Macro B Code. 
Thanks for all the help, and the references.  We purchased that book, it is a gold mine of information. 
I'm anxious to get the Auto Measure System put on the machine.  I just finished machining the top side of the riser plate for the Unit, hopefully going to test the fit tomorrow when I get it finished.
Title: Re: Can you use Inputs with Macro B Programming.
Post by: smurph on December 07, 2017, 05:22:25 PM
Any Smid book is a good book.  That guy does a good job. 

Steve
Title: Re: Can you use Inputs with Macro B Programming.
Post by: Cbyrdtopper on December 14, 2017, 04:52:31 PM
Here is a video of our In Process Gauging.
This is working out great!!  It was holding within 0.0001" on over 100 parts, then we set up on another operation. 
https://www.youtube.com/watch?v=kOIo9YLQ3cQ&t=27s