Loop and condition by g-code command

11.8k views Asked by At

How I can make and stop loop at selected condition using G-code?
For example, I have the following G-code commands:

G10  L2 P1 X-10. Y-10.  Z-10
G10  L2 P2 X-10. Y-11.  Z-10
G10  L2 P3 X-10. Y-12.  Z-10

I would like to create loop, which repeats my code 5 times. I can not use m-code . I need build loop by G92

3

There are 3 answers

0
paolo antonio Reina On

Let's suppose you wanted to perform a particular g-code operation 5 times. You might write the WHILE loop to do that as follows:

#100 = 1  
WHILE [#100 LE 5] DO1
    (Some G-Code Blocks Go Here to Be Repeated Each Loop)
    #100 = #100 + 1 (Increase #100 by 1 each iteration of the loop)
END1
0
Gray On

If you are using LinuxCNC, then the code below would be the code used to loop or iterate some lines of gcode.

FYI, LinuxCNC and gcode can be more difficult to own than most of the other common programming languages … python, R, etc...

And LinuxCNC does not accept just any old gcode. The AXIS in my LinuxCNC rejected the code in the other answer that is shown below. LinuxCNC wants the formatting to be exact - including brackets, starting / ending file characters, etc....

This code works in the AXIS GUI in LinuxCNC.

%
/ Tool is set at starting position.  Enter the conditional loop

#100 = 1

o101 while [#100 le 5] 

G1 X -0.02 F10
G54 Z -.25 F10
G0 X0.0
G54 Z0.0

#100 = [#100 + 1]

o101 endwhile

M2
%
1
MaxEkb77 On

LinuxCNC macro

G91 
o103 repeat [5]
G0 Z-10
G0 Z10
o103 endrepeat
G90