Newbie First G-code


Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: First G-code

  1. #1
    Member
    Join Date
    Feb 2017
    Location
    United States
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default First G-code

    While I'm waiting for delivery of my cnc mill, its been recommended to me to learn g-code rather than just relying on conversational programming. Its all pretty bizarre to me, but after watching a bunch of videos have made my first try at it.
    The project consists of a 5" x 5" x 0.5" piece of aluminum with four 0.5 holes drilled in it as a 3" square. This code is for the four center drill holes. X0 Y0 is the front left corner. Z0 is the top of the work piece.
    This is presented as my work process rather than the way the actual code will be (has all my notes and expanations included so I can check whther it makes sense. Please let me know whether it will work.

    % begin
    O00123 program number
    N5 G90 G20 G54 G28 G40 G80; Safe line G90 absolute positioning command
    G20 verify inch coordinate positioning
    G54 work offset positioning coordinate #1
    G28 machine zero return thru reference point
    G40 cutter compensation cancel G41/G42/G141
    G80 cancel canned cycle
    N10 T01; Load tool 1 (center drill)
    N15 G43 H01; Tool length compensation Tool 1
    N20 S1000 M03; Set spindle speed 2000rpm Turn spindle on clockwise
    N25 G00 X-1.0 Y1.0; Fast movement to X,Y coordinates (first hole coordinates)
    N30 Z -1.0; Fast movement to Z coordinate
    N35 G01 Z 0.1; Slow movement to Z .1000 above workpiece N40 F20 Z-0.35 Z0.35; Drill start hole .25" deep and return
    N45 X-1.0 Y3.0; Coordinates for second hole
    N50 Z-0.35 Z0.35; Drill start hole .25" deep and return
    N55 X-3.0 Y3.0; Coordinates for third hole
    N60 Z-0.35 Z0.35; Drill start hole .25" deep and return
    N65 X-3.0 Y-3.0; Coordinates for fourth hole
    N70 Z-0.35 Z0.35; Drill start hole .25" deep and return
    N75 Z1.0 M05 Raise 1" above work spindle stop
    N80 G28 Machine zero return
    % End

    Thanks



    Sorry. Formatting got all screwed up when I posted











    Similar Threads:


  2. #2
    Community Moderator Jim Dawson's Avatar
    Join Date
    Dec 2013
    Posts
    5717
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Looks like you are rapid plunging the drill 0.5 inches into the table on your first Z move

    N30 Z -1.0; Fast movement to Z coordinate

    It also looks like you are mixing up G90 and what seems to be G91 (incremental) moves without setting a G91. Stick with the G90, and correct the G-code. Normally you will want to use G90 for all moves.

    N50 Z-0.35 Z0.35; Drill start hole .25" deep and return

    N50 should read:
    N50 Z-0.25 ( Drill start hole .25" deep)
    M52 Z0.1 (and return)

    For drilling, look at G81, and G83 codes.

    Good first try, just needs a little work. We'll help you through it. A lot of talent here.



  3. #3
    Member
    Join Date
    Feb 2017
    Location
    United States
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Yep, I set for absolute and programed for relative. I'll fix it tomorrow!
    Thanks Jim



  4. #4
    Member
    Join Date
    Feb 2017
    Location
    United States
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Ok, I think I got my head screwed back on straight. After checking out drilling codes as suggested I think I learned a few things. Whether I implemented them correctly I don't know!
    Here is my revosed code:

    % begin
    O00123 program number
    N5 G90 G20 G54 G28 G40 G80; Safe line
    G90 absolute positioning command
    G20 verify inch coordinate positioning
    G54 work offset positioning coordinate #1
    G28 machine zero return thru reference point
    G40 cutter compensation cancel G41/G42/G141
    G80 cancel canned cycle
    N10 T01; Load tool 1 (center drill)
    N15 G43 H01; Tool length compensation Tool 1
    N20 S1000 M03; Set spindle speed 2000rpm Turn spindle on clockwise
    N25 G00 X-1.0 Y1.0; Fast movement to X,Y coordinates (first hole coordinates)
    N30 Z 1.0; Fast movement to Z coordinate
    N35 G01 F20 Slow movement. Feed rate 20ipm
    N40 G98 G81 R.01 Z-.25; Drill cycle, return to Z1.0
    N45 X-1.0 Y4.0; Coordinates for second hole
    N50 G98 G81 R.01 Z-.25; Drill cycle, return to Z1.0
    N55 X-4.0 Y4.0; Coordinates for third hole
    N60 G98 G81 R.01 Z-.25; Drill cycle, return to Z1.0
    N65 X-4.0 Y1.0; Coordinates for fourth hole
    N70 G98 G81 R.01 Z-.25; Drill cycle, return to Z1.0
    N75 M05; Spindle stop
    N80 G28 Machine zero return
    % End


    This is the drawing I'm working with. The code above only represents the first step.

    Attached Thumbnails Attached Thumbnails First G-code-img_0453-jpg  
    Last edited by Jonathans; 03-21-2017 at 05:54 PM.


  5. #5
    Community Moderator Jim Dawson's Avatar
    Join Date
    Dec 2013
    Posts
    5717
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    This code snippet was generated with a Mach3 post in CamBam, but I don't know what you are using.

    This is not the complete code, but just illustrates the use and format of G81. The dimensions are for the hole layout and position you described above, with the 3 inch hole pattern centered in the 5 inch square. 0,0 is at the bottom right as looking at it on the screen.

    G0 Z1.0
    M3 S1000
    G0 X-1.0 Y1.0 (move to first hole)
    G98 (start canned cycle(G81))
    G81 X-1.0 Y1.0 Z-0.25 R0.1 F5.0
    G81 Y4.0 Z-0.25
    G81 X-4.0 Z-0.25
    G81 Y1.0 Z-0.25
    G80 (end canned cycle)
    G0 Z1.0 (Retract to Z to safe position)



  6. #6
    Community Moderator Jim Dawson's Avatar
    Join Date
    Dec 2013
    Posts
    5717
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Let's use 2D Cartesian Coordinates to describe the location of the part There is no "front'' as looking at it on the screen Top, Bottom, Left, and Right are the easiest to use when working with a 2D drawing






  7. #7
    Member
    Join Date
    Feb 2017
    Location
    United States
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Thanks Jim,
    Much more simplified. I see that if an axis value doesn't change there is no need to state it again in following blocks. Is this always true or only in a canned cycle?
    Based on your code, isn't 0,0 at the lower left? Spindle movement to the right is negative, correct?
    I'm not using any program for what I have coded. Drawing was done in Fusion 360. Hardly know how to use it. Haven't tried the CAM yet.



  8. #8
    Community Moderator Jim Dawson's Avatar
    Join Date
    Dec 2013
    Posts
    5717
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Depending on the controller, the previous positions may not have to be repeated. It is true for any move, if the axis position doesn't change.

    The tool moves in the negative direction as the tool is moving into the work. That physical direction could be to the right if the machine were laying on it's side At least I assume that we are working with a mill or a router here, rather than a horizontal machining center.

    In Fusion or any solid modeling software, do not confuse the drawing layout with the CAM layout. In CAM you define the X, Y, and Z surfaces.



  9. #9
    Member
    Join Date
    Feb 2017
    Location
    United States
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    What direction does the spindle move in -x? I thought it was to the right.



  10. #10
    Community Moderator Jim Dawson's Avatar
    Join Date
    Dec 2013
    Posts
    5717
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Just to keep things simple, what kind of a machine are we working with?



  11. #11
    Member
    Join Date
    Feb 2017
    Location
    United States
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Bridgeport knee mill



  12. #12
    Community Moderator Jim Dawson's Avatar
    Join Date
    Dec 2013
    Posts
    5717
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    OK, this says it better than I can



    Attached Thumbnails Attached Thumbnails First G-code-cnc_machine_axes-png  


  13. #13
    Member
    Join Date
    Feb 2017
    Location
    United States
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Got it

    Last edited by Jonathans; 03-21-2017 at 09:01 PM.


  14. #14
    Member handlewanker's Avatar
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    6463
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Hi, welcome to the starter's club........being a noob too I found starting with a simple work piece like 4 holes in a plate and modifying the code and re-writing it once the start lines were established made more sense to me than trying to create a complete complex.....relatively.....program that had too many values to get to grips with.

    I also found that trying to write code without a machine to try it out on as I went along left me confused and not relating to what was happening........the Mach 3 screen with the on screen tool path made no sense to me before I got my mill.

    I have a white board next to the mill and write a code sequence on it and run it as I go along.

    If you get good with the simple code it gets better as you add to it.....any mistakes usually generate a warning from Mach 3 that it won't work, so you can backtrack to that point.

    I also set up a dummy cutter using a 9mm diam wooden stick with a point to simulate a cutter and a block of wood in the vice to simulate the work piece.

    I marked the wood block with a black marker and cross lines and then generated the code to run through a drilling sequence to hit the lines as if it was a drilling op.

    Contrary and against advice to set the Z axis zero to the work piece top, I prefer to use a Z axis setting gauge to set the cutter tip to zero on the table top......the gauge gives me an exact 50mm above the table top.

    I found too that it pays to know where your tool point is at any time, hence the preference to the table top Z axis zero point.........everything that is Z coded will be a + value.... FOR ALL TOOLS.

    You also need to know EXACTLY the vice base thickness and the parallels that will be used to rest the job on........that is if you are using a vice......any old bits of steel strip will not do.

    My vice base is 43mm thick and with a 20 mm parallel means I'm 63 mm above the table, but more specifically the bottom of the work piece on the parallel is 63mm.....that's all you need to know.......Z63 is the bottom of the job......Z43 is the top of the vice base......Z0 is the table top where you never need to go to.
    Ian.



  15. #15
    Member
    Join Date
    Feb 2017
    Location
    United States
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Thanks Ian,
    I do think that once I have my mill it will make sense in a way that it can't right now. Its a challenge for my old brain to get familiar with a new language of sorts, but its quite exciting. I like the idea of having a white board at the mill. Great idea with the wood dummy tool and work piece. I was thinking I would just lower the knee some and let any new routine run in the air.



  16. #16
    Community Moderator Jim Dawson's Avatar
    Join Date
    Dec 2013
    Posts
    5717
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Jonathans there is hope, I know about those old brains. About 5 years ago I couldn't even spell G-code, and I just turned 68



  17. #17
    Member
    Join Date
    Feb 2017
    Location
    United States
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Well, you have seven years on me Jim! So now I do have hope! I appreciate the help.



  18. #18
    Member handlewanker's Avatar
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    6463
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Well. I top you all.....2 years ago I didn't know what G code was and I'm now 78......been a manual machinist all my life and got the CNC bug, so it was a slight deviation from the norm for me.

    One thing I did do and that was to browse many of the UTUBE tutorials with G code and setting up the mill from word go, then creating lots of notes on G code compiling.

    I owe a huge debt to Mactec54 and many others for guiding me through the maze.

    My mill is a Skyfire bench top model SVM-0, so it's a slightly different setup to the Bridgeport knee mill.

    If you just move the cutter above the job you lose the experience of getting the Z axis commands right.......touching down onto the job with the wood point is a joy and it gives you confidence to mount a drill and do serious work.......milling is another challenge with tool offsets for various tool diams and lengths etc.....one big learning curve.
    Ian. .



  19. #19
    Member
    Join Date
    Feb 2017
    Location
    United States
    Posts
    29
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    OK. Here's another try incorporating what I have learned so far.

    % begin
    O00123 program number
    N5 G90 G20 G54 G28 G40 G80; Safe line
    (G90 absolute positioning command)
    (G20 verify inch coordinate positioning)
    (G54 work offset positioning coordinate #1)
    (G28 machine zero return thru reference point)
    (G40 cutter compensation cancel G41/G42/G141)
    (G80 cancel canned cycle)
    N10 T01; Load tool 1 (center drill)
    N15 G43 H01; Tool length compensation Tool 1
    N20 G00 X00 Y00; Fast movement to X,Y coordinates (Top bottom left corner of work) N25 Z 1.0; Initial Z coordinate
    N30 M3 S1000 ; Set spindle speed 1000rpm Turn spindle on clockwise
    N35 G98; Canned cycle start
    N40 G81 X-1.0 Y1.0 Z-0.25 R0.2 F5; Drill first hole
    N50 G81 Y4.0 Z-0.25; Drill second hole
    N55 G81 X-4.0 Z-0.25; Drill third hole
    N60 G81 Y1.0 Z-0.25; Drill Fourth hole
    N65 G81 X-2.5 Y2.5; Drill center hole
    N70 G80; End Canned cycle
    N75 M5; Spindle stop
    N80 G28 Machine zero return
    % End

    once I get the nod that I got this portion down, I'll proceed with the next step.

    Attached Thumbnails Attached Thumbnails First G-code-img_0453-jpg  


  20. #20
    Community Moderator Jim Dawson's Avatar
    Join Date
    Dec 2013
    Posts
    5717
    Downloads
    0
    Uploads
    0

    Default Re: First G-code

    Close, but not quite. You still have your coordinate system a bit confused, and it can be confusing at first. Because you are working with a Bridgeport, think in terms of table movement. Your Y is correct, but X is inverted. Table moving to the right = -X, table moving to the left = +X. With 0,0 at the bottom left of the part, you are working in the +X, +Y quadrant. So all of your holes will be +X, +Y because the table is going to have to move to the left from 0 for the drill bit to be positioned over the hole.



Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

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


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

First G-code

First G-code