![]() | |
| Home Page | Mark Forums Read | Today's Posts | My Replies | Classifieds | Reviews | Photo Gallery | Web Links | Share Files | Advertise With Us | Ad List |
| |||||||
| LinuxCNC (formerly EMC2) Discuss LinuxCNC (formerly EMC2) Controlers here! |
| This forum is sponsored by: |
![]() |
| | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
| |||
| |||
| Could someone post an example of a nested sub program? I know that there are su programs for drilling and etc., but I'm interested in how the sub program is defined, labeled, called, and ended. It need not be a large program, just that it contains how to do sub programs in EMC2. Thanks |
|
#2
| |||
| |||
| More information. People say that EMC2 uses the same commands as a Fanuc control, yet EMC2 doesn't recognize M98 and M99. I've read over and over about O100 or 0100 labeled subprograms, but still don't understand the full workings of how they relate to say a Fanuc6M post that uses M98 to call, and M99 to end subprogram. EMC2 G98 and G99 don't seem to be the same commands. The EMC2 manual and quick G-code guide do not give much in the way of examples, and my tech school book doesn't use EMC2's protocols for G-code writing. My Anilam M and Fanuc Posts in Dolphin Part Master does fine for none subprogram posts, but the minute I start getting involved with subprograms there are problems. I have the PP manual for Partmaster posts, but need subprogram example to make the changes needed. |
|
#3
| |||
| |||
| looking at the EMC manual it uses O### <-- any unique number as the sub label followed by "sub, endsub, call" instead of M98, M99 that fanuc uses. It looks like any O number can be used, not just 100 or 101 like in the examples. It also allows calling subs in separate files. In that case the O is followed by the file name. The sub program still has to have O### sub, and endsub lines. |
|
#4
| |||
| |||
| Something I don't understand about the examples. When a notation is made at the start of program , () is used so Axis knows it isn't part of the program. In all but the first example they have constants(?) inside of (). Like; o200 sub (1=x ... 2=i ... ) and when I look down at the rest of the program it seems that the () data IS being looked at by Axis. I would use the G-code basic tutorial in the WIKI, but it isn't more than an outline of possible chapters with no information and the last update was over two years ago. The G-code program I'm trying to make has two .64 dia pockets .76 deep 3" away from each other on Y axis, and a border (boss) around them (part of a dust boot). The boss is machined semi finish, and finish passes using separate depths as roughing clears all surrounding material and i don't want that. The loop would be three steps at deeper depth on the boss, and holes. My text book just assigns a name (number) to a sub g-code program for a call. move to position, call sub "whatever" which has an incremental modal g-coded program, finish the sub cut, end sub, move in absolute, and repeat. The examples in the advanced coding is well,... advanced and uses a different (macro?) format. So looking at what my book says is way different from what I'm seeing. |
|
#5
| |||
| |||
| The variables are set by the call line, not the beginning of the sub. Also use [] not () O115 call [1] [2] [37] [3.2] inside: O115 sub (#1=1, #2=2, #3=3,7 #4=3.2) .... O115 endsub Note: the sub code needs to be before the call line in your program unless it is called from a separate file. It has to be read first, but it will not execute until you use the call command. |
| Sponsored Links |
|
#6
| |||
| |||
| example: main program: Code: G00 x1 y1 z.25 o123 call G00 X2 o123 call m2 Code: o123 sub G91 G01 z-.5 f10 G03 x.5 y0 r.25 f5 x-1 y0 r.5 x1 y0 r.5 x-.5 y0 r.25 G01 z.5 g90 o123 endsub subprogram is 123.ngc Save both programs in the prefix directory set in the .ini file. This is most likely to be home/you/emc2/nc_files Untested and not meant for actual milling
__________________ Anyone who says "It only goes together one way" has no imagination. |
|
#7
| |||
| |||
Hi Don't know if you have got to grips with this yet. Very often you don't actually need to put the subroutine in a separate file, only if the code is to be reusable to other code files. There are 2 examples attached that I use as a psuedo G71 template for linear turning. I have a different one for turning which involves arcs. The decrementing of the X value for each cut is calculated in a separate file '710.ngc' because I use it with other templates. It also shows the use of named parameters, passing parameters in the subroutine call and using the return value parameter. 1 - 30 can be parameters to the call and 31-60 the return values. Named Parameters are a real plus for EMC gcode, make reading the code much easier 2 months later! Hope this is of some assistance. regards ArcEye |
|
#8
| |||
| |||
| I like the way it seems to have addresses, but I haven't learned this style. Heck I didn't even know it existed, being self taught. Knowing would help trouble shoot an EMC2 post I'm playing with. As a work around, its all posted as long hand. Fanuc sub programming isn't the same as EMC2 in all respects. |
|
#9
| |||
| |||
| Sub calls can be a simple path, or complex macro commands. It all depends on the creativity of the programmer. The main reason for simple subs is you only need to change code in 1 place to change every use of the sub. Macros (fancy subs) allow the use of the same code to do varied operations. Again easily changed in the sub, or by the sub call parameters. Two samples might be: Simple g-code that is executed where ever the sub is called Code: o123 call (1 x 1 square) o123 sub (1" square sub) G91 G1 X1.0 F10.0 Y1.0 X0.0 Y0.0 G90 o123 subend Code: o123 call [2.0] [1.5] (2 x 1.5 rectangle) o123 call [1.0] [2.5] (1 x 2.5 rectangle) o123 sub (rectangle macro) G91 G1 X#1 F10.0 Y#2 X0.0 Y0.0 G90 o123 subend |
|
#10
| |||
| |||
Hi All the information needed is in the wikis and documentation, the trouble is that you have to know what it is you need to know, sometimes a chicken and egg situation. I have not found any really useful books, but I can recommend the articles in Digital Machinist magazine by Ed Nisley. He uses EMC and in particular uses named parameters, sub-routines etc that are specific to EMC. His series started some while back but back issues are available quite cheaply from Village Press. The only issue I have with Digital Machinist, is that the other articles tend to be hugely wordy and padded. I don't know if this is an American trait or just this magazine. I for one do not need 6 pages and a blow by blow description of drilling operations interspersed with workshop reminiscences, where 1 page and 2 photos would have made all abundantly clear. That said, there are a couple of writers who make the purchase worthwhile. Good Luck ArcEye |
| Sponsored Links |
|
#11
| |||
| |||
| fairly new to emc2 and newer still to making complex sub. but i hope this helps. % g17 g20 g40 g49 g54 g80 g90 g94 (Mill Four Ports) #<_plunge> = 3 #<_startfeed> = 3.5 #<_regfeed> = 5 #<_finfeed> = 8 #<_fastfeed> = 12 #<_safeheight> = .2 #<_start> = .05 #<_end> = .06 #<_.69step> = -.69 #<_.8depth> = -.8 o100 sub (roughing top) g1 f#<_startfeed> x#<_start> y#<_start> y2.27 x1.2 y#<_start> x#<_start> x.03 y.03 f#<_regfeed> y2.29 x1.22 y.03 x.03 x#<_end> y#<_end> o100 endsub o101 sub (top cleanup) f#<_regfeed> x.15 y .15 x1.05 y2.15 x.15 y.15 x.3 y.3 x.9 y2 x.3 y.3 x.45 y.45 x.75 y1.85 x.45 y.45 x.6 y.6 y1.7 o101 endsub o102 sub (finishing top) g1 f#<_regfeed> x.022 y.022 y2.293 x1.228 y.022 x.022 x.015 y.015 y2.3 x1.235 y.015 x.015 x.01 y.01 y2.305 x1.24 y.01 x.01 x.005 y.005 y2.31 x1.245 y.005 x.005 x0 y0 y2.315 x1.25 y0 x0 f#<_fastfeed> y2.315 x1.25 y0 x0 g0 x#<_end> y#<_end> o102 endsub o103 sub (roughing Step) g1 f#<_startfeed> x.02 y.02 x.01 y.01 y2.02 x.91 y2.305 x1.24 y1.76 x.99 y.09 x1.24 y.01 x.01 (step cleanup) x.15 y.15 x.8 y1.85 x1.075 y2.165 y1.9 x.15 y.25 x.65 y1.7 x.3 y.35 x.475 y1.5 o103 endsub o104 sub (finish step) g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_regfeed> z#<_.8depth> x.005 y.005 y2.025 x.9 y2.31 x1.245 y1.75 x1 y.1 x1.245 y.005 x.005 x0 y0 f#<_finfeed> y2.03 x.9 y2.315 x1.25 y1.75 x1 y.1 x1.25 y0 x0 f#<_fastfeed> y2.03 x.9 y2.315 x1.25 y1.75 x1 y.1 x1.25 y0 x0 g0 x#<_end> y#<_end> o104 endsub o105 sub (tool change) g0 z2 g49 g80 g0 x3.8 y2 o105 endsub o106 sub (0.0 run on top) g1 f#<_fastfeed> x.01 y.01 z-.68 x0 y0 y2.315 x1.25 y0 x0 g0 x#<_end> y#<_end> z#<_safeheight> o106 endsub ( o107 sub) (O102 if [#<_.69step> lt .68]) ( o100 call [10]) (O102 else) ( o101 call) (O102 endif) ( o107 endsub) (program start) G10 L2 P1 x0 y0 z0 (p1 = g54, L2? L1? L10? L20?) G10 L2 P2 x1.9 y0 z0 (p2 = g55 ) G10 L2 P3 x3.8 y0 z0 (p3 = g56 ) G10 L2 P4 x5.7 y0 z0 (p4 = g57,p5 = g58,etc...g59.3) o105 call g28.1 (o107 call) g54 (g54) g64 p.005 q0 g0 x#<_start> y#<_start> z#<_safeheight> m6 t4 (msg, first port) (disable / to mill from blank stock) g1 f#<_regfeed> z-.1 /o100 call x#<_start> y#<_start> g1 f#<_plunge> z-.2 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.3 /o100 call) x#<_start> y#<_start> g1 f#<_plunge> z-.4 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.5 /o100 call x#<_start> y#<_start> g1 f#<_plunge> z-.6 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.675 o100 call x#<_start> y#<_start> g1 f#<_plunge> z#<_.69step> o100 call o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z#<_.69step> o102 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.78 o103 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z#<_.8depth> o103 call o104 call o106 call g0 z#<_safeheight> g55 (g55) (msg, second port, s to continue) x#<_start> y#<_start> m1 (alternate stop) g1 f#<_regfeed> z-.1 /o100 call x#<_start> y#<_start> g1 f#<_plunge> z-.2 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.3 /o100 call) x#<_start> y#<_start> g1 f#<_plunge> z-.4 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.5 /o100 call x#<_start> y#<_start> g1 f#<_plunge> z-.6 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.675 o100 call x#<_start> y#<_start> g1 f#<_plunge> z#<_.69step> o100 call o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z#<_.69step> o102 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.78 o103 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z#<_.8depth> o103 call o104 call o106 call g0 z#<_safeheight> g56 (g56) (msg,third port, s to continue) x#<_start> y#<_start> m1 (alternate stop) g1 f#<_regfeed> z-.1 /o100 call x#<_start> y#<_start> g1 f#<_plunge> z-.2 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.3 /o100 call) x#<_start> y#<_start> g1 f#<_plunge> z-.4 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.5 /o100 call x#<_start> y#<_start> g1 f#<_plunge> z-.6 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.675 o100 call x#<_start> y#<_start> g1 f#<_plunge> z#<_.69step> o100 call o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z#<_.69step> o102 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.78 o103 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z#<_.8depth> o103 call o104 call o106 call g0 z#<_safeheight> g57 (g57) (msg,fourth port, s to continue) x#<_start> y#<_start> m1 (alternate stop) g1 f#<_regfeed> z-.1 /o100 call x#<_start> y#<_start> g1 f#<_plunge> z-.2 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.3 /o100 call) x#<_start> y#<_start> g1 f#<_plunge> z-.4 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.5 /o100 call x#<_start> y#<_start> g1 f#<_plunge> z-.6 o100 call /o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.675 o100 call x#<_start> y#<_start> g1 f#<_plunge> z#<_.69step> o100 call o101 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z#<_.69step> o102 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z-.78 o103 call g0 z#<_safeheight> x#<_start> y#<_start> g1 f#<_plunge> z#<_.8depth> o103 call o104 call o106 call g0 z#<_safeheight> (msg,Complete) g40 g80 g54 g92.1 m6 t0 g28 m2 % o100b sub (roughing top) o101b sub (roughing Step) o102b sub (finish step) o103b sub (finishing top) o104b sub (top cleanup) o105b sub (safe position) o106b sub (0.0 run on top) |
|
#12
| |||
| |||
| A nice real world example. Because it is long though, I wanted to edit your example to show the different parts better. Note the order. Also note this example is using nicely named global variables, and not passing local only variables in the sub call command as I posted above. Start of program set variables before any use define sub programs Main program with sub calls
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help needed for incremental line numbering of a Gcode program | yaji63 | G-Code Programing | 14 | 06-25-2010 02:12 PM |
| Need Help!- Direction needed with BobCad Pro Art X to GCode | tamedia1 | BobCad-Cam | 1 | 03-23-2010 03:47 AM |
| Warmup Program Gcode | Phife | DIY-CNC Router Table Machines | 6 | 01-08-2010 07:45 PM |
| What program builds 3D Model from GCode? | cjjonesarmory | General CAM Discussion | 2 | 07-28-2009 02:33 PM |
| cheap bitmap to gcode program | balsaman | DIY-CNC Router Table Machines | 29 | 07-28-2003 01:04 PM |