Results 1 to 5 of 5

Thread: Lathe Code for Mill With Subroutine

  1. #1
    Registered
    Join Date
    Jun 2010
    Location
    U.S.A.
    Posts
    10
    Downloads
    0
    Uploads
    0

    Lathe Code for Mill With Subroutine

    I'm trying to hand-code a program to do some turning on my RF-30 mill and I'm trying to wrap my head around subroutines. The program below is for a Mach3 controller and takes a Cut Depth and Cut Length parameter, then loops however many times from the start point.

    I've never written a program by hand before, so I was wondering if any of you see any major flaws with this approach. Cheers, and thanks for any insight.

    Code:
    ( Axle )
    G20 G90 G91.1 G64 G40 G49
    G0 Z0.25
    T0 M6
    G17
    M3 S1900
    G0 Z0
    G1 F5 X.250
    #1=.010 (SUBROUTINE DEPTH)
    #2=1.27 (SUBROUTINE LENGTH)
    M98 P100 L12
    (FINISH PASS)
    G1 F5 X.123
    G1 F17 Z-1.270 X.125 (TAPER SPRING PASS)
    G1 X.350
    M5
    M30
    
    O100
    (TURNING SUBROUTINE)
    G91 (BEGIN INCREMENTAL)
    G1 F5 X[0-#1] (CUT DEPTH)
    G1 F17 Z[0-#2] (CUT LENGTH)
    G1 X#1 (PULL OUT TO START X")
    G0 Z#2 (RAPID TO START Z)
    G1 F7 X[0-#1] (BACK TO START X)
    G90 (END INCREMENTAL)
    M99
    %


  2. #2
    Registered fordav11's Avatar
    Join Date
    Aug 2011
    Location
    Fordaville
    Posts
    1,672
    Downloads
    0
    Uploads
    0
    What kind of machine is this? Normally you can't do 'real' XZ turning on a mill.

    If you have never programmed long hand before why are you over-complicating it by using macro variables? It would be easier to just use long hand code. The sub with incremental values is ok but using macro just makes it harder to understand from the point of view of someone who has never written long hand code before.

    As for problems, you are in G17 (XY plane) and you are cutting XZ plane (G18). It's not a problem here because you are only cutting straight but if you cut an arc with G02/G03 you will get an alarm (wrong plane)

    Also T0 is not valid except when cancelling an offset. A T0 with M6 after it will generate an alarm.

    Your program is very strange regardless of these errors


  3. #3
    Registered
    Join Date
    Jun 2010
    Location
    U.S.A.
    Posts
    10
    Downloads
    0
    Uploads
    0
    Quote Originally Posted by fordav11 View Post
    What kind of machine is this? Normally you can't do 'real' XZ turning on a mill.
    The machine is a round column mill/drill converted to CNC with servos and a Mach3 controller. I'm chucking up 1/2" dia aluminum stock in a collet and clamping some lathe tools in the vice.

    Quote Originally Posted by fordav11 View Post
    If you have never programmed long hand before why are you over-complicating it by using macro variables?
    I guess I figured I was simplifying things. The subroutine keeps me from making dangerous numerical typos, and the parts I'm making have a shoulder and three grooves of varying depths and widths, so I figured by passing in parameters I could use the same subroutine for each groove and the shoulder. It's not in the example I posted, but my plan was to call M98 multiple times, and correspondingly rewrite the parameters for each call. Is that a piss-poor way to go about it?

    Quote Originally Posted by fordav11 View Post
    As for problems, you are in G17 (XY plane) and you are cutting XZ plane (G18). It's not a problem here because you are only cutting straight but if you cut an arc with G02/G03 you will get an alarm (wrong plane)
    Yeah, my plan there was to switch to G18 only for any arc moves (none in this program) and then switch back to G17. Since it's a mill, I wanted to be sure it stays in G17 as a default in case the next program doesn't explicitly call G17.

    Quote Originally Posted by fordav11 View Post
    Also T0 is not valid except when cancelling an offset. A T0 with M6 after it will generate an alarm.
    Good point. My controller doesn't alarm with a T0, but I'll switch it to an unused tool number and use the tool offset for the stock length.

    Quote Originally Posted by fordav11 View Post
    Your program is very strange regardless of these errors
    How you skin a cat can say a lot about your personality, I suppose


  4. #4
    Registered fordav11's Avatar
    Join Date
    Aug 2011
    Location
    Fordaville
    Posts
    1,672
    Downloads
    0
    Uploads
    0
    Quote Originally Posted by wileydavis View Post
    The machine is a round column mill/drill converted to CNC with servos and a Mach3 controller. I'm chucking up 1/2" dia aluminum stock in a collet and clamping some lathe tools in the vice.
    that's a novel approach. I guess if that's all you have to work with then it's fine if it works.

    on a mill it's not necessary to use T0 to cancel offsets.
    Tool length offset is called with G43 and cancelled with G49
    Tool diameter offset is called with G41/G42 and cancelled with G40
    T0 isn't required unless your control somehow acts like a lathe control.

    How you skin a cat can say a lot about your personality, I suppose
    I don't skin cats, I usually roast them on a spit. The skin usually just falls off with the cooked meat. Much easier than skinning it manually.
    Last edited by fordav11; 01-06-2012 at 01:52 AM.


  • #5
    Registered
    Join Date
    Jun 2010
    Location
    U.S.A.
    Posts
    10
    Downloads
    0
    Uploads
    0

    Success!

    I finally got the subroutine working. Turned out I had the wrong line-ending on my text file encoding and Mach3 didn't like the line return after the M99. Once I saved to a windows line ending, it ran fine (similar to the above code but not the same program). Here's a video of the outcome (turning a shoulder, a 1/4" wide groove, and parting.

    http://thungy-videos.s3.amazonaws.co...ng-960_540.mp4

    Thanks for the advice on T0. Cheers.


  • Similar Threads

    1. Found in archives - A2100 thread mill subroutine
      By Ron P in forum Cincinnati CNC
      Replies: 2
      Last Post: 05-17-2011, 09:38 AM
    2. subroutine
      By kendo in forum Okuma
      Replies: 3
      Last Post: 01-14-2010, 07:50 AM
    3. Problem- macro code inside of a subroutine
      By brockmo in forum Fadal
      Replies: 7
      Last Post: 03-12-2009, 11:32 PM
    4. Program g-code for mill as multiple tool lathe?
      By Monte in forum G-Code Programing
      Replies: 12
      Last Post: 04-19-2008, 12:18 AM
    5. G-code viewer (subroutine)
      By hao in forum G-Code Programing
      Replies: 1
      Last Post: 11-15-2006, 07:10 AM

    Posting Permissions


     


    About CNCzone.com

      We are the largest and most active discussion forum from DIY CNC Machines to the Cad/Cam software to run them. The site is 100% free to join and use, so join today!

    Follow us on

    Facebook Dribbble RSS Feed


    Search Engine Friendly URLs by vBSEO ©2011, Crawlability, Inc.