Velocity/accel limits in nested loop

This is a XY motion loop for testing several values of velocity and acceleration.

[gcode_macro LOOP_TEST]
gcode:
    {% set vel = (300,400,500) %}               # set velocity values to be tested (mm/s)
    {% set accel = (10000,20000,30000) %}       # set accel values to be tested (mm/s^2)
    {% set min = 5 %}                           # set the square lower left point
    {% set max = 195 %}                         # set the square upper right corner

    G1 X{min} Y{min} F5000

    {% for V in vel %}
        {% set machineVel = V*60 %}
        {% for A in accel %}
            M118 velocity:{V}mm/s, accel:{A}mm/s^2
            SET_VELOCITY_LIMIT VELOCITY={V}
            SET_VELOCITY_LIMIT ACCEL={A}
            SET_VELOCITY_LIMIT ACCEL_TO_DECEL={A}
            G1 X{max} Y{min} F{machineVel}
            G1 X{max} Y{max}
            G1 X{min} Y{min}
            G1 X{min} Y{max}
            G1 X{max} Y{min}
            G1 X{max} Y{min}
            G1 X{max} Y{max}
            G1 X{min} Y{max}
            G1 X{min} Y{min}
            G4 P1000
        {% endfor %}
    {% endfor %}

    # restore original limits
    SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity}
    SET_VELOCITY_LIMIT ACCEL={printer.configfile.settings.printer.max_accel}
    SET_VELOCITY_LIMIT ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel}

Not sure if this it the best way to write loops in jinja. It would be nice to be able to set low-value/high-value/step. Well, for the purpose of this experiment it’s not hard to define a handful of values in a couple of tuples.

Here it’s in action…

2 Likes

That’s great !!! :wave:
I was looking for something like that but was afraid to start scripting !
Thanks a lot , very helpful to expose your limits :smiley:

Petros

Thank you for sharing - I’ll definitively use it. The printer looks solid, how come the belt going to the carriage is so misaligned?

@w00sh I changed the 20T pulleys for 16T ones to switch from 0.0125mm/ustep to 0.01mm/ustep and I thought to add the extra rear idlers (the black ones) to choke the belt and gain a couple of teeth of engagement.

I was under the impression that as long as the outer Y belt segments run parallel to the Y rails and the X belt segments run parallel to the X rail, the rest could zig-zag.

After revisiting the basics it turns out the inner Y segments must run perpendicular to the X segments.

I have since removed the black idlers… re-ran input shaper and thanks to the macro, re-ran the tests and got the same results! No extra idlers anymore, everything runs parallel.

1 Like

With all those augmented fourths, this sounds like it should be a death-metal song!