PDA

View Full Version : gcode nested loops



ldaniels
10-26-2007, 08:59 AM
I have searched high and low through CNCZone, etc. I am new at
gcode, though it reminds me much of basic from late 1970's. A question
I have not yet answered - can gcode interpret nested loops
( a loop within a loop?). My use is for drilling multiple rows of holes on
the exterior of a cylinder.

thanks

Andre' B
10-26-2007, 10:29 AM
On most controls with macro B you can nest up to 4 levels deep.
So it depends on how standard Machs implimentation is, it should be in the manual I would think.


WHILE [] DO1
WHILE [] DO2
WHILE [] DO3
WHILE [] DO4
END4
END3
END2
END1

Some other info on macro programming.
http://www.cnczone.com/forums/showpost.php?p=356054&postcount=13
http://www.cnczone.com/forums/showpost.php?p=355987&postcount=12

Geof
10-26-2007, 11:22 AM
It is not a case of can G-code interpret nested loops but a matter of can the controller software interpreting the G-code interpret nested loops. Your analogy with Basic is correct to some extent but not really for plain G-code; this is more analogous to html and just as some browsers cannot interpret some features or interpret them differently some controllers interpret G-code differently. Within G-code there is a subset of commands known as Macro A or B and this is based on Basic and allows most of the operations in Basic but again it depends on whether the controller software has macro capabalities turned on. Again I think an analogy with browsers can be made this time with respect to Java which some browsers could not interpret.

I run commercial machines (Haas) which have their own proprietary controller software and they can handle nested loops; my old machines are limited to nine deep but the newer ones do not seem to have any limit I can find. The subroutine commands are (normally) M97 (P)nnnn which commands go to line nnnn and proceed from there until a M99 is encountered which means return to the line below the M97; I put the P in parentheses because some controllers use a different label. An Lnn, as in M97 Pnnnn Lnn, modifies the meaning so that the return comes back the M97 until the L is counted to zero.

I have several programs that do what you are seeking on the X Y plane and they use subroutines nested three deep (I think); modifying these to use the X and A axes would be trivial.

Of course if Macros are enabled in the machine controller software then nested loops are possible within a macro subprogram in which case the G code command is G65 followed by a string of variables and a target which is a separate program; I think G65 is the standard G code.

Switcher
10-26-2007, 07:21 PM
I run Siemens 840D control, I think the max. it will nest is 11 deep.

I've never had to go that far. :)

.