Hello Guest it is March 28, 2024, 05:05:04 AM

Author Topic: subroutine  (Read 5886 times)

0 Members and 1 Guest are viewing this topic.

subroutine
« on: March 09, 2007, 06:43:32 PM »
OK, so you're about to discover how new I am. Can someone please direct me to where I can learn to convert a 26 line G-code I've written into a subroutine, how to call it up & start it in 14 different start positions on my Router table please & do I just write the G-code for the new start position after the end of each subroutine code followed by the subroutine code again ? I've found the section on subroutines in the manual but not the description for dummies like me on how to write it.
Keep it simple please as I'm not very bright.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: subroutine
« Reply #1 on: March 09, 2007, 08:03:06 PM »
Does this help? It is a quote from one of the Gurus, not me.


Quote
O0001 (MAIN PROGRAM)
G00 X0 Y0 Z0
M98 P2 L5
M30

O0002 (SUB PROGRAM)
G01 X1. A??? F10.
X0 A???
M99

Try this

Graham.

Brett
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline Graham Waterworth

*
  • *
  •  2,668 2,668
  • Yorkshire Dales, England
    • View Profile
Re: subroutine
« Reply #2 on: March 10, 2007, 05:53:04 AM »
Hi plasticbaldy,

You have 2 options with this problem,

1. You code the sub program with incremental moves only. then move to the start points in the main program and call the sub.

2. You code the sub as normal and use G52 X? y? to offset the datum.

e.g.

Option 1.

(main program)

O0001

G21 G40 G00 G99 G17
S1000 M3
G00 G90 X0 Y0 Z5. (FIRST PART POS)
M98 P0002
G00 X25. Y0 (SECOND PART OFFSET 25MM)
M98 P0002
G00 X25. Y25. (THIRD PART OFFSET 25MM X AND 25MM Y)
M98 P0002
G00 X0 Y25. (FORTH PART OFFSET 25MM Y)
M98 P0002
G00 Z150. M5
M30

(SUB PROGRAM)

O0002
G90 G01 Z- 2. F50. ( ABS MOVE)
G91 X5. F150. (INC MOVES)
Y5.
X-5.
Y-5.
G90 G00 Z5. (ABS MOVE)
M99

Option 2.

(main program)

O0001

G21 G40 G00 G99 G17
S1000 M3
G00 G90 X0 Y0 Z5. (FIRST PART POS)
M98 P0002
G52 X25. Y0 Z0 (SECOND PART OFFSET 25MM)
M98 P0002
G52 X25. Y25. Z0 (THIRD PART OFFSET 25MM X AND 25MM Y)
M98 P0002
G52 X0 Y25. Z0 (FORTH PART OFFSET 25MM Y)
M98 P0002
G00 Z150. M5
M30

(SUB PROGRAM)

O0002
G01 Z- 2. F50.
X5. F150.
Y5.
X0
Y0
G00 Z5.
G52 X0 Y0 Z0 (CANCEL OFFSET SHIFT)
M99

The one Brett showed you is close but not quite what you want but a good guide on how to call subs.

Graham.

Without engineers the world stops
Re: subroutine
« Reply #3 on: March 11, 2007, 05:52:08 AM »
Thanks Graham. I'll go try to work this out today. Like I said in my question - I have no experience with this. "You code the sub as normal' is a whole exercise in itself for me. When I 'Load G-Code' do I load the main programme first & the sub after it like you've done ? Can you please direct me to the manual or somewhere where I'll learn correct G-code sequences.
Andy (plasticbaldy)

Offline Graham Waterworth

*
  • *
  •  2,668 2,668
  • Yorkshire Dales, England
    • View Profile
Re: subroutine
« Reply #4 on: March 11, 2007, 06:08:13 AM »
Hi Andy,

the main and sub program are all in one file, the main program first and all the subs follow on.

The main program starts with a program number e.g. O0001 and ends with an M30

The subs start with a program number e.g. O0002 and end with an M99

