Hello Guest it is July 18, 2024, 07:26:52 AM

Author Topic: subroutines  (Read 4060 times)

0 Members and 1 Guest are viewing this topic.

« on: October 16, 2010, 04:41:08 PM »
HI everyone even though I am still new at CNC programming I am making headway I have the book that everyone seems to be talking about but I am having a bit of difficulty in setting up my first subroutine. I have a drawing that I want to make into a subroutines and simply adjust the z axis lower by the same amount in each iteration. A job suited nicely with subroutines.(ie multi pass)
The drawing has a small cutout in the center and then another shape the outer edge. I will attach the .tap file from mach. Anyway I successfully made it process the subroutines the amount of times but I can't seem to get the Z axis to adjust incrementally I believe I am correct in using the G91 - G91.1 CNC commands but something is off and as soon as I try to make what I think is an insignificant change to test I get something that says all words I J K don't exist or something along those lines.

I have several jobs that will all be using this same subroutines structure 3 iteration pass of a small cutout circle and a 3 iteration pass of the outer edge.
So with a little help and guidance I may be able to get all my jobs created and running soon.

The object is a gear with a center hole cut out, if my previous explanation was insufficient(Hope this one helps)

I have looked at the book regarding subroutines which is how I got most of it working but the incremental increase in the z axis on each pass is eluding me

Offline Hood

  •  25,835 25,835
  • Carnoustie, Scotland
Re: subroutines
« Reply #1 on: October 16, 2010, 05:15:17 PM »
Afraid I am not great with code so I would let the multi pass wizard write it for me ;)
Re: subroutines
« Reply #2 on: October 16, 2010, 05:28:26 PM »
You want to use a variable to set the Z height, and update it after each pass:

N10 #100 = -0.01 (set initial Z depth)
N20 N30 M98 P600 L3

G1 Z#100 Fx.xx (Plunge to depth)
(do your cutting here)
G0 Z1.00 (return to safe Z height)
#100 = #100 - 0.100 (set depth for next pass)

Ray L.
Ray L.

Offline BR549

  •  6,965 6,965
Re: subroutines
« Reply #3 on: October 16, 2010, 05:45:07 PM »
Here is a MOD of YOUR code.  

The Gcode for switching between modes is G90 abs  and G91 inc

ALso remember when you loop the SUB and intend on doing an inc down move into the material  you cannot Move back  up to a safe .500 unlees you include that value into your down move. Swithing back and forth can get tricky sometimes. You just have to pay attention to where you are in ABS and what you intend to do in INC.(;-)

Also remember when you are done CLEAR out your offsetts in this case the G43H2  Cancel with G49.

GOOD JOB on the code(;-) You did allow for the tool offset right?

Hope that helps, (;-) TP

N5 (File Name = 2__43_NO_OFFSET_cutout on Saturday, October 16, 2010)
N10 (Default Mill Post)
N11 G40  G54 G80 G90
N25 M6 T2(TOOL Change 1mm str_end_cut)
N30 G43 H2
N35 G0  Z0.5000
N45  X1.0429  Y1.0000
N50  Z0.0000
N51 M98 P600 L3
        G0 Z.500
N52  G0 X1.7209  Y0.5594
N53  G0 Z0.0000
N54 M98 P610 L3
        G0 Z.500
N55 M5
N56 G49
N56 M30

N55 G91
N56 G1 Z-0.0417 F9.0
N57 G90
N60 G2  I-0.0429  J0.0000  F60.00
N67 M99

N80 G91
         G1  Z-0.0417  F9.00
N81  G90
N85  G2  X1.7196  Y0.5573  I-0.6894  J0.4226  F60.00
N90  X1.7682  Y0.4903  I-0.2141  J-0.2064
N95  X1.7670  Y0.4699  I-0.0174  J-0.0092
N100  X1.7485  Y0.4441  I-0.7384  J0.5108
N105  X1.7295  Y0.4365  I-0.0158  J0.0118
N110  X1.6506  Y0.4610  I0.0474  J0.2922
N115  X1.6475  Y0.4573  I-0.6511  J0.5399
N120  X1.6858  Y0.3840  I-0.2408  J-0.1722
N125  X1.6816  Y0.3640  I-0.0186  J-0.0066
N130  X1.6597  Y0.3412  I-0.8485  J0.7925
N135  X1.6398  Y0.3362  I-0.0140  J0.0138
N140  X1.5652  Y0.3720  I0.0892  J0.2815
N145  X1.5616  Y0.3688  I-0.5844  J0.6491
N150  X1.5888  Y0.2907  I-0.2638  J-0.1356
N155  X1.5818  Y0.2715  I-0.0193  J-0.0038
N160  X1.5569  Y0.2522  I-0.7047  J0.8830
N165  X1.5364  Y0.2502  I-0.0119  J0.0157
N170  X1.4677  Y0.2964  I0.1302  J0.2678
N175  X1.4638  Y0.2938  I-0.4712  J0.7092
N180  X1.4793  Y0.2125  I-0.2795  J-0.0954
N185  X1.4695  Y0.1946  I-0.0197  J-0.0009
N190  X1.4420  Y0.1791  I-0.5367  J0.9212
N195  X1.4215  Y0.1801  I-0.0094  J0.0173
N200  X1.3603  Y0.2358  I0.1667  J0.2445
N205  X1.3559  Y0.2338  I-0.3542  J0.7521
N210  X1.3595  Y0.1512  I-0.2918  J-0.0539
N215  X1.3472  Y0.1348  I-0.0196  J0.0019
N220  X1.3178  Y0.1235  I-0.3990  J0.9948
N225  X1.2977  Y0.1275  I-0.0068  J0.0185
N230  X1.2452  Y0.1916  I0.2011  J0.2182
N235  X1.2407  Y0.1902  I-0.2300  J0.7616
N240  X1.2321  Y0.1079  I-0.2962  J-0.0109
N245  X1.2176  Y0.0934  I-0.0191  J0.0047
N250  X1.1866  Y0.0866  I-0.2077  J0.8660
N255  X1.1674  Y0.0935  I-0.0039  J0.0193
N260  X1.1249  Y0.1645  I0.2300  J0.1859
N265  X1.1202  Y0.1638  I-0.1342  J0.8922
N270  X1.0998  Y0.0837  I-0.2960  J0.0324
N275  X1.0834  Y0.0715  I-0.0182  J0.0074
N280  X1.0518  Y0.0691  I-0.0921  J1.0274
N285  X1.0336  Y0.0788  I-0.0012  J0.0197
N290  X1.0019  Y0.1552  I0.2545  J0.1504
N295  X0.9971  Y0.1552  I-0.0024  J0.8742
N300  X0.9654  Y0.0789  I-0.2876  J0.0750
N305  X0.9473  Y0.0692  I-0.0170  J0.0100
N310  X0.9157  Y0.0715  I0.0626  J1.1060
N315  X0.8992  Y0.0836  I0.0017  J0.0196
N320  X0.8789  Y0.1639  I0.2730  J0.1116
N325  X0.8742  Y0.1646  I0.1202  J0.8292
N330  X0.8316  Y0.0937  I-0.2739  J0.1162
N335  X0.8123  Y0.0868  I-0.0153  J0.0124
N340  X0.7815  Y0.0936  I0.2127  J1.0352
N345  X0.7669  Y0.1081  I0.0045  J0.0192
N350  X0.7584  Y0.1905  I0.2884  J0.0712
N355  X0.7539  Y0.1918  I0.2261  J0.7545
N360  X0.7014  Y0.1279  I-0.2535  J0.1545
N365  X0.6814  Y0.1239  I-0.0133  J0.0145
N370  X0.6517  Y0.1352  I0.3210  J0.8831
N375  X0.6395  Y0.1516  I0.0074  J0.0183
N380  X0.6432  Y0.2342  I0.2947  J0.0283
N385  X0.6389  Y0.2362  I0.3852  J0.8296
N390  X0.5777  Y0.1806  I-0.2276  J0.1891
N395  X0.5572  Y0.1796  I-0.0111  J0.0163
N400  X0.5296  Y0.1951  I0.4580  J0.8490
N405  X0.5198  Y0.2131  I0.0099  J0.0170
N410  X0.5354  Y0.2944  I0.2972  J-0.0149
N415  X0.5316  Y0.2969  I0.4315  J0.6539
N420  X0.4629  Y0.2509  I-0.1974  J0.2200
N425  X0.4425  Y0.2528  I-0.0086  J0.0177
N430  X0.4175  Y0.2721  I0.6592  J0.8840
N435  X0.4104  Y0.2913  I0.0122  J0.0154
N440  X0.4377  Y0.3695  I0.2907  J-0.0577
N445  X0.4342  Y0.3727  I0.5164  J0.5776
N450  X0.3595  Y0.3370  I-0.1642  J0.2476
N455  X0.3397  Y0.3419  I-0.0059  J0.0188
N460  X0.3177  Y0.3647  I0.6611  J0.6594
N465  X0.3135  Y0.3847  I0.0144  J0.0134
N470  X0.3519  Y0.4581  I0.2807  J-0.0999
N475  X0.3489  Y0.4617  I0.6852  J0.5744
N480  X0.2698  Y0.4373  I-0.1257  J0.2676
N485  X0.2509  Y0.4451  I-0.0031  J0.0195
N490  X0.2324  Y0.4708  I0.8420  J0.6242
N495  X0.2312  Y0.4912  I0.0162  J0.0112
N500  X0.2799  Y0.5582  I0.2604  J-0.1383
N505  X0.2775  Y0.5622  I0.6508  J0.3980
N510  X0.1958  Y0.5496  I-0.0856  J0.2836
N515  X0.1781  Y0.5600  I-0.0003  J0.0197
N520  X0.1636  Y0.5881  I1.0001  J0.5360
N525  X0.1653  Y0.6086  I0.0176  J0.0088
N530  X0.2232  Y0.6678  I0.2389  J-0.1757
N535  X0.2214  Y0.6720  I0.8507  J0.3658
N540  X0.1387  Y0.6715  I-0.0434  J0.2926
N545  X0.1228  Y0.6843  I0.0026  J0.0195
N550  X0.1125  Y0.7144  I0.8251  J0.2974
N555  X0.1173  Y0.7343  I0.0188  J0.0060
N560  X0.1831  Y0.7844  I0.2107  J-0.2086
N565  X0.1819  Y0.7889  I0.7729  J0.2037
N570  X0.1001  Y0.8004  I-0.0003  J0.2967
N575  X0.0862  Y0.8154  I0.0054  J0.0189
N580  X0.0804  Y0.8466  I0.9907  J0.2007
N585  X0.0880  Y0.8656  I0.0194  J0.0033
N590  X0.1605  Y0.9057  I0.1784  J-0.2374
N595  X0.1600  Y0.9103  I0.8161  J0.0918
N600  X0.0806  Y0.9336  I0.0428  J0.2926
N605  X0.0690  Y0.9504  I0.0081  J0.0179
N610  X0.0678  Y0.9820  I1.0430  J0.0562
N615  X0.0781  Y0.9998  I0.0197  J0.0005
N620  X0.1557  Y1.0289  I0.1417  J-0.2603
N625  X0.1558  Y1.0336  I0.7974  J-0.0275
N630  X0.0807  Y1.0680  I0.0856  J0.2859
N635  X0.0717  Y1.0864  I0.0106  J0.0166
N640  X0.0752  Y1.1180  I0.9024  J-0.0833
N645  X0.0879  Y1.1340  I0.0195  J-0.0025
N650  X0.1689  Y1.1515  I0.1024  J-0.2786
N655  X0.1697  Y1.1560  I0.8618  J-0.1559
N660  X0.1003  Y1.2012  I0.1252  J0.2681
N665  X0.0942  Y1.2206  I0.0130  J0.0148
N670  X0.1022  Y1.2515  I0.8356  J-0.2029
N675  X0.1172  Y1.2654  I0.0190  J-0.0054
N680  X0.1998  Y1.2708  I0.0606  J-0.2897
N685  X0.2013  Y1.2753  I0.7506  J-0.2543
N690  X0.1392  Y1.3300  I0.1634  J0.2478
N695  X0.1359  Y1.3502  I0.0150  J0.0128
N700  X0.1483  Y1.3794  I0.9174  J-0.3709
N705  X0.1652  Y1.3911  I0.0180  J-0.0080
N710  X0.2477  Y1.3843  I0.0172  J-0.2971
N715  X0.2499  Y1.3887  I0.8478  J-0.4301
N720  X0.1964  Y1.4518  I0.1984  J0.2222
N725  X0.1961  Y1.4723  I0.0167  J0.0105
N730  X0.2127  Y1.4994  I0.7447  J-0.4366
N735  X0.2310  Y1.5084  I0.0166  J-0.0106
N740  X0.3116  Y1.4897  I-0.0262  J-0.2958
N745  X0.3144  Y1.4937  I0.7041  J-0.4995
N750  X0.2708  Y1.5639  I0.2272  J0.1897
N755  X0.2734  Y1.5842  I0.0180  J0.0080
N760  X0.2936  Y1.6086  I0.7910  J-0.6348
N765  X0.3132  Y1.6150  I0.0150  J-0.0128
N770  X0.3902  Y1.5848  I-0.0692  J-0.2901
N775  X0.3936  Y1.5883  I0.5673  J-0.5443
N780  X0.3606  Y1.6641  I0.2533  J0.1552
N785  X0.3662  Y1.6838  I0.0190  J0.0053
N790  X0.3898  Y1.7050  I0.6071  J-0.6537
N795  X0.4100  Y1.7084  I0.0129  J-0.0149
N800  X0.4818  Y1.6673  I-0.1101  J-0.2753
N805  X0.4856  Y1.6703  I0.4878  J-0.6281
N810  X0.4641  Y1.7501  I0.2731  J0.1166
N815  X0.4724  Y1.7687  I0.0195  J0.0024
N820  X0.4990  Y1.7863  I0.4996  J-0.7263
N825  X0.5195  Y1.7867  I0.0106  J-0.0166
N830  X0.5845  Y1.7357  I-0.1488  J-0.2561
N835  X0.5887  Y1.7381  I0.3884  J-0.6876
N840  X0.5790  Y1.8201  I0.2864  J0.0755
N845  X0.5900  Y1.8374  I0.0197  J-0.0004
N850  X0.6187  Y1.8509  I0.4056  J-0.8261
N855  X0.6391  Y1.8483  I0.0081  J-0.0180
N860  X0.6960  Y1.7883  I-0.1848  J-0.2322
N865  X0.7005  Y1.7900  I0.3007  J-0.7775
N870  X0.7029  Y1.8727  I0.2931  J0.0329
N875  X0.7163  Y1.8882  I0.0194  J-0.0033
N880  X0.7466  Y1.8973  I0.3001  J-0.9356
N885  X0.7664  Y1.8919  I0.0054  J-0.0189
N890  X0.8140  Y1.8242  I-0.2174  J-0.2035
N895  X0.8187  Y1.8252  I0.2100  J-0.9179
N900  X0.8331  Y1.9067  I0.2957  J-0.0102
N905  X0.8486  Y1.9200  I0.0187  J-0.0061
N910  X0.8800  Y1.9247  I0.1618  J-0.9756
N915  X0.8988  Y1.9164  I0.0026  J-0.0195
N920  X0.9359  Y1.8425  I-0.2418  J-0.1678
N925  X0.9417  Y1.8429  I0.0609  J-0.7975
N930  X0.9679  Y1.9214  I0.2910  J-0.0534
N935  X0.9852  Y1.9323  I0.0176  J-0.0088
N940  X1.0170  Y1.9322  I0.0130  J-0.8885
N945  X1.0343  Y1.9212  I-0.0004  J-0.0197
N950  X1.0602  Y1.8428  I-0.2662  J-0.1316
N955  X1.0651  Y1.8424  I-0.0634  J-0.8822
N960  X1.1023  Y1.9162  I0.2819  J-0.0958
N965  X1.1211  Y1.9245  I0.0162  J-0.0112
N970  X1.1525  Y1.9198  I-0.1229  J-0.9308
N975  X1.1680  Y1.9065  I-0.0032  J-0.0194
N980  X1.1823  Y1.8250  I-0.2832  J-0.0916
N985  X1.1870  Y1.8239  I-0.1967  J-0.8908
N990  X1.2346  Y1.8916  I0.2646  J-0.1356
N995  X1.2544  Y1.8970  I0.0144  J-0.0135
N1000  X1.2848  Y1.8879  I-0.2745  J-0.9637
N1005  X1.2982  Y1.8724  I-0.0060  J-0.0188
N1010  X1.3004  Y1.7897  I-0.2918  J-0.0492
N1015  X1.3050  Y1.7880  I-0.2816  J-0.7352
N1020  X1.3620  Y1.8479  I0.2411  J-0.1720
N1025  X1.3823  Y1.8505  I0.0122  J-0.0154
N1030  X1.4111  Y1.8368  I-0.3532  J-0.7834
N1035  X1.4220  Y1.8196  I-0.0088  J-0.0176
N1040  X1.4122  Y1.7375  I-0.2959  J-0.0062
N1045  X1.4164  Y1.7352  I-0.4715  J-0.8459
N1050  X1.4814  Y1.7862  I0.2142  J-0.2059
N1055  X1.5019  Y1.7858  I0.0099  J-0.0170
N1060  X1.5284  Y1.7683  I-0.5693  J-0.8893
N1065  X1.5368  Y1.7495  I-0.0111  J-0.0163
N1070  X1.5152  Y1.6697  I-0.2938  J0.0369
N1075  X1.5189  Y1.6668  I-0.4993  J-0.6470
N1080  X1.5908  Y1.7078  I0.1811  J-0.2338
N1085  X1.6110  Y1.7044  I0.0073  J-0.0183
N1090  X1.6347  Y1.6829  I-0.5243  J-0.6033
N1095  X1.6402  Y1.6633  I-0.0135  J-0.0143
N1100  X1.6072  Y1.5875  I-0.2869  J0.0798
N1105  X1.6105  Y1.5841  I-0.6981  J-0.6772
N1110  X1.6875  Y1.6143  I0.1456  J-0.2585
N1115  X1.7070  Y1.6079  I0.0046  J-0.0192
N1120  X1.7273  Y1.5833  I-0.6221  J-0.5339
N1125  X1.7299  Y1.5631  I-0.0154  J-0.0122
N1130  X1.6863  Y1.4929  I-0.2722  J0.1207
N1135  X1.6890  Y1.4890  I-0.6311  J-0.4511
N1140  X1.7696  Y1.5076  I0.1062  J-0.2763
N1145  X1.7880  Y1.4985  I0.0017  J-0.0196
N1150  X1.8045  Y1.4714  I-0.8292  J-0.5236
N1155  X1.8042  Y1.4509  I-0.0170  J-0.0100
N1160  X1.7507  Y1.3878  I-0.2513  J0.1586
N1165  X1.7529  Y1.3835  I-0.7129  J-0.3666
N1170  X1.8353  Y1.3902  I0.0647  J-0.2885
N1175  X1.8521  Y1.3785  I-0.0012  J-0.0197
N1180  X1.8645  Y1.3492  I-0.9510  J-0.4215
N1185  X1.8613  Y1.3290  I-0.0182  J-0.0074
N1190  X1.7991  Y1.2743  I-0.2251  J0.1931
N1195  X1.8006  Y1.2698  I-0.9140  J-0.3151
N1200  X1.8832  Y1.2643  I0.0215  J-0.2965
N1205  X1.8982  Y1.2503  I-0.0040  J-0.0193
N1210  X1.9061  Y1.2196  I-0.9169  J-0.2547
N1215  X1.8999  Y1.2001  I-0.0191  J-0.0046
N1220  X1.8306  Y1.1551  I-0.1950  J0.2243
N1225  X1.8315  Y1.1503  I-0.8280  J-0.1539
N1230  X1.9123  Y1.1329  I-0.0220  J-0.2977
N1235  X1.9250  Y1.1169  I-0.0068  J-0.0185
N1240  X1.9285  Y1.0855  I-1.0466  J-0.1314
N1245  X1.9195  Y1.0670  I-0.0196  J-0.0019
N1250  X1.8443  Y1.0325  I-0.1599  J0.2496
N1255  X1.8445  Y1.0277  I-0.8149  J-0.0303
N1260  X1.9219  Y0.9987  I-0.0650  J-0.2912
N1265  X1.9322  Y0.9810  I-0.0094  J-0.0173
N1270  X1.9310  Y0.9493  I-0.8984  J0.0189
N1275  X1.9194  Y0.9324  I-0.0197  J0.0011
N1280  X1.8400  Y0.9093  I-0.1216  J0.2697
N1285  X1.8395  Y0.9045  I-0.7995  J0.0875
N1290  X1.9119  Y0.8644  I-0.1059  J-0.2765
N1295  X1.9194  Y0.8454  I-0.0119  J-0.0157
N1300  X1.9137  Y0.8144  I-1.0390  J0.1754
N1305  X1.8998  Y0.7994  I-0.0193  J0.0039
N1310  X1.8178  Y0.7880  I-0.0817  J0.2866
N1315  X1.8166  Y0.7833  I-0.9243  J0.2384
N1320  X1.8824  Y0.7331  I-0.1453  J-0.2587
N1325  X1.8871  Y0.7132  I-0.0140  J-0.0138
N1330  X1.8769  Y0.6833  I-0.9583  J0.3104
N1335  X1.8610  Y0.6705  I-0.0185  J0.0067
N1340  X1.7783  Y0.6712  I-0.0389  J0.2946
N1345  X1.7764  Y0.6668  I-0.8031  J0.3394
N1350  X1.8342  Y0.6075  I-0.1806  J-0.2338
N1355  X1.8360  Y0.5872  I-0.0159  J-0.0116
N1360  X1.8214  Y0.5591  I-0.8120  J0.4015
N1365  X1.8038  Y0.5487  I-0.0173  J0.0093
N1370  X1.7221  Y0.5614  I0.0044  J0.2971
N1375  X1.7209  Y0.5594  I-0.6907  J0.4206
N1382 M99

« Last Edit: October 16, 2010, 05:53:29 PM by BR549 »
Re: subroutines
« Reply #4 on: October 16, 2010, 10:47:01 PM »
Thank you very much BR549 your mod let me see the error of my ways I was close just didn't go back to ABS after the INC. I'll look more closely at the differences between your mod and my original to make sure but your mod is working and seeing the mod I will probably be able to make further revision on my own.
For give my but I am still quite new but I noticed that on LINES 51 54 and 80 of your mod there is code on the next line with no line number what does this indicate I have noticed this on other code sample but neer knew the significance if any

Thanks again very much
Re: subroutines
« Reply #5 on: October 16, 2010, 10:49:28 PM »
Himey your suggestion may have worked as well but I am still quite new and haven't gotten into the use of variables yet  Thanks for replying I will also look at your suggestions as well

Offline BR549

  •  6,965 6,965
Re: subroutines
« Reply #6 on: October 16, 2010, 11:25:14 PM »
YOu can have line numbers OR not , EXCEPT on the SUB name line, it must not have a line number. 


You WILL like the variable approach AFTER you figure out the specifics of Gcode (;-)

(;-) TP