G-code loop updated?

I am trying to use loop for code simplification as I am at 10 000 lines right now when writing every single move in one line

does this work or is not supported?

image

i read in this post that it is not supported, but post is 6 years old

I have not seen that used before. I don’t think it works. Did you try it?

I would use some other scripting language, like python, bash, or perl to write out the gcode I wanted. That is a lot easier to debug and inspect than while loops in gcode in the firmware.

I tried and did not work. I wrote it with excel, it ended up at 15550 lines of code haha
I dont have an experience with scripting languages so far

RepRap firmware has loop and conditional code support, I’ve used it minimally.

So far as I am aware, Marlin does not support iterative gcode.

It looks to me like you want to bounce the bed up and down while moving X to the left.

Thanks for info.

Yeah, and I want to do this up down movement couple thousand of times. I will use LowRiderV3 to test large touch screen, so these movements will be touches with stylus.

1 Like

I think I would have designed the part in F360 and used it’s CAM to create the gcode.

1 Like
# python script to plot a thousand touch points
Xset=[0, 20, 40, 20]
Yset=[0, 10, 0, -10]
def touchScreen(x):
    print ("G1 X",str(Xset[x])," Y",str(Yset[x])," F10000")
    print ("G1 Z-5 F10000")
    print ("G1 Z5 F10000")
    return
   
for i in range(1000):
    touchScreen(i%4)

exit()

Poor coding practices, one character variable names (I think that “i” as an iterator count is acceptable, myself…) but anyway, this will plot touching 4 places on the screen 250 times each.

The Xset and Yset are arrays of the places on the screen that you want to touch. yhou can code in as many of these as you want, or you could even choose random points if you want. I chose an array of 4, but, whatever floats your boat. creates a G1 command to go there, then G1 commands to put Z to -5 then back up to 5.

Edit: for those not familiar, the expression (i%4) returns the remainder of the iterator divided by 4. This results in a number that is in the range of 0-3. This lets me use a small array of X and Y coordinates to probe while cycling through them. You could ignore the argument in the touchScreen() function or set up a larger array. I suppose that a random function could also be used if you wanted to.

1 Like

Thanks for a help. That looks great, will definitely use when I will need some more code.

Modulus operator