What's new
What's new

How to loop the program for multiple parts on lathe?

SageGlad

Aluminum
Joined
Apr 16, 2022
Hey guys,

having some trouble to understand how do I loop the program if I want to pull the stock with the bar puller and keep making same part over and over till it reaches 20 parts for example.

Can someone show me any examples how you do it?
I was trying to figure out M98 M99 but I couldn't.

Here is my program below, what should I add at the end to get it back to beginning and repeat it 20 times?

%
O1235 (DOVE TAIL PIN)
G40 G80
G20

N1(DRILL1)
G00 G28 U0.
G28 W0.
M69
G54
G98 G18 M46
T0909
M08
G97 S900 M03
G00 Z0.5
X0.
G80
G00 Z0.1
G83 Z-0.0192 R-0.002 F1.5
G80
G00 Z0.5
M09
G28 U0.
G28 W0.
M01

N2(FACE1)
G00 G28 U0.
G28 W0.
M69
G54
G99 G18 M46
G50 S2000
T0101
M08
G97 S1215 M03
G00 Z0.0121
X1.1
G96 S350 M03
X0.7
G01 X0.5283 F0.003
X0.5 Z-0.002
X-0.0352
X-0.007 Z0.0121 F0.04
G00 X1.1

(PROFILE ROUGHING1)
G00 Z0.0534
X0.9
G96 S350 M03
X0.4897
G01 Z-0.4655 F0.003
X0.5606 Z-0.5009
X0.5697
X0.6497 Z-0.4609
G00 Z0.0534
X0.4097
G01 Z-0.451
X0.4478
G03 X0.4698 Z-0.4556 I0. K-0.0156
G01 X0.4897 Z-0.4655
X0.5697 Z-0.4255
G00 Z0.0534
X0.3297
G01 Z-0.451
X0.4097
X0.4897 Z-0.411
G00 Z0.0534
X0.2744
G01 Z0.0011
X0.2938 Z-0.0086
G03 X0.303 Z-0.0196 I-0.011 K-0.011
G01 Z-0.451
X0.3297
X0.4097 Z-0.411
G00 Z0.0534
X0.2191
G01 Z0.0288
X0.2744 Z0.0011
X0.3544 Z0.0411
G00 X0.9
M09
G28 U0.
G28 W0.
M01

N3(DRILL3)
G00 G28 U0.
G28 W0.
M69
G54
G98 G18 M46
T1212
M08
G97 S1389 M03
G00 Z0.6
X0.
G00 Z0.2
G83 Z-0.872 R-0.202 F2.778
G80
G00 Z0.6
M09
G28 U0.
G28 W0.
M01

N4(DRILL1 2)
G00 G28 U0.
G28 W0.
M69
G54
G98 G18 M46
T0909
M08
G97 S900 M03
G00 Z0.5
X0.
G00 Z0.1
G83 Z-0.2872 R-0.202 F2.
G80
G00 Z0.5
M09
G28 U0.
G28 W0.
M01

N5(DRILL2)
G00 G28 U0.
G28 W0.
M05
M69
G54
G99 G17 M45
G00 G28 H0.
M68
T0808
M08
M69
G00 C0.
M68
G00 Z0.6
X0.
G00 Z0.2
G97 S250 M329
G84 Z-0.728 R-0.138 F0.05
G80
G00 Z0.6
M05
M69
M09
G28 U0.
G28 W0.
M01

N6(2D CONTOUR1)
G00 G28 U0.
G28 W0.
M69
G54
G98 G17 M45
G00 G28 H0.
T0606
M08
G97 S5000 M13
G00 Z0.6
X1.6983
C0.
G12.1
G01 X-1.611 C-0.2687 F59.055
Z-1.002
Z-1.1626 F100.
Z-1.202
X-1.511 F30.
G03 X-1.411 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.511 C0.2687 I-0.05 J0.
G01 X-1.611
X-1.565 C-0.2687
X-1.465
G03 X-1.365 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.465 C0.2687 I-0.05 J0.
G01 X-1.565
X-1.519 C-0.2687
X-1.419
G03 X-1.319 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.419 C0.2687 I-0.05 J0.
G01 X-1.519
X-1.473 C-0.2687
X-1.373
G03 X-1.273 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.373 C0.2687 I-0.05 J0.
G01 X-1.473
X-1.427 C-0.2687
X-1.327
G03 X-1.227 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.327 C0.2687 I-0.05 J0.
G01 X-1.427
C-0.2687
X-1.327
G03 X-1.227 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.327 C0.2687 I-0.05 J0.
G01 X-1.427
Z0.2 F59.055
X1.611
Z-1.002
Z-1.1626 F100.
Z-1.202
X1.511 F30.
G03 X1.411 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.511 C-0.2687 I0.05 J0.
G01 X1.611
X1.565 C0.2687
X1.465
G03 X1.365 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.465 C-0.2687 I0.05 J0.
G01 X1.565
X1.519 C0.2687
X1.419
G03 X1.319 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.419 C-0.2687 I0.05 J0.
G01 X1.519
X1.473 C0.2687
X1.373
G03 X1.273 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.373 C-0.2687 I0.05 J0.
G01 X1.473
X1.427 C0.2687
X1.327
G03 X1.227 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.327 C-0.2687 I0.05 J0.
G01 X1.427
C0.2687
X1.327
G03 X1.227 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.327 C-0.2687 I0.05 J0.
G01 X1.427
Z0.6 F59.055
G13.1
M05
M69
M09
G00 G28 U0.
G28 W0.
M01

N7(2D CONTOUR1 2)
G00 G28 U0.
G28 W0.
M69
G54
G98 G17 M45
G00 G28 H0.
T0707
M08
G97 S5000 M13
G00 Z0.6
X1.4221
C0.
G12.1
G01 X-1.3166 C-0.2687 F59.055
Z0.2
Z0.0394 F100.
Z-1.257
X-1.2166 F40.
G03 X-1.1166 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.2166 C0.2687 I-0.05 J0.
G01 X-1.3166
X-1.2646 C-0.2687
X-1.1646
G03 X-1.0646 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.1646 C0.2687 I-0.05 J0.
G01 X-1.2646
X-1.2126 C-0.2687
X-1.1126
G03 X-1.0126 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.1126 C0.2687 I-0.05 J0.
G01 X-1.2126
X-1.1566 C-0.2687
X-1.0566
G03 X-0.9566 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.0566 C0.2687 I-0.05 J0.
G01 X-1.1566
X-1.1366 C-0.2687
X-1.0366
G03 X-0.9366 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.0366 C0.2687 I-0.05 J0.
G01 X-1.1366
Z0.2 F59.055
X1.3166
Z0.0394 F100.
Z-1.257
X1.2166 F40.
G03 X1.1166 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.2166 C-0.2687 I0.05 J0.
G01 X1.3166
X1.2646 C0.2687
X1.1646
G03 X1.0646 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.1646 C-0.2687 I0.05 J0.
G01 X1.2646
X1.2126 C0.2687
X1.1126
G03 X1.0126 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.1126 C-0.2687 I0.05 J0.
G01 X1.2126
X1.1566 C0.2687
X1.0566
G03 X0.9566 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.0566 C-0.2687 I0.05 J0.
G01 X1.1566
X1.1366 C0.2687
X1.0366
G03 X0.9366 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.0366 C-0.2687 I0.05 J0.
G01 X1.1366
Z0.6 F59.055
G13.1

(2D CONTOUR1 3)
G00 C0.
G12.1
G01 X1.3026 C0.2687 Z0.6 F59.055
Z0.2
Z0.0394 F100.
Z-1.302
X1.2026 F40.
G03 X1.1026 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.2026 C-0.2687 I0.05 J0.
G01 X1.3026
X1.2466 C0.2687
X1.1466
G03 X1.0466 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.1466 C-0.2687 I0.05 J0.
G01 X1.2466
X1.2266 C0.2687
X1.1266
G03 X1.0266 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.1266 C-0.2687 I0.05 J0.
G01 X1.2266
Z0.2 F59.055
X-1.3026
Z0.0394 F100.
Z-1.302
X-1.2026 F40.
G03 X-1.1026 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.2026 C0.2687 I-0.05 J0.
G01 X-1.3026
X-1.2466 C-0.2687
X-1.1466
G03 X-1.0466 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.1466 C0.2687 I-0.05 J0.
G01 X-1.2466
X-1.2266 C-0.2687
X-1.1266
G03 X-1.0266 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.1266 C0.2687 I-0.05 J0.
G01 X-1.2266
Z0.6 F59.055
G13.1

(2D CONTOUR1 4)
G00 C0.
G12.1
G01 X-1.3466 C-0.2687 Z0.6 F59.055
Z0.2
Z0.0394 F100.
Z-1.352
X-1.2466 F40.
G03 X-1.1466 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.2466 C0.2687 I-0.05 J0.
G01 X-1.3466
X-1.3266 C-0.2687
X-1.2266
G03 X-1.1266 C-0.2187 I0. J0.05
G01 C0.2187
G03 X-1.2266 C0.2687 I-0.05 J0.
G01 X-1.3266
Z0.2 F59.055
X1.3466
Z0.0394 F100.
Z-1.352
X1.2466 F40.
G03 X1.1466 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.2466 C-0.2687 I0.05 J0.
G01 X1.3466
X1.3266 C0.2687
X1.2266
G03 X1.1266 C0.2187 I0. J-0.05
G01 C-0.2187
G03 X1.2266 C-0.2687 I0.05 J0.
G01 X1.3266
Z0.6 F59.055
G13.1
M05
M69
M46
M09
G00 G28 U0.
G28 W0.
M01

N8(PART1)
G00 G28 U0.
G28 W0.
M05
M69
G54
G99 G18 M46
G50 S1000
T0505
M08
G97 S1000 M03
G00 Z-1.466
X0.7
G96 S200 M03
X0.519
G01 X0.447 F0.001
X0.519
G00 Z-1.4366
G01 X0.4696 Z-1.4613
G03 X0.447 Z-1.466 I-0.0113 K0.0113
G01 X-0.036
G00 X0.519
X0.7
M05
M09
G00 G28 U0.
G28 W0.
M1

N9 (BAR PULLER);
M05;
G54;
T1010;
G0 Z0.0;
X3.0;
G98 (FEED PER MINUTE);
G01 X0.0 F20.;
M11 (OPEN CHUCK);
G04 U1.0 (DWELL TO OPEN CHUCK);
G01 W1.466 F30. (PULL IN Z+);
M10 (CLAMP CHUCK);
G01 X3. F30.;


G00 G28 U0.
G28 W0.
M46

/M99
M30
%
 
Make your puller program the main and call the part program from the main with a G98/G99. That way you can put the # of repeats in the puller program on the G98 line. Keeps things simple. Not very elegant, but its quick and foolproof.
 
What problems are you having with the M98 sub routine call? It’s something definitely worth figuring out and understanding. I’m sure some people here can help you if you give us an example of what you tried or what’s confusing you.
 
Make your puller program the main and call the part program from the main with a G98/G99. That way you can put the # of repeats in the puller program on the G98 line. Keeps things simple. Not very elegant, but its quick and foolproof.
L20 in the M98 block would repeat the called program 20 times (M98 Pxxxx L20)
M98 20xxxx also would do the same thing.
What problems are you having with the M98 sub routine call? It’s something definitely worth figuring out and understanding. I’m sure some people here can help you if you give us an example of what you tried or what’s confusing you.
I kind of understand that I should put this in one simple program to call another program from there 20 times. But it is confusing me exactly. Where goes what and wen it gets back to beginning of the program. If you could drop here like an example of a code how exactly I should write the code and name the program and call another program I would really appreciate that guys. Sorry, sounds so simple, but still.
 
I used a very simple program for our Victor lathe. Main program called the sub "N" times and then just opened the chuck and M30 at the end. The only thing about this sort of logic is restarting half way down a bar if an insert breaks. If I knew how much bar was remaining I could just edit the main program to reflect on the number of parts that could be made and then put the main repeat call back to that for a full bar. Since this machine had no bar feeder I used to cut bars to 28" length for five 5.0" long parts which allowed for partoff kerf plus a short 2" scrap stub at the program end.
 
I kind of understand that I should put this in one simple program to call another program from there 20 times. But it is confusing me exactly. Where goes what and wen it gets back to beginning of the program. If you could drop here like an example of a code how exactly I should write the code and name the program and call another program I would really appreciate that guys. Sorry, sounds so simple, but still.


Are you sure that you don't have a counter available on the control?
Most are likely optioned with one...

On a Fanuc (since you didn't bother to let us know what control you are working with)

Go to SETTINGS page (will have Parameter Write Enable at the top of page)
Page down 2 pages.
You should have a counter there.
Depending on the model, you could even have the counter display on the POSition page.


A counter, whether an actual displayed counter or one that you enable via a macro statement, will be by far better than a loop counter. If you stop mid cycle on a loop counter, you need to know where you stopped and reset your M98 statement to the new number left in the bar - if you know it.

With the counter - of either type, you doo not start over at each green button push.


I guess you would need to have a "repeat" button somewhere to make that work as well, but I would like to think that any normal lathe would have that?


----------------------

Think Snow Eh!
Ox
 
Are you sure that you don't have a counter available on the control?
Most are likely optioned with one...

On a Fanuc (since you didn't bother to let us know what control you are working with)

Go to SETTINGS page (will have Parameter Write Enable at the top of page)
Page down 2 pages.
You should have a counter there.
Depending on the model, you could even have the counter display on the POSition page.


A counter, whether an actual displayed counter or one that you enable via a macro statement, will be by far better than a loop counter. If you stop mid cycle on a loop counter, you need to know where you stopped and reset your M98 statement to the new number left in the bar - if you know it.

With the counter - of either type, you doo not start over at each green button push.


I guess you would need to have a "repeat" button somewhere to make that work as well, but I would like to think that any normal lathe would have that?


----------------------

Think Snow Eh!
Ox
Thank you very much!
I didn't think about particular control. I have Mitsubishi (Mapps) and Fanuc controls on lathes, I'll Definitely take a look in there for this counter (I'm sure I have it, I just never used it before.)
 
With the programming I suggested earlier, the counter records the number of M30's in a shift. So in my case there would be five times as many parts as the counter would display.
 
Make sure that M30 has EOB with it; otherwise, the part may not be counted.
M30 without EOB may not throw an alarm.
 
you can always use a macro as a counter
#500 = [#500 +1]
at the end of your sub program
of course change that # to whatever format your control uses and be sure to zero out the macro before beginning.
 








 
Back
Top