CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Machine Controllers Software and Solutions > LinuxCNC (formerly EMC2)


LinuxCNC (formerly EMC2) Discuss LinuxCNC (formerly EMC2) Controlers here!


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 06-22-2010, 01:28 PM
 
Join Date: Oct 2005
Location: US
Posts: 1,220
MrWild is on a distinguished road
Question Gcode sub program example needed

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
Reply With Quote

  #2   Ban this user!
Old 06-23-2010, 03:18 PM
 
Join Date: Oct 2005
Location: US
Posts: 1,220
MrWild is on a distinguished road

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.
Reply With Quote

  #3   Ban this user!
Old 06-23-2010, 05:00 PM
 
Join Date: Feb 2006
Location: United States
Posts: 273
dpuch is on a distinguished road

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.
Reply With Quote

  #4   Ban this user!
Old 06-23-2010, 05:28 PM
 
Join Date: Oct 2005
Location: US
Posts: 1,220
MrWild is on a distinguished road

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.
Reply With Quote

  #5   Ban this user!
Old 06-23-2010, 10:13 PM
 
Join Date: Feb 2006
Location: United States
Posts: 273
dpuch is on a distinguished road

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.
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 06-25-2010, 01:31 AM
 
Join Date: May 2005
Location: canada
Posts: 1,149
cyclestart is on a distinguished road

example:

main program:
Code:
G00 x1 y1 z.25
o123 call
G00 X2
o123 call
m2
subprogram:
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
main program can be what-ever-name.ngc
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.
Reply With Quote

  #7   Ban this user!
Old 07-15-2010, 03:56 AM
 
Join Date: Mar 2010
Location: UK
Posts: 4
ArcEye is on a distinguished road
Sub Program example

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
Attached Files
File Type: txt G71_Linear_Template.ngc.txt‎ (2.4 KB, 123 views)
File Type: txt 710.ngc.txt‎ (965 Bytes, 110 views)
Reply With Quote

  #8   Ban this user!
Old 07-22-2010, 08:49 PM
 
Join Date: Oct 2005
Location: US
Posts: 1,220
MrWild is on a distinguished road

Originally Posted by ArcEye View Post
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.

regards

ArcEye
WOW. My G-code text book is much too basic. Where might I find a book that tells and explains what each line. and word represents? I can write snfd proof G-code, but this is different than Gwords telling do this and do that. My bok defines a sub program as another g-code string of move.

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.
Reply With Quote

  #9   Ban this user!
Old 07-22-2010, 10:59 PM
 
Join Date: Feb 2006
Location: United States
Posts: 273
dpuch is on a distinguished road

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
A more advanced example that uses the two numbers in the call line to change the lengths of the rectangle each time it is called.
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
Remember EMC2 needs the sub to be BEFORE the call, or in a separate file like ArcEye's attachements
Reply With Quote

  #10   Ban this user!
Old 07-23-2010, 02:40 AM
 
Join Date: Mar 2010
Location: UK
Posts: 4
ArcEye is on a distinguished road
Learning GCode

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
Reply With Quote

Sponsored Links
  #11   Ban this user!
Old 09-01-2010, 05:37 AM
 
Join Date: Jan 2008
Location: UNITED STATES
Posts: 6
piasdom is on a distinguished road

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)
Reply With Quote

  #12   Ban this user!
Old 09-01-2010, 01:07 PM
 
Join Date: Feb 2006
Location: United States
Posts: 273
dpuch is on a distinguished road

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

Originally Posted by piasdom View Post
%
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


... snip

(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>

... snip

m2
%
Reply With Quote

Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


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




All times are GMT -5. The time now is 04:56 AM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361