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-10-2007, 05:10 AM
 
Join Date: Feb 2007
Location: UK
Posts: 26
watchman is on a distinguished road
EMC and Subroutines?

Hi,
I'm new to EMC2 and have a problem. I don't understand how I can use a subroutine in the g-code supported by EMC. What I am trying to do is grind a part which is mounted vertically on a rotary table ('C' axis) and I want to grind a diameter, step down nearly the width of the grinding wheel and repeat the grinding to diameter a number of times (there is a good reason for wanting to do it this way rather than turning the diameters!). So, what I would like to create is a subroutine which would take care of the grinding to diameter part (and preferably be able to accept different final diameters). Reading the EMC2 documentation I guess that G81 wouldn't do but that some form of 'O' routine might - the only problem is that I don't understand how the 'O' routine is supposed to work or how it is called from the main program - other documentation seems to suggest G98 but this doesn't seem to be supported by EMC2. Can anyone offer (simplified) words of wisdom please? Thanks, Ian
Reply With Quote

  #2   Ban this user!
Old 06-10-2007, 09:02 AM
 
Join Date: Sep 2004
Location: USA
Posts: 147
Dan Falck is on a distinguished road
EMC2 subroutines

Try something like this:

%
(SUBROUTINE EXAMPLE)

o100 sub
G02 X-.5 Y-0 I-.5 J0
G02 X.5 Y-0 I.5 J0
o100 endsub

G54
G01 X.5 Y0 Z1. F50.


G1 Z-.25
o100 call
G1 z-.5
o100 call
G1 z-.75
o100 call


G0 Z1.
M30
%

Notice that I put the subroutine at the top of the program. I read in the user's manual (page 153) that subs had to preceed the code that calls them.
I hope this helps you out.
Dan
Reply With Quote

  #3   Ban this user!
Old 06-10-2007, 03:17 PM
 
Join Date: May 2005
Location: canada
Posts: 1,149
cyclestart is on a distinguished road

Originally Posted by watchman View Post
Hi,
G98 but this doesn't seem to be supported by EMC2.
EMC2 does support G98, at least with code G81. Just loaded a drill program to double check. Not sure if there is a problem with G98/G99 with other canned cycles. Maybe the problem is with the height of the initial approach movement or the use of G90/G91 ?

Edit/ Took the time to read the post more closely. This isn't a job for a canned cycle.

Last edited by cyclestart; 06-10-2007 at 04:57 PM.
Reply With Quote

  #4   Ban this user!
Old 06-11-2007, 04:33 AM
 
Join Date: Feb 2007
Location: UK
Posts: 26
watchman is on a distinguished road

Thanks,
I did find a bit more in the EMC WIKI and made a script as below..
%
#1 = 0.2 (finished diameter)
#2 = 0.05 (feed step size)
#3 = 1 (total depth)
#4 = 0.1 (safe X)
#5 = 1.4 (stock diameter)
#6 = 0.5 (grinding disk thickness)
#7=#6
#8 = [[[#5-#1]/2]/#2] (no. of turns of A axis to final diameter)
#9 = [#3/#6]+1 (no. of steps down to finished depth)
#10 = [#3/#9] (step size)
#11 = 0 (counter)

o100 do
G0 Z[0 - #10]
G0 A[#8*360] X[[[#5] - [#1]] /2]
G0 X[#4]
#11 = [[#11] + 1]

o100 while [[ #11 * #10] LT #3]


o200 sub
G0 Y5.0
G0 X-0.565
G1 Y-5.0 F 3.0
G0 A180
G1 Y5.0 F3.0
G0 Y0.000
G1 A180 F15
o200 endsub

N001 G21 G90 G40 G49
N002 o100 call [0.20] [0.04] [1.00]
N003 o100 call [0.27] [0.05] [2.00]
N004 G0 Z-3.3
N005 o200 call
N006 G0 Z-3.8
N007 o200 call
N008 G0 X0.1
N009 G0 Z-3.47
N010 o100 call [0.27] [0.05] [2.74]
N011 M0
N012 G0 Z-6.23
N013 o200 call
N014 o100 call [0.20] [0.04] [1.00]
N015 o100 call [0.1] [0.04] [0.5]
N016 G0 X40
%

I do have a problem with this, however, that I can't understand..
When I try to load it into EMC2, I get an error message saying 'Bad character near line 34' - this appears to be the line numbered N002 - the first subroutine call. I copied the format of this line directly from the WIKI and I've looked at it many times without seeing the problem - any ideas? Thanks, Ian
Reply With Quote

  #5  
Old 06-11-2007, 01:23 PM
Gold Member
 
Join Date: Dec 2004
Location: Newtown, CT, USA
Age: 68
Posts: 517
lerman is on a distinguished road

I believe you can't have line numbers on lines with o-words.

Ken
__________________
Kenneth Lerman
55 Main Street
Newtown, CT 06470
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 06-11-2007, 04:41 PM
 
Join Date: Feb 2007
Location: UK
Posts: 26
watchman is on a distinguished road

Thanks Ken - you are correct. I removed them from the script and EMC2 loaded it - then wouldn't run - just sat there looking stupid....dohhhh!!
Ian
Reply With Quote

  #7   Ban this user!
Old 06-12-2007, 08:17 AM
 
Join Date: May 2005
Location: canada
Posts: 1,149
cyclestart is on a distinguished road

There might be a problem with your use of the while loop. That program tries to load here in axis but seems to get caught in some type of infinite loop. Probably it either it doesn't have a break or can't reach it. My best guess being not much of a script writer.

I've written a few parametrics but not with the type of loops and conditionals found in the wiki.
Reply With Quote

  #8   Ban this user!
Old 06-12-2007, 12:40 PM
acondit's Avatar  
Join Date: Apr 2005
Location: USA
Posts: 1,774
acondit is on a distinguished road

Originally Posted by watchman View Post
Thanks,
I did find a bit more in the EMC WIKI and made a script as below..
%
#1 = 0.2 (finished diameter)
#2 = 0.05 (feed step size)
#3 = 1 (total depth)
#4 = 0.1 (safe X)
#5 = 1.4 (stock diameter)
#6 = 0.5 (grinding disk thickness)
#7=#6
#8 = [[[#5-#1]/2]/#2] (no. of turns of A axis to final diameter)
#9 = [#3/#6]+1 (no. of steps down to finished depth)
#10 = [#3/#9] (step size)
#11 = 0 (counter)

o100 do
G0 Z[0 - #10]
G0 A[#8*360] X[[[#5] - [#1]] /2]
G0 X[#4]
#11 = [[#11] + 1]

o100 while [[ #11 * #10] LT #3]


o200 sub
G0 Y5.0
G0 X-0.565
G1 Y-5.0 F 3.0
G0 A180
G1 Y5.0 F3.0
G0 Y0.000
G1 A180 F15
o200 endsub

N001 G21 G90 G40 G49
N002 o100 call [0.20] [0.04] [1.00]
N003 o100 call [0.27] [0.05] [2.00]
N004 G0 Z-3.3
N005 o200 call
N006 G0 Z-3.8
N007 o200 call
N008 G0 X0.1
N009 G0 Z-3.47
N010 o100 call [0.27] [0.05] [2.74]
N011 M0
N012 G0 Z-6.23
N013 o200 call
N014 o100 call [0.20] [0.04] [1.00]
N015 o100 call [0.1] [0.04] [0.5]
N016 G0 X40
%

I do have a problem with this, however, that I can't understand..
When I try to load it into EMC2, I get an error message saying 'Bad character near line 34' - this appears to be the line numbered N002 - the first subroutine call. I copied the format of this line directly from the WIKI and I've looked at it many times without seeing the problem - any ideas? Thanks, Ian
%

o100 sub [1] [2] [3]
(#1 = 0.2) (finished diameter)
(#2 = 0.05) (feed step size)
(#3 = 1) (total depth)
#4 = 0.1 (safe X)
#5 = 1.4 (stock diameter)
#6 = 0.5 (grinding disk thickness)
#7=#6
#8 = [[[#5-#1]/2]/#2] (no. of turns of A axis to final diameter)
#9 = [#3/#6]+1 (no. of steps down to finished depth)
#10 = [#3/#9] (step size)
#11 = 0 (counter)
o101 do
G0 Z[0 - #10]
G0 A[#8*360] X[[[#5] - [#1]] /2]
G0 X[#4]
#11 = [[#11] + 1]

o101 while [[ #11 * #10] LT #3]
o100 endsub

o200 sub
G0 Y5.0
G0 X-0.565
G1 Y-5.0 F 3.0
G0 A180
G1 Y5.0 F3.0
G0 Y0.000
G1 A180 F15
o200 endsub

N001 G21 G90 G40 G49
N002 o100 call [0.20] [0.04] [1.00]
N003 o100 call [0.27] [0.05] [2.00]
N004 G0 Z-3.3
N005 o200 call
N006 G0 Z-3.8
N007 o200 call
N008 G0 X0.1
N009 G0 Z-3.47
N010 o100 call [0.27] [0.05] [2.74]
N011 M0
N012 G0 Z-6.23
N013 o200 call
N014 o100 call [0.20] [0.04] [1.00]
N015 o100 call [0.1] [0.04] [0.5]
N016 G0 X40
%

I made a couple of changes in your code. It still has a problem that I haven't taken the time to fix. It is reporting a divide by zero error in line 11. You hadn't specified O100 as a subroutine. So I changed your do while loop to O101 and wrapped it in a O100 sub -- endsub pair. You specified three parameters in your calling sequence, but didn't specify the formal parameters in the sub routine. I moved the variables 1 thru 11 inside the subroutine and I commented out #1, #2 and #3 since they are passed in to the subroutine. If they are needed, you need to change them so they don't conflict with the parameters that are passed in at the call.

Alan
__________________
http://www.alansmachineworks.com
Reply With Quote

  #9   Ban this user!
Old 06-14-2007, 05:24 PM
 
Join Date: Feb 2007
Location: UK
Posts: 26
watchman is on a distinguished road

Thanks, I'll try Alan's amended routine as soon as I get a minute.. Ian
Reply With Quote

  #10   Ban this user!
Old 06-17-2007, 02:30 PM
 
Join Date: May 2005
Location: canada
Posts: 1,149
cyclestart is on a distinguished road

Originally Posted by watchman View Post
Thanks, I'll try Alan's amended routine as soon as I get a minute.. Ian
So how did you get on with this?

This thread was an eye opener for me. Like a 2 year old with a newly learned word, just can't resist trying to show off.
**while the more senior members snicker no doubt**

As I haven't quite grasped what you're doing, I expanded on Dan Falck's post.

The way I would have done this orginally
Code:
%
#100= 1000 (RPM)
#101= 1    (CIRCLE RADIUS)
#102= .375    (CUTTER RADIUS)
#103= 30   (FEED)
#104= 2    (X CENTER)
#105= 2    (Y CENTER)
#106= -.25 (DEPTH)


o100 sub
#107= [#101+#102] (PATH OF CUTTER)
G00 X#104 Y[[2*#102]+[#107+#105]]
G01 Z#106 F#103
G03 X#104 Y[#107+#105] R#102
G02 X[#107+#104] Y#105 R#107
X#104 Y[[-1*#107]+#105] R#107
X[[-1*#107]+#104] Y#105 R#107
X#104 Y[#107+#105] R#107
G03 X#104 Y[[2*#102]+[#107+#105]] R#102
o100 endsub

S#100 M03
G54 G00 X#104 Y[[2*#102]+[#107+#105]]
Z.1
o100 call
#101=.8
o100 call
#106=-.5
#101=1
o100 call
#101=.8
o100 call
G00 Z2
M02
%
using the "while" conditional trick
Code:
%
([1=first_cut.r] [2=cutter.r] [3=feed] [4=x center] [5=y center] [6=depth] [7=stepover] [8=finish.r])
o100 sub
o101 while [#8 LE #1]
#10= [#1+#2] (PATH OF CUTTER)
G00 X#4 Y[[2*#2]+[#10+#5]]
G01 Z#6 F#3
G03 X#4 Y[#10+#5] R#2
G02 X[#10+#4] Y#5 R#10
X#4 Y[[-1*#10]+#5] R#10
X[[-1*#10]+#4] Y#5 R#10
X#4 Y[#10+#5] R#10
G03 X#4 Y[[2*#2]+[#10+#5]] R#2
#1=[#1-#7]
o101 endwhile
o100 endsub

S1000 M03
G00 Z1
o100 call [1] [.375] [30] [0] [0] [-.25] [.1] [.8]
o100 call [1] [.375] [30] [0] [0] [-.5] [.1] [.6]
G00 Z2
M02
%
These programs are probably buggy as hell, but sure were fun to write.

Maybe there's something you can use in above somehow.
Reply With Quote

Sponsored Links
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
Calling a subprogram that has subroutines Shizzlemah Fadal 6 03-25-2007 09:04 PM
Oi subroutines help mishikwest Fanuc 1 08-01-2006 05:17 PM
Fanuc 15m Subroutines BROCD Fanuc 11 02-27-2006 07:04 AM
Subroutines in Mill Master Pro truline G-Code Programing 0 10-08-2005 12:37 AM




All times are GMT -5. The time now is 02:53 PM.





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