To call a sub from the main you enter M98 Pnnnn where nnnn is the subs program number less the 'O' e.g. P0002

The format I gave in option 1 and 2 are the standard layout.

______________________________________________________________________________________________

When you program a component you have absolute and incremental programming.

Absolute is where all the dimensions are from a single point on the work piece.

Incremental is where the next dimension is the distance from where the cutter is now.  it can get very confusing as you have to remember where you are all the time.

You can mix absolute and incremental in the same part if needed.

Most of the time you will use absolute.

You can cut and paste the sample code into mach and the sim will show what it is doing.

Send me a drawing and some details of cutters you have and I will do you a program to try.

Graham.
Without engineers the world stops
Re: subroutine
« Reply #5 on: March 11, 2007, 06:30:20 PM »
Thank you Graham. My workshop is currently 4 street blocks from my internet PC. I'll print this & go try it with my subroutine & some absolute value co-ordinates.
You're very patient & helpful. I'll see if Elle McPherson will go around to your place & plant some thank-you kisses on your face.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: subroutine
« Reply #6 on: March 11, 2007, 08:47:03 PM »
LOL, send her my way and I'll write your codes for you. LOL ;D

Brett
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: subroutine
« Reply #7 on: April 20, 2007, 02:35:35 AM »
OK, I seem to have a rudimentary handle on this but I just wrote another tap and on line 540 (the 540 in the centre) it occasionally sends the router to  X+683 instead of the coded X-683. Any ideas on what to do to stop this please ?
N0000 (Combined L & R Fig12 Targets with offset shift)
N0010 (Post processor: Mach2.post)
N0020 (Date: 20/04/2007)
N0030 G21 (Units: Metric)
N0040 G40 G90
N0050 F1
N0060 (Part: ~$Fig12RHmod001)
N0070 (Process: Outside offset 0, Mill/Router, 5 mm diameter, 5 mm Deep)
N0090 M06 T1  (Mill/Router, 5 mm diameter)
N0120 M03 S500
N0125 G00 Z40
N0130 X-325.5000 Y231.0000
N0150 G00 Z0.0000
N0160 Z-15.0000
N0170 G01 X122.0979 F1500
N0180 G02 X125.9975 Y229.9065 I0.0000 J-7.5000
N0190 G01 X329.3996 Y106.0965
N0200 G02 X333.0000 Y99.6900 I-3.8996 J-6.4065
N0210 G01 Y-99.6900
N0220 G02 X329.3996 Y-106.0965 I-7.5000 J0.0000
N0230 G01 X125.9975 Y-229.9065
N0240 G02 X122.0979 Y-231.0000 I-3.8996 J6.4065
N0250 G01 X-325.5000 Y-231.0000
N0260 G02 X-333.0000 Y-223.5000 I0.0000 J7.5000
N0265 G01 Y-216 Z0.0
N0270 G01 Y-137.0000
N0280 G02 X-325.5000 Y-129.5000 I7.5000 J0.0000
N0290 G01 X-267.5000
N0300 G03 X-267.5000 Y-124.5000 I0.0000 J2.5000
N0310 G01 X-325.5000
N0320 G02 X-333.0000 Y-117.0000 I0.0000 J7.5000
N0330 G01 Y-73.5000
N0340 G02 X-325.5000 Y-66.0000 I7.5000 J0.0000
N0350 G01 X-285.5000
N0360 G03 X-285.5000 Y-61.0000 I0.0000 J2.5000
N0370 G01 X-325.5000
N0380 G02 X-333.0000 Y-53.5000 I0.0000 J7.5000
N0390 G01 Y53.5000
N0400 G02 X-325.5000 Y61.0000 I7.5000 J0.0000
N0410 G01 X-285.5000
N0420 G03 X-285.5000 Y66.0000 I0.0000 J2.5000
N0430 G01 X-325.5000
N0440 G02 X-333.0000 Y73.5000 I0.0000 J7.5000
N0450 G01 Y117.0000
N0460 G02 X-325.5000 Y124.5000 I7.5000 J0.0000
N0470 G01 X-267.5000
N0480 G03 X-267.5000 Y129.5000 I0.0000 J2.5000
N0490 G01 X-325.5000
N0500 G02 X-333.0000 Y137.0000 I0.0000 J7.5000
N0550 G01 Y216
N0510 G01 Y223.5000 Z-15.00
N0520 G02 X-325.5000 Y231.0000 I7.5000 J0.0000
N0530 G00 X-325.5 Y231.0 Z0.0

