What's new
What's new

Using local variables with subprograms

manoweb

Aluminum
Joined
Sep 13, 2018
I am writing a small subprogram to run on a VF-3. It would be so convenient if I could pass a "step" value so that I do not have multiple of the same subprogram that are 99% identical and only differ on a Y value on two lines.
Is the following correct?

main program:
...

Code:
...
N50 G01 X.7399 Y-.4
N60 G01 Z.5 F20
N70 #1=0.1
N75 M98 P2561 L7
...
N70 #1=0.03
N75 M98 P2561 L7
...


O2461
...
N50 G03 X-.3524 Z-0.0209 R.3530
N60 G02 X-.6399 Z0.25 R0.2880
N70 G01 X-.7399
N80 G91 Y#1
...


Note how I assign a value to #1 and then I call the subprogram, hoping that I can use #1 inside it.
I am not going to be able to test this until tomorrow so I thought I'd ask here. Right now, I'd rather not convert this into a MACRO (G65) unless it's necessary. One little step at a time.
 
Look at G65. Or G66 if you run the subprogram over and over in different spots.

I didn't read your aversion to G65. There is very little difference between M98 (M97) or G65. G65 will do what you're asking, and it's simple.

G65 P2461 is exactly the same as M98 P2451 You just have to add an alpha to the line to pass your argument to the sub. (I think it's 1-27 for A thru Z, with some you can't use)
 
I don’t see enough code to really know. From what you posted it will only cut on the first time thru the loop , then cut air 6 times.

You need to write it in incremental if you want to loop it.
 
@beege I do not necessarily have an aversion, but one step at a time. I would like to understand if that is going to work with M98 for now.

@Booze Daily line N80 of the subprogram is a G91
 
Okay then, instead of using #1 (which isn't a variable per se) try using #500. this works if you have User Macros turned on (an option I wish I had on all my Hasses). And right after your G91 line, be sure to go back to G90. #1 is what you would use if you had a G65P####L7A### - The number after A would be passed on as variable #1 in the sub.
 
Okay then, instead of using #1 (which isn't a variable per se) try using #500. this works if you have User Macros turned on (an option I wish I had on all my Hasses). And right after your G91 line, be sure to go back to G90. #1 is what you would use if you had a G65P####L7A### - The number after A would be passed on as variable #1 in the sub.
I see, I thought using #1 was the "easiest" but now it turns out maybe going G65 is the right thing to do without upsetting other users of the machine? I will study how G65 works.
 
I don’t see a switch back to G90 anywhere so I still don’t understand.
Well I did not write a full program with dozens of lines, there are other operations that use G90, also I did not write the M99 to return to the main program to be called again... I was just concentrating on the #1 variable usage
 
I have modified it to use G65, can somebody check if this is going to work because I'd like to minimize the amount of time I need to mess with the machine :D

I have removed some extra steps that would make the program way too long, to concentrate on the actual G65 usage:


Code:
O2461
N10 G91 G01 Y#1 (INCREMENTAL MOTION IN +Y)
N20 G90 X-.73
N80 G91 Y#1 (STEP)
N140 G01 X.73
N150 M99

O2460 (TROUGH .500 RA125)
(SKIPPING SOME SETUP)
(ROUGHING Y STEPOVER 0.1)
N60 G65 P2461 A0.1 L7
N70 G00 Z0.4
N80 X.74 Y0
N90 G01 Z.5 F50.0
(FINISH Y STEPOVER 0.0314)
N100 G65 P2461 A.0314 L24
N110 M09
N120 G00 G53 G49 G17 D0 Z0 M05
N130 M02
 
Your A and L aren’t defined in your “macro”
There’s still not enough code to figure out what you’re trying to do

Can you post a pic?
 
Local variables get cleared on each subsequent subroutine… meaning if you nest pultiple subroutines, you can pass parameters with the alphabet addressing. Only use variables higher than the local addresses if you need to PERSIST those numbers, i.e. several areas in your program need them or you just don’t want to continue passing it down the chain…

Keep in mind when using locally addressed variables, they will clear on more nesting or parent program return.

An easy way to see this is single block through your probing routines if you got them… keep the macro variables tab open and each G65 call will clear all values, and write the alphabet addresses that are passed in. A === #1, etc. you can find the addresses and corresponding variable numbers on the first page of macro variables.
 
I have modified it to use G65, can somebody check if this is going to work because I'd like to minimize the amount of time I need to mess with the machine :D

I have removed some extra steps that would make the program way too long, to concentrate on the actual G65 usage:


Code:
O2461
N10 G91 G01 Y#1 (INCREMENTAL MOTION IN +Y)
N20 G90 X-.73
N80 G91 Y#1 (STEP)
N140 G01 X.73
N150 M99

O2460 (TROUGH .500 RA125)
(SKIPPING SOME SETUP)
(ROUGHING Y STEPOVER 0.1)
N60 G65 P2461 A0.1 L7
N70 G00 Z0.4
N80 X.74 Y0
N90 G01 Z.5 F50.0
(FINISH Y STEPOVER 0.0314)
N100 G65 P2461 A.0314 L24
N110 M09
N120 G00 G53 G49 G17 D0 Z0 M05
N130 M02
I have only had 1 mountain dew so far today but, looks like that will do it. Maybe run it in the air and watch your macro page and make sure.
 
I will of course test it before moving metal, thanks for confirming it doesn't look horrible.
 
The G65 part like:

Code:
N100 G65 P2461 L24 A.0314

Worked perfectly thanks! In fact I was able to get rid of several unnecessary subprograms and we decided to use this in any similar case in the future.

What I wish I knew before trying this is:

G65 can replace M98 and takes both P and L arguments to specify which subprogram and how many times to call it.
However, it adds the possibility to pass arguments by using letters (Axxx, Bxxx, Cxxx...) which are then converted to parameters in the subprogram (#1, #2, #3...). A complete list of available letters and to which number they translate into is available at:
unfortunately that page is pretty confusing as one has to click on the tabs on the top to see the various sections.

Thanks @beege !!!
 








 
Back
Top