Machsupport Forum
G-Code, CAD, and CAM => G-Code, CAD, and CAM discussions => Topic started by: Overloaded on April 29, 2009, 08:26:53 AM
-
Hi,
Just experimenting.....can a sub run within a sub ?
This sample code executes nicely for however many duplicates requested in the X.
%
#3=0
M98 P01 L4
G0 X0 Y0
M30
O1
G0 X#3
G1 z-.2 F50
G03 I-1.
G0 z.1
#3=[#3+2.3]
m99
%
Can I run this sub IN another sub that shifts the Y in the same manner ?
Say.....4 rows and 4 columns ?
I've made several attempts wit no sucess.
Thanks,
RC
-
Have a look at this thread :-
Graham
http://www.machsupport.com/forum/index.php/topic,310.msg1603.html#msg1603
Or this one
http://www.machsupport.com/forum/index.php/topic,1551.msg8780.html#msg8780
-
I think Mach can do 3 levels as long as you do NOT recall a currently running sub. Don't hold me to it though(;-) Post what you tried and I will test it as well.
Nothing like an adventure, (;-) TP
-
Hey Graham......GREAT links. I wish I'd seen them while searching.
They are very helpful...Thanks. Found some others too.
I especially liked the tapping grid you illustrated.
I guess that is the "Three Levels" that Tony just mentioned.
Hi Tony,
Not enough band width to post what I have tried...lol
Another question,
The grid looks great for tapping or drilling but what if I were making a multi cavity mould of say a star.
The datum of the star would be the center, so the shifts are OK so would the star program, with x-y moves, be the last sub running in G91 ?
Or would you use another approach.....like G52 instead ?
Hope this makes sense to ya.
Thanks
RC
-
Here is a sub in a sub drilling 10 rows of ten holes
G0 x0y0z0
g91
M98 P1 L5
g80
G90
M30
%
o1
g81 z-.1 R.1 F20
x1 L9
y1
x-1L9
g80
M98 P2 L0
o2
Y1
m99
%
m99
%
(;-) TP
-
Mighty handy there TP...amazing how much can be done with so little code.
How would you go about making a grid of a part program ?
Like this one attached for example.
4 rows, 8 columns
Thanks,
RC
-
If I were doing multi pockets then a calculated G52 local shift would be my method.
Graham
-
Graham, Tony,
This runs well in simulation.
m98 p0001
G52 x5
X0
m98 p0001
g52 x10
X0
m98 p0001
G52 x15
X0
m98 p0001
G52 x20
X0
m98 p0001
G52 X0
X0
m30
Is this a proper way to use G52 ?
Thanks guys,
RC
-
RC Graham is correct the g52 would be a good choice. With a drilling CYCLE it is very easy to work in incremental, BUT when you shift to doing a shape then INC becomes a bear to keep track of and the G52 shift becomes the favorite venue.
Also note that there are MANY ways it can be done, BUT sometimes Mach struggles with complex subs. I just did one to do a shape in a grid using parametric code 4x4 grid of a simple square. It was funny that mach could draw it out on the toolscreen correctly but could NOT cut it correctly.
Also just because it is crazy complicated DOESN"T mean it is the best approach the simple ways are normally the BEST ways to programming
Just a thought, (;-) TP
(;-) TP
-
RC it displays correct but can't say it would actually cut correct(;-)
N5 (File Name = ARING on Wednesday, April 29, 2009)
N10 (Default Mill Post)
N15 G91.1
#1=0
#2=0
N20 M5 M9
N25 M6 T33(TOOL Change .125 End Mill)
N30 G43 H33
N35 G0 Z0.2000
N40 M3 S4000
M98 P10 L4
M98 P11 L9
M30
o10
N45 X-0.5000 Y0.0000
N50 Z0.1000
N55 G1 Z-0.0300 F50.00
N60 G2 X0.5000 Y0.0000 I0.5000 J-0.0000 F100.00
N65 X-0.5000 Y0.0000 I-0.5000 J0.0000
N70 G0 Z0.2000
N75 X-1.0000 Y0.0000
N80 Z0.1000
N85 G1 Z-0.0300 F50.00
N90 G2 X1.0000 Y0.0000 I1.0000 J-0.0000 F100.00
N95 X-1.0000 Y0.0000 I-1.0000 J0.0000
N100 G0 Z0.2000
N105 X-2.0000 Y0.0000
N110 Z0.1000
N115 G1 Z-0.0300 F50.00
N120 G2 X2.0000 Y0.0000 I2.0000 J-0.0000 F100.00
N125 X-2.0000 Y0.0000 I-2.0000 J0.0000
N130 G0 Z0.2000
N135 X0.3214 Y0.3830
N140 Z0.1000
N145 G1 Z-0.0300 F50.00
N150 X0.2595 Y0.4443 F100.00
N155 X0.2042 Y0.5122
N160 X0.1552 Y0.5857
N165 X0.1125 Y0.6638
N170 X0.0448 Y0.8292
N175 X0.0000 Y1.0000
N180 X-0.0205 Y1.1233
N185 X-0.0337 Y1.2477
N190 X-0.0411 Y1.4987
N195 X-0.0279 Y1.7504
N200 X0.0000 Y2.0000
N205 G0 Z0.2000
N210 X0.3420 Y0.9397
N215 Z0.1000
N220 G1 Z-0.0300 F50.00
N225 X0.6840 Y1.8794 F100.00
N230 G0 Z0.2000
N235 X0.4924 Y0.0868
N240 Z0.1000
N245 G1 Z-0.0300 F50.00
N250 X0.4844 Y0.1735 F100.00
N255 X0.4856 Y0.2611
N260 X0.4954 Y0.3489
N265 X0.5128 Y0.4362
N270 X0.5674 Y0.6064
N275 X0.6428 Y0.7660
N280 X0.7762 Y0.9775
N285 X0.9319 Y1.1745
N290 X1.1037 Y1.3588
N295 X1.2856 Y1.5321
N300 G0 Z0.2000
N305 X0.8660 Y0.5000
N310 Z0.1000
N315 G1 Z-0.0300 F50.00
N320 X1.7321 Y1.0000 F100.00
N325 G0 Z0.2000
N330 X1.9696 Y0.3473
N335 Z0.1000
N340 G1 Z-0.0300 F50.00
N345 X1.7189 Y0.3315 F100.00
N350 X1.4688 Y0.3007
N355 X1.3451 Y0.2781
N360 X1.2229 Y0.2498
N365 X1.1027 Y0.2152
N370 X0.9848 Y0.1736
N375 X0.8244 Y0.0998
N380 X0.6732 Y0.0045
N385 X0.5398 Y-0.1121
N390 X0.4826 Y-0.1784
N395 X0.4330 Y-0.2500
N400 G0 Z0.2000
N405 X0.9848 Y-0.1736
N410 Z0.1000
N415 G1 Z-0.0300 F50.00
N420 X1.9696 Y-0.3472 F100.00
N425 G0 Z0.2000
N430 X1.7321 Y-1.0000
N435 Z0.1000
N440 G1 Z-0.0300 F50.00
N445 X1.5298 Y-0.8510 F100.00
N450 X1.3185 Y-0.7138
N455 X1.2092 Y-0.6516
N460 X1.0974 Y-0.5947
N465 X0.9830 Y-0.5439
N470 X0.8660 Y-0.5000
N475 X0.6957 Y-0.4534
N480 X0.6076 Y-0.4382
N485 X0.5186 Y-0.4293
N490 X0.4296 Y-0.4273
N495 X0.3415 Y-0.4329
N500 X0.2550 Y-0.4469
N505 X0.1710 Y-0.4698
N510 G0 Z0.2000
N515 X0.6428 Y-0.7660
N520 Z0.1000
N525 G1 Z-0.0300 F50.00
N530 X1.2856 Y-1.5320 F100.00
N535 G0 Z0.2000
N540 X-0.1710 Y-0.4698
N545 Z0.1000
N550 G1 Z-0.0300 F50.00
N555 X-0.0919 Y-0.5062 F100.00
N560 X-0.0167 Y-0.5511
N565 X0.0545 Y-0.6035
N570 X0.1214 Y-0.6622
N575 X0.2415 Y-0.7946
N580 X0.3420 Y-0.9397
N585 X0.4034 Y-1.0485
N590 X0.4584 Y-1.1610
N595 X0.5512 Y-1.3943
N600 X0.6249 Y-1.6352
N605 X0.6840 Y-1.8794
N610 G0 Z0.2000
N615 X0.0000 Y-1.0000
N620 Z0.1000
N625 G1 Z-0.0300 F50.00
N630 Y-2.0000 F100.00
N635 G0 Z0.2000
N640 X-0.6840 Y-1.8794
N645 Z0.1000
N650 G1 Z-0.0300 F50.00
N655 X-0.5724 Y-1.6544 F100.00
N660 X-0.4740 Y-1.4224
N665 X-0.3951 Y-1.1840
N670 X-0.3649 Y-1.0626
N675 X-0.3420 Y-0.9397
N680 X-0.3257 Y-0.7639
N685 X-0.3261 Y-0.6745
N690 X-0.3327 Y-0.5853
N695 X-0.3462 Y-0.4973
N700 X-0.3670 Y-0.4115
N705 X-0.3958 Y-0.3287
N710 X-0.4330 Y-0.2500
N715 G0 Z0.2000
N720 X-1.2855 Y-1.5320
N725 Z0.1000
N730 G1 Z-0.0300 F50.00
N735 X-0.6427 Y-0.7660 F100.00
N740 G0 Z0.2000
N745 X-1.7321 Y-1.0000
N750 Z0.1000
N755 G1 Z-0.0300 F50.00
N760 X-1.5019 Y-0.8994 F100.00
N765 X-1.2774 Y-0.7849
N770 X-1.0637 Y-0.6530
N775 X-0.9626 Y-0.5794
N780 X-0.8660 Y-0.5000
N785 X-0.7405 Y-0.3758
N790 X-0.6311 Y-0.2345
N795 X-0.5848 Y-0.1584
N800 X-0.5456 Y-0.0793
N805 X-0.5145 Y0.0026
N810 X-0.4924 Y0.0868
N815 G0 Z0.2000
N820 X-1.9696 Y-0.3472
N825 Z0.1000
N830 G1 Z-0.0300 F50.00
N835 X-0.9848 Y-0.1736 F100.00
N840 G0 Z0.2000
N845 X-1.6426 Y0.2566
N850 Z0.1000
N855 G1 Z-0.0300 F50.00
N860 X-1.4831 Y0.2198 F100.00
N865 X-1.3591 Y0.1987
N870 X-1.2346 Y0.1835
N875 X-1.1098 Y0.1749
N880 X-0.9848 Y0.1736
N885 X-0.8972 Y0.1782
N890 X-0.8088 Y0.1882
N895 X-0.7208 Y0.2040
N900 X-0.6342 Y0.2260
N905 X-0.5498 Y0.2546
N910 X-0.4689 Y0.2900
N915 X-0.3924 Y0.3327
N920 X-0.3214 Y0.3830
N925 G0 Z0.2000
N930 X-1.9696 Y0.3473
N935 Z0.0000
N940 G1 Z-0.0300 F50.00
N945 X-1.7286 Y0.2764 F100.00
N950 X-1.6426 Y0.2566
N955 G0 Z0.2000
N960 X-1.7320 Y1.0000
N965 Z0.1000
N970 G1 Z-0.0300 F50.00
N975 X-0.8660 Y0.5000 F100.00
N980 G0 Z0.2000
N985 X-1.2856 Y1.5321
N990 Z0.1000
N995 G1 Z-0.0300 F50.00
N1000 X-1.1465 Y1.3229 F100.00
N1005 X-0.9948 Y1.1217
N1010 X-0.8278 Y0.9342
N1015 X-0.7377 Y0.8473
N1020 X-0.6428 Y0.7660
N1025 X-0.4987 Y0.6640
N1030 X-0.4211 Y0.6196
N1035 X-0.3405 Y0.5808
N1040 X-0.2576 Y0.5484
N1045 X-0.1728 Y0.5236
N1050 X-0.0868 Y0.5071
N1055 X0.0000 Y0.5000
N1060 G0 Z0.2000
N1065 X-0.3420 Y0.9397
N1070 Z0.1000
N1075 G1 Z-0.0300 F50.00
N1080 X-0.6840 Y1.8794 F100.00
N1085 G0 Z0.2000
X0 Y0 Z0
N1090 M5
g92 x[#1+5]
m99
o11
G92 y[#2+5] X[#1-15]
M98 P10 L4
M99
%
-
Really neat Tony.
This is a fine example of using G92.
This is what I was trying to do in the initial post. I LIKE IT !
I goes good with the description in the G-Code list.
One can save it like below and just plug in the part program and set the offsets to suit.
Wizards are fine but I like to see whats happening.
G91.1
#1=0
#2=0
M98 P10 L4
M98 P11 L9
M30
o10
************
PART PROGRAM
************
g92 x[#1+5]
m99
o11
G92 y[#2+5] X[#1-15]
M98 P10 L4
M99
%
Is it, or does it need to be cancelled with G92.1 or 2 just before M30 ?
If not, will the offsets carry over to the next program ?
Should I include G92.1 in the initialization string ?
Thanks much Tony, good examples really help to see the effects of the functions.
RC
-
Yes you should cancell it when done sorry I forgot to include that part, Good call (;-)
It is always a GOOD idea to clean up the mess after each program is done to assure the next program will run correctly.
Hope it helps (;-) TP