Free 186 More Best Homemade Tools eBook:  
Get tool plans

User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18

Thread: Using GOTO and IF-THEN-ELSE G-code Commands

  1. #1
    Supporting Member rgsparber's Avatar
    Join Date
    Nov 2012
    Location
    Phoenix, AZ
    Posts
    1,321
    Thanks
    775
    Thanked 2,838 Times in 670 Posts

    rgsparber's Tools

    Using GOTO and IF-THEN-ELSE G-code Commands

    If you deal with CNC machines, cutter movement must come to mind. Yet G-Code can also do math and logic. This article introduces a few of these commands and then explains a program that drills an array of holes.

    If you are interested, please see

    https://rick.sparber.org/GcodeLogic.pdf


    Your comments are welcome. All of us are smarter than any one of us.


    Thanks,

    Rick

    186 More Best Homemade Tools eBook
    Rick

  2. The Following 13 Users Say Thank You to rgsparber For This Useful Post:

    Carnel (Jun 27, 2022), Jeffie (Mar 13, 2019), Jon (Jan 3, 2020), Kevic (Mar 12, 2019), Marine2171 (Mar 12, 2019), markcawston (May 1, 2019), Miloslav (Mar 17, 2019), nova_robotics (Jun 26, 2022), Paul Jones (Mar 15, 2019), Seedtick (Mar 12, 2019), Sleykin (Jun 23, 2021), thevillageinn (Jun 26, 2022), UncleBob (Mar 12, 2019)

  3. #2
    Supporting Member rgsparber's Avatar
    Join Date
    Nov 2012
    Location
    Phoenix, AZ
    Posts
    1,321
    Thanks
    775
    Thanked 2,838 Times in 670 Posts

    rgsparber's Tools
    I see more than 400 people have at least started to read this article. It is my first attempt at explaining G-code and I'm not sure if my assumptions about the reader's background are correct. Please let me know if you felt it was too simple, just right, or too complicated.

    Thanks,

    Rick

    2,000+ Tool Plans
    Rick

  4. The Following 2 Users Say Thank You to rgsparber For This Useful Post:

    MeJasonT (May 2, 2019), Paul Jones (Mar 13, 2019)

  5. #3
    Supporting Member Paul Jones's Avatar
    Join Date
    May 2014
    Location
    Del Mar, California
    Posts
    1,231
    Thanks
    5,810
    Thanked 1,459 Times in 657 Posts

    Paul Jones's Tools
    Thank you for the detail on the GOTO and IF-THEN-ELSE G-code Commands.

  6. #4
    Supporting Member tonyfoale's Avatar
    Join Date
    Nov 2016
    Location
    Spain
    Posts
    1,595
    Thanks
    713
    Thanked 2,688 Times in 719 Posts

    tonyfoale's Tools
    Quote Originally Posted by rgsparber View Post
    I see more than 400 people have at least started to read this article. It is my first attempt at explaining G-code and I'm not sure if my assumptions about the reader's background are correct. Please let me know if you felt it was too simple, just right, or too complicated.
    Rick
    Rick,

    Your post has a limited readership, almost by definition so it would not be wise to limit it further by aiming it only at those with a higher starting knowledge. I think that you got the level about right. I assume that only those who have manually written G-code would be interested and so there should be no need to assume a lower starting level than that. For completeness you could add explanations of subroutines as well.

    If I had to criticise, I would say that you might retain reader interest longer if you gave some very brief examples near the beginning of the document rather than starting off with the meat. As it is, you start off with "here is some great stuff that you might not know about", I imagine some readers thinking "so what?" and going elsewhere. If initially you showed some examples that would be long winded without these techniques and then offered them as a solution I think that more readers would stay the course.

    My comments should be taken as from someone who has written engineering application software since 1960 and who regularly hand codes G-code. For me there was nothing new in your post so maybe i do not have the best perspective to comment on the level for your expected/intended readership. Take my comments with that in mind.

  7. #5
    Supporting Member rgsparber's Avatar
    Join Date
    Nov 2012
    Location
    Phoenix, AZ
    Posts
    1,321
    Thanks
    775
    Thanked 2,838 Times in 670 Posts

    rgsparber's Tools
    Quote Originally Posted by tonyfoale View Post
    Rick,

    Your post has a limited readership, almost by definition so it would not be wise to limit it further by aiming it only at those with a higher starting knowledge. I think that you got the level about right. I assume that only those who have manually written G-code would be interested and so there should be no need to assume a lower starting level than that. For completeness you could add explanations of subroutines as well.

    If I had to criticise, I would say that you might retain reader interest longer if you gave some very brief examples near the beginning of the document rather than starting off with the meat. As it is, you start off with "here is some great stuff that you might not know about", I imagine some readers thinking "so what?" and going elsewhere. If initially you showed some examples that would be long winded without these techniques and then offered them as a solution I think that more readers would stay the course.

    My comments should be taken as from someone who has written engineering application software since 1960 and who regularly hand codes G-code. For me there was nothing new in your post so maybe i do not have the best perspective to comment on the level for your expected/intended readership. Take my comments with that in mind.
    Great suggestion. How does this look (see page 2): https://rick.sparber.org/GcodeLogic.pdf

    I have also rewritten the explaination of the code example. As the author, I am unable to see what does not work for the readers so PLEASE give me your comments.

    Thanks,

    Rick
    Rick

  8. The Following User Says Thank You to rgsparber For This Useful Post:

    Paul Jones (Mar 15, 2019)

  9. #6
    Supporting Member tonyfoale's Avatar
    Join Date
    Nov 2016
    Location
    Spain
    Posts
    1,595
    Thanks
    713
    Thanked 2,688 Times in 719 Posts

    tonyfoale's Tools
    Quote Originally Posted by rgsparber View Post
    Great suggestion. How does this look (see page 2): https://rick.sparber.org/GcodeLogic.pdf

    I have also rewritten the explaination of the code example. As the author, I am unable to see what does not work for the readers so PLEASE give me your comments.
    Rick
    As an author of two technical books as well as a contributing author to other books and 100s of magazine articles I am only too well aware of the difficulties of determining how the average reader interprets one's work. This applies much more to technical works because it is hard to strike the right balance between those with the minimum starting knowledge and those with much more. It is easy to lose one extreme or the other if the balance is wrong. I do not read fiction ( never get past the first page when I have tried ) but I guess that these considerations do not apply to that genre.

    I think that your page 2 additions are much more likely to suck the reader in. Great choice of variations on the same theme, very clever. You state that conditionals and navigation statements will be discussed but then you start talking about variables without initial explanation. I would suggest an early mention that variables are useful in conjunction with the conditionals and navigation statements.

  10. The Following User Says Thank You to tonyfoale For This Useful Post:

    Paul Jones (Mar 15, 2019)

  11. #7
    Supporting Member rgsparber's Avatar
    Join Date
    Nov 2012
    Location
    Phoenix, AZ
    Posts
    1,321
    Thanks
    775
    Thanked 2,838 Times in 670 Posts

    rgsparber's Tools
    Quote Originally Posted by tonyfoale View Post
    As an author of two technical books as well as a contributing author to other books and 100s of magazine articles I am only too well aware of the difficulties of determining how the average reader interprets one's work. This applies much more to technical works because it is hard to strike the right balance between those with the minimum starting knowledge and those with much more. It is easy to lose one extreme or the other if the balance is wrong. I do not read fiction ( never get past the first page when I have tried ) but I guess that these considerations do not apply to that genre.

    I think that your page 2 additions are much more likely to suck the reader in. Great choice of variations on the same theme, very clever. You state that conditionals and navigation statements will be discussed but then you start talking about variables without initial explanation. I would suggest an early mention that variables are useful in conjunction with the conditionals and navigation statements.
    Thanks Tony, changes now implemented. https://rick.sparber.org/GcodeLogic.pdf

    Rick
    Rick

  12. The Following 2 Users Say Thank You to rgsparber For This Useful Post:

    albertq (Dec 30, 2023), Sleykin (Jun 23, 2021)

  13. #8
    Supporting Member marksbug's Avatar
    Join Date
    Apr 2016
    Posts
    1,938
    Thanks
    774
    Thanked 382 Times in 308 Posts
    I used to program& run cnc mills back in the mid 90's ( hurco mills) a lot of aerospace stuff, DOD mill spec stuff& prototype stuff. the boss said I did not want to try to learn G code for the other machines....I did some checking and reading and...he was right. I liked the simple programing the hurco's have. I dont understand why everything isant simple to program...why still G code stuff.....I sure would love to convert one of my mills to cnc but not if I gotta do the g code. these days I dont think my brain could stand the abuse.

  14. #9
    Supporting Member tonyfoale's Avatar
    Join Date
    Nov 2016
    Location
    Spain
    Posts
    1,595
    Thanks
    713
    Thanked 2,688 Times in 719 Posts

    tonyfoale's Tools
    Quote Originally Posted by marksbug View Post
    I dont understand why everything isant simple to program...why still G code stuff.....I sure would love to convert one of my mills to cnc but not if I gotta do the g code. these days I dont think my brain could stand the abuse.
    You have to have some means of transferring instructions to a machine and it is hard to imagine anything simpler than G-code. The stuff that Rick showed could be considered advanced and be a bit intimidating to non-programmers but you do not need to write code using those advanced features. Mostly you can just use the simple commands which reduce down to only two sets of commands. One, to go from where you are to where you want to be in a straight line, and two, to do the same on a circular path. e.g.

    G1 X20 moves in a straight line 20 units (usually inches or mm) in the X direction.
    G1 X15 Y10 Z5 moves the tool or work piece (depending on the machine type) in a coordinated fashion to the position (15, 10, 5)

    If the tool centre is at (0, 20) then either of the following will cut a path to (20, 0) on a clockwise circular arc
    G2 X20 Y0 I0 J0 (I and J are the absolute coordinates of the centre) or G2 X20 Y0 R20 (with R being the arc radius)

    I find it hard to imagine how you could transfer instructions much simpler than that. In any case many machinists do not manually write the G-code. CAM software takes a CAD drawing and spews out the G-code for you. I don't use CAD and so I either write the code manually or write my own software to generate the G-code for specific purposes. You can also do a lot of machining using wizards ( pre-written G-code often called "conversational").

  15. #10
    Content Editor
    Supporting Member
    DIYer's Avatar
    Join Date
    Aug 2013
    Posts
    3,055
    Thanks
    791
    Thanked 1,880 Times in 1,677 Posts
    Thanks Rick! We've added your Gcode Methodology to our Machining category, as well as to your builder page: Rick's Homemade Tools. Your receipt:


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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