586,111 active members*
3,584 visitors online*
Register for free
Login
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2007
    Posts
    29

    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

  2. #2
    Join Date
    Sep 2004
    Posts
    149

    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

  3. #3
    Join Date
    May 2005
    Posts
    1662
    Quote 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.

  4. #4
    Join Date
    Feb 2007
    Posts
    29
    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

  5. #5
    Join Date
    Dec 2004
    Posts
    524
    I believe you can't have line numbers on lines with o-words.

    Ken
    Kenneth Lerman
    55 Main Street
    Newtown, CT 06470

  6. #6
    Join Date
    Feb 2007
    Posts
    29
    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

  7. #7
    Join Date
    May 2005
    Posts
    1662
    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.

  8. #8
    Join Date
    Apr 2005
    Posts
    1778
    Quote 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

  9. #9
    Join Date
    Feb 2007
    Posts
    29
    Thanks, I'll try Alan's amended routine as soon as I get a minute.. Ian

  10. #10
    Join Date
    May 2005
    Posts
    1662
    Quote 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.

Similar Threads

  1. Calling a subprogram that has subroutines
    By Shizzlemah in forum Fadal
    Replies: 6
    Last Post: 03-26-2007, 03:04 AM
  2. Oi subroutines help
    By mishikwest in forum Fanuc
    Replies: 1
    Last Post: 08-01-2006, 11:17 PM
  3. Fanuc 15m Subroutines
    By BROCD in forum Fanuc
    Replies: 11
    Last Post: 02-27-2006, 02:04 PM
  4. Subroutines in Mill Master Pro
    By truline in forum G-Code Programing
    Replies: 0
    Last Post: 10-08-2005, 06:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •