Gcode and For-Next Loops

More
26 Nov 2015 15:07 #65825 by Micromet
Does Gcode have a programmable For-Next loop? The Problem is:

Say I want to engrave a set pattern many times onto an aluminium plate.
Also say - I've already created the Gcode that will engrave the pattern and have homed and touched-off the initial X,Y,Z positions
What I want to do now is engrave the pattern, move the X and Y positions to a new location and engrave the pattern again, then move the X and Y positions and do it again.......again, again, etc.

I'm guessing the O-codes are where I need to begin to look - although there doesn't seem to be a For-Next loop in there - but I could use either IF-While or create a subroutine.
But I need to find out how to add X and Y values to the initial values so that the If - While loop or subroutine moves from one iteration of the pattern to the next until the End condition is met. Any help would be useful

Please Log in or Create an account to join the conversation.

More
26 Nov 2015 15:36 - 26 Nov 2015 15:56 #65827 by cncbasher
Replied by cncbasher on topic Gcode and For-Next Loops
yes you can look at G91 & G92 for ideas , you can also use work offsets , and sub programs , dependant on the complexity

theirs an example of a for loop here
WHILE: Automating Repetition
www.cnccookbook.com/CCCNCGCodeIFGOTOWHEN.htm
Last edit: 26 Nov 2015 15:56 by cncbasher.
The following user(s) said Thank You: Micromet

Please Log in or Create an account to join the conversation.

More
27 Nov 2015 07:29 #65853 by Rick G
Replied by Rick G on topic Gcode and For-Next Loops
You might get some ideas here...
forum.linuxcnc.org/forum/40-subroutines-...ling-multiple-copies

Rick G
The following user(s) said Thank You: Micromet

Please Log in or Create an account to join the conversation.

More
27 Nov 2015 14:57 #65864 by Micromet
Replied by Micromet on topic Gcode and For-Next Loops
Hi Rick,

Thanks for the link and the associated program listings. My next question is: is there a decent book that deals largely with Gcode programming protocol - in the same way that other computer language programming books do it - i.e. without any real appeal to machining as such.
I have Michael J Peterson's "CNC Programming - Basics and Tutorial" which for a supposedly English-speaking author often comes over as Chinglish e.g. p29. "Absolute programming is programming mode that is a reflection of each number read is from part or machine Zero" ??? and the programming examples given are for specific production of an item with little explanation of options, why specific code was chosen or possible options - a good book if you wanted to make his example pieces but lacking if otherwise.
I also have Marcus Bowman's "CNC Milling in the Workshop" which is a much better book - but is still geared towards specific examples and the code needed to produce the artifact.
What I am looking for is a book that is separate from any CNC machining at all - but just explains Gcode instructions, the options available for each instruction, what a typical program needs to consist of (Initialisation, parameter definitions, global presets, ) the various ways you can arrange loops, subroutines, even nested subroutines (if these are allowed), can you carry arguments through into subroutines? where to put comment statements (are inline comments allowed? and why some CNC Gcode use " ;" while others use "/"), etc.

I guess what I am looking for is a book entitled "The CNC programming language"

Please Log in or Create an account to join the conversation.

More
27 Nov 2015 15:15 #65866 by andypugh
Replied by andypugh on topic Gcode and For-Next Loops

I guess what I am looking for is a book entitled "The CNC programming language"


Have you read the LinuxCNC docs? They may not completely answer your needs, but they are free.

linuxcnc.org/docs/2.7/html/gcode/overview.html
The following user(s) said Thank You: Micromet

Please Log in or Create an account to join the conversation.

More
27 Nov 2015 16:55 #65871 by Micromet
Replied by Micromet on topic Gcode and For-Next Loops
Hi Rick,

Doh! why didn't I think of that. Just need to find the appropriate pdf and print that out - I'm old-fashioned that way - prefer a book I can annotate and mark rather than having to scroll back and forth in an html.

Please Log in or Create an account to join the conversation.

More
28 Nov 2015 06:24 #65922 by Rick G
Replied by Rick G on topic Gcode and For-Next Loops
Part of the problem is when you get past the basic commands gcode is not universal, not all gcodes may be implemented from one flavor to another. Say linuxcnc and fanuc. Which is one reason you see so many post processor options in Cam software.

These may also help...
linuxcnc.org/docs/2.4/html/gcode_main.html
gnipsel.com/linuxcnc/g-code/

Nothing wrong with print, paper and books, and I would not even call that old fashion!

Rick G

Please Log in or Create an account to join the conversation.

More
28 Nov 2015 21:15 #65975 by comjon
Replied by comjon on topic Gcode and For-Next Loops
The lack of standards is a problem, as Rick G.commented, and this seems similar to other tech companies creating "proprietary" use of a language.

If you learned For-Next loops or subroutines in a languages like C++ you will find G code easier but odd. For what you are trying to accomplish (code reuse I gather) you could write O codes for pocketing operations, as I learned on the Haas, but it has it's drawbacks. Gcode is procedural, as you may have guessed, you don't write for classes or inheritance or object oriented methodology. There are quirks to some Gcode commands depending on vendor implementations. Standard are nice to have, no doubt.

Please Log in or Create an account to join the conversation.

Time to create page: 0.098 seconds
Powered by Kunena Forum