N0540 G52 X-683 Y0.00 (Set Temp Offset)

N0000 (Filename: ~$Fig12LHmod008.tap)
N0010 (Post processor: Mach2.post)
N0020 (Date: 19/04/2007)
N0030 G21 (Units: Metric)
N0040 G40 G90
N0050 F1
N0070 (Process: Outside offset 0, Mill/Router, 5 mm diameter, 5 mm Deep)
N0090 M06 T1  (Mill/Router, 5 mm diameter)
N0130 X333.0000 Y223.5000
N0150 G01 Z-10.00 F1500
N0160 Z-15.0000
N0170 G03 X325.5000 Y231.0000 I-7.5000 J0.0000
N0180 G01 X-122.0979
N0190 G03 X-125.9975 Y229.9065 I0.0000 J-7.5000
N0200 G01 X-329.3996 Y106.0965
N0210 G03 X-333.0000 Y99.6900 I3.8996 J-6.4065
N0220 G01 Y-99.6900
N0230 G03 X-329.3996 Y-106.0965 I7.5000 J0.0000
N0240 G01 X-125.9975 Y-229.9065
N0250 G03 X-122.0979 Y-231.0000 I3.8996 J6.4065
N0260 G01 X325.5000 Y-231.0000
N0270 G03 X333.0000 Y-223.5000 I0.0000 J7.5000
N0275 G01 Y-216 Z0.0
N0280 G01 Y-137.0000 F1500
N0290 G03 X325.5000 Y-129.5000 I-7.5000 J0.0000 F1000
N0300 G01 X267.5000
N0310 G02 X267.5000 Y-124.5000 I0.0000 J2.5000
N0320 G01 X325.5000
N0330 G03 X333.0000 Y-117.0000 I0.0000 J7.5000
N0340 G01 Y-73.5000
N0350 G03 X325.5000 Y-66.0000 I-7.5000 J0.0000
N0360 G01 X285.5000
N0370 G02 X285.5000 Y-61.0000 I0.0000 J2.5000
N0380 G01 X325.5000
N0390 G03 X333.0000 Y-53.5000 I0.0000 J7.5000
N0400 G01 Y53.5000
N0410 G03 X325.5000 Y61.0000 I-7.5000 J0.0000
N0420 G01 X285.5000
N0430 G02 X285.5000 Y66.0000 I0.0000 J2.5000
N0440 G01 X325.5000
N0450 G03 X333.0000 Y73.5000 I0.0000 J7.5000
N0460 G01 Y117.0000
N0470 G03 X325.5000 Y124.5000 I-7.5000 J0.0000
N0480 G01 X267.5000
N0490 G02 X267.5000 Y129.5000 I0.0000 J2.5000
N0500 G01 X325.5000
N0510 G03 X333.0000 Y137.0000 I0.0000 J7.5000
N0515 G01 Y216
N0520 G01 Y225.5000 Z-15
N0530 G00 Z25.0000
N0535 M05


G52 X683 Y0.0 (Cancel Offset Shift)
N0580 Y460
N0590 X-325.5
M30

Offline Graham Waterworth

*
  • *
  •  2,668 2,668
  • Yorkshire Dales, England
    • View Profile
Re: subroutine
« Reply #8 on: April 20, 2007, 02:41:56 AM »
To cancel a G52 shift you enter G52 X0 Y0 Z0

Graham.
Without engineers the world stops