585,567 active members*
3,529 visitors online*
Register for free
Login
IndustryArena Forum > WoodWorking Machines > DIY CNC Router Table Machines > Looking for a detailed G code primer.
Page 1 of 2 12
Results 1 to 20 of 25
  1. #1
    Join Date
    Sep 2007
    Posts
    44

    Question Looking for a detailed G code primer.

    I've written computer programs since I was 8 in many different languages, so I do not expect that I'll have any difficulty learning g code. However, Google really doesn't turn up much. I can find lists of varying lengths of the various g code commands, but I can find very little in the way of a tutorial. I would like to not only see the complete list of commands, but also an example of each command.

    Maybe I'm using the wrong search terms. Can someone direct me to such a tutorial, if it exists?

  2. #2
    Join Date
    Jul 2005
    Posts
    12177
    This is a very comprehensive course thst covers everything.

    MFET 275 - CNC Applications

    A thing to be aware of with G and M codes is that there are some differences in code interpretation between different manufacturers. Most codes do mean the same on just about every machine but codes that call up canned routines are often different.
    An open mind is a virtue...so long as all the common sense has not leaked out.

  3. #3
    Join Date
    Dec 2003
    Posts
    24220
    The difference also applies to Machine application types, for e.g. the G codes will vary between Mill, Lathe,Gantry (router,plasma,oxy/gas), EDM, Punch press etc, to suit the difference in machine peculiarities.
    Also as Geoff points out M codes although often follow traditional practice, are written at the discretion of the MTB, so these can vary between identical controllers.
    Get a hold of a copy of CNC Programming Handbook by Peter Smid.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.

  4. #4
    Join Date
    Sep 2007
    Posts
    44
    That's good, but I'm hoping for more of a book format. Not necessarily a book, but in the format of a book.

    Also, how would one write a g code program to machine a curve path? Let's say, for example, that I want to mill the letter "S" out of wood and I use a drawing program to define the character out of Bezier curves. How do I machine the profile? My guess would be to write a program (not g code) that converts the curves into a series of line segments and then outputs the correct g code. Is there a better way?

    Quote Originally Posted by Al_The_Man View Post
    The difference also applies to Machine application types, for e.g. the G codes will vary between Mill, Lathe,Gantry (router,plasma,oxy/gas), EDM, Punch press etc, to suit the difference in machine peculiarities.
    In my case, strictly mill.

    Quote Originally Posted by Al_The_Man View Post
    Also as Geoff points out M codes although often follow traditional practice, are written at the discretion of the MTB, so these can vary between identical controllers.
    So, if I am using Mach3, I need to write the g code for Mach3's interpretation?

    Quote Originally Posted by Al_The_Man View Post
    Get a hold of a copy of CNC Programming Handbook by Peter Smid.
    Will do, although I'd like an online reference as well. It has been my experience, from a game programming perspective, that technical books pretty much are out of date at the moment of printing. Maybe not so much in this case, but the internet is far more dynamic.

  5. #5
    Join Date
    Dec 2003
    Posts
    24220
    You need a CAM system, this follows the CAD operation, Mach has a built in CAM called Lazycam where you can import different CAD or drawing file types.
    It also has a Customizable M code application.
    Even complicated shapes end up as G code, if not simple arcs or circles then smaller segments are generated.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.

  6. #6
    Join Date
    Sep 2007
    Posts
    44
    Quote Originally Posted by Al_The_Man View Post
    You need a CAM system, this follows the CAD operation, Mach has a built in CAM called Lazycam where you can import different CAD or drawing file types.
    It also has a Customizable M code application.
    Even complicated shapes end up as G code, if not simple arcs or circles then smaller segments are generated.
    Al.
    I don't have the money for "professional" CAM software and I am aware of LazyCAM. I'll probably use it for a while after my machine is built, but I would like to write my own simple CAM application. Other than that, I would really like to know what my machine is doing or about to do and that requires understanding g code in depth.

  7. #7
    Join Date
    Oct 2005
    Posts
    1237
    You don't need a CAM program, it just makes things easier. I went to a community college and bought a G-code programming book (used) at the book store. It came with a 100 line G-code interpreter (Predator CNC) to show the moves from a written G-code program.

    A book from a college book store will teach you how to interpret a blue print, offset your cutter (cutter comp) and do lead in's to your work. Ebay might be a good place to look for a used college book that's cheaper than a college bookstore would be. My book used Fanuc G-code language as the G-code it taught. Fanuc is about as generic a G-code as it comes.

  8. #8
    Join Date
    Mar 2003
    Posts
    35538
    Also, how would one write a g code program to machine a curve path? Let's say, for example, that I want to mill the letter "S" out of wood and I use a drawing program to define the character out of Bezier curves. How do I machine the profile? My guess would be to write a program (not g code) that converts the curves into a series of line segments and then outputs the correct g code. Is there a better way?
    That's pretty much it. Some CAD programs can export the Bezier curves (spines) as line segments.
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  9. #9
    Join Date
    Dec 2003
    Posts
    24220
    Quote Originally Posted by maspeir View Post
    but I would like to write my own simple CAM application. Other than that, I would really like to know what my machine is doing or about to do and that requires understanding g code in depth.
    If you run a program through Lazycam, you can see the resultant G code to get an example of what you require for programming purposes.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.

  10. #10
    Join Date
    Aug 2008
    Posts
    247

    RS274NGC

    As a developer, my guess is you'll appreciate this document.

    http://citeseerx.ist.psu.edu/viewdoc...=rep1&type=pdf

    G-Code files are text, so understanding what the interpreter is looking for is a good place to start.

    Another good resource is the EMC2 Project. The source code is available as a free download.

    ~John

  11. #11
    Join Date
    Sep 2007
    Posts
    44

    Quote Originally Posted by ger21 View Post
    That's pretty much it. Some CAD programs can export the Bezier curves (spines) as line segments.
    I was really expecting it to be more involved than that. CNC is all about precision and accuracy and representing a curve with line segments is, in the graphics programming world at least, considered to be the least precise and accurate representation of a curve. No matter how finely you subdivide the curve, part of the line segment will always be off of the curve.

    Quote Originally Posted by johnohara View Post
    As a developer, my guess is you'll appreciate this document.
    That is EXACTLY the kind of thing I was looking for! Thanks!:banana:

    I'll look up the EMC2 project. Sounds interesting.

  12. #12
    Join Date
    Dec 2006
    Posts
    406
    I agree that breaking things up into line segments detracts from accuracy...but... You can decide the standard deviation from the actual curve. That means basicly you can let the path deviate by as much as you want to shorten program length by using longer and fewer line segments. You can also specify better accuracy standards which just means more smaller segments that better apporximate the actual geometry. This can give you accuracy to as close a tolerance as your machine tool can hold. (.01-.001 for a decent cnc router or .001-.0002 for a mill from my experiance).
    Judleroy

  13. #13
    Join Date
    May 2005
    Posts
    1662
    Quote Originally Posted by maspeir View Post
    My guess would be to write a program (not g code) that converts the curves into a series of line segments and then outputs the correct g code. Is there a better way?
    Better ? Possibly not.
    Different ? Yes.

    This is a sample G-Code file provided with EMC2 for NURBS. Here's how one of the curves is defined.
    Code:
    G5.2 X-10.78  Y2.56    P1
         X-24.12  Y7.57    P1
         X-35.39  Y-1.18   P1
         X-33.00  Y-9.76   P1
         X-25.07  Y-10.98  P1 
         X-19.41  Y-18.53  P1
         X-22.02  Y-25.27  P1
         X-18.77  Y-30.08  P1 
         X-12.70  Y-28.16  P2
         X-8.25   Y-23.28  P1
         X-5.65   Y-22.06  P2
         X-2.94   Y-23.50  P1
    G5.3
    You now know as much about it as I do.
    Attached Thumbnails Attached Thumbnails butterfly.png  
    Anyone who says "It only goes together one way" has no imagination.

  14. #14
    Join Date
    Sep 2007
    Posts
    44
    Quote Originally Posted by cyclestart View Post
    This is a sample G-Code file provided with EMC2 for NURBS. Here's how one of the curves is defined.
    Code:
    G5.2 X-10.78  Y2.56    P1
         X-24.12  Y7.57    P1
         X-35.39  Y-1.18   P1
         X-33.00  Y-9.76   P1
         X-25.07  Y-10.98  P1 
         X-19.41  Y-18.53  P1
         X-22.02  Y-25.27  P1
         X-18.77  Y-30.08  P1 
         X-12.70  Y-28.16  P2
         X-8.25   Y-23.28  P1
         X-5.65   Y-22.06  P2
         X-2.94   Y-23.50  P1
    G5.3
    That was actually what I was expecting with curves. There is no "G5.2" or "G5.3", so I suspect that these are G codes specific to EMC2. It appears that the control points are defined with these functions. I would guess that internally, EMC2 is creating the curve as a sequence of line segments, but since it is controlling the machine directly, it doesn't have to.

  15. #15
    Join Date
    May 2006
    Posts
    168
    Quote Originally Posted by maspeir View Post
    That was actually what I was expecting with curves. There is no "G5.2" or "G5.3", so I suspect that these are G codes specific to EMC2. It appears that the control points are defined with these functions. I would guess that internally, EMC2 is creating the curve as a sequence of line segments, but since it is controlling the machine directly, it doesn't have to.
    I do not believe this is "standard" g-code. More of a hybrid from how graphic software produces curves.

    The TurboCNC manual is a good reference for G-code used in industry. And it is a good G-code interpreter for hobby cnc machines.

  16. #16
    Join Date
    May 2005
    Posts
    1662
    Quote Originally Posted by rlwoodjr View Post
    I do not believe this is "standard" g-code. More of a hybrid from how graphic software produces curves.
    My guess is the author had a need for it and shared back the code. It's labeled "experimental" and there's very little information available. Most controls have some some unique G+M code but this is as nonstandard as G-code gets.

    If maspeir is using Mach3, the Mach3 manuals should explain the legal G+M codes ? The Mach3 documentation tends to be pretty good.
    Anyone who says "It only goes together one way" has no imagination.

  17. #17
    Join Date
    Sep 2007
    Posts
    44
    Quote Originally Posted by cyclestart View Post
    My guess is the author had a need for it and shared back the code. It's labeled "experimental" and there's very little information available. Most controls have some some unique G+M code but this is as nonstandard as G-code gets.

    If maspeir is using Mach3, the Mach3 manuals should explain the legal G+M codes ? The Mach3 documentation tends to be pretty good.
    I'm not using anything yet, but it looks like I will be using Mach 3. EMC2 looks good as well, and better than Mach 3, but I am not a fan of Linux' complexity. I hate that even the versions with a GUI require a command line interface for basic operations (Need to use the command line to install a graphics driver? WTH?!).

  18. #18
    Join Date
    May 2005
    Posts
    1662
    EMC2 is available rolled into Ubuntu which is very user friendly imo. That said, it is Linux and has whatever warts come with that.

    Whether Mach3 is better than EMC2 or vice versa......... I don't know.
    The EMC2 developers are very active, it keeps things interesting.
    Anyone who says "It only goes together one way" has no imagination.

  19. #19
    Join Date
    Sep 2007
    Posts
    44
    Quote Originally Posted by cyclestart View Post
    EMC2 is available rolled into Ubuntu which is very user friendly imo. That said, it is Linux and has whatever warts come with that.

    Whether Mach3 is better than EMC2 or vice versa......... I don't know.
    The EMC2 developers are very active, it keeps things interesting.
    I don't know how EMC2 compares with Mach 3 exactly, but the screen shots from EMC2 show many CAM program features rolled into the program. I'm guessing that EMC2 is the better app, and free to boot! However, I'll play around with Linux more after they drop the command line. It is an archaic interface and simply is no longer needed. It is absurdly complex and simply absurd that it is expected that the average user must remember all of the commands to do simple tasks. Anyway, Linux rant off...

  20. #20
    Join Date
    Mar 2003
    Posts
    35538
    Mach3 is free for up to 500 lines of code.

    Which is better, probably depends on your needs.
    EMC can do some things out of the box that Mach3 can't, like close a servo loop.
    For Windows users, Mach3 is the easy choice. That's probably why Mach3 users outnumber EMC by a huge margin.

    And, unless your a Linux expert, Mach3 is probably much easier to modify and customize for the average user.
    Gerry

    UCCNC 2017 Screenset
    http://www.thecncwoodworker.com/2017.html

    Mach3 2010 Screenset
    http://www.thecncwoodworker.com/2010.html

    JointCAM - CNC Dovetails & Box Joints
    http://www.g-forcecnc.com/jointcam.html

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

Page 1 of 2 12

Similar Threads

  1. Mi primer CNC <<Colombia>>
    By macsim in forum Spanish
    Replies: 53
    Last Post: 01-29-2014, 08:39 PM
  2. Primer post, solicito ayuda.
    By dolordemuela in forum Spanish
    Replies: 1
    Last Post: 11-23-2010, 09:15 PM
  3. Construyendo mi primer Maquina.
    By bernardo in forum Spanish
    Replies: 18
    Last Post: 11-16-2009, 03:48 PM
  4. ISO Surface Grinding Primer
    By r11449 in forum MetalWork Discussion
    Replies: 2
    Last Post: 03-21-2009, 06:04 PM
  5. A Primer on Soldering
    By kreutz in forum CNC Machine Related Electronics
    Replies: 0
    Last Post: 03-18-2008, 01:00 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
  •