Custom Travel Acceleration

Hi Guys,

i want to share my macro/gcode manipulation G0/G1/G2/G3 ( initial base for script/macro found somewhere in the net, cant remember exactly where it was, if the person reads this, pm me so that i can credit you! )

It modifies the GCODE to set different acceleration settings for travel moves similar to M204 T in Marlin


[gcode_macro _global_variables]
variable_accel_scv_modified_is_print_move: 1
gcode:
  ; must provide something
  
[gcode_macro G0]
rename_existing: G0.1
gcode:
    {% if params.E is defined %}
        {% if printer["gcode_macro _global_variables"].accel_scv_modified_is_print_move == 0 %}
            SET_VELOCITY_LIMIT ACCEL={printer.configfile.settings.printer.max_accel}
            SET_VELOCITY_LIMIT ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel/2}
            SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={printer.configfile.settings.printer.square_corner_velocity}
            SET_GCODE_VARIABLE MACRO=_global_variables VARIABLE=accel_scv_modified_is_print_move VALUE=1
	    {% endif %}		
    {% else %}
	    {% if printer["gcode_macro _global_variables"].accel_scv_modified_is_print_move == 1 %}
            SET_VELOCITY_LIMIT ACCEL=8000
            SET_VELOCITY_LIMIT ACCEL_TO_DECEL=8000
            SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY=100
            SET_GCODE_VARIABLE MACRO=_global_variables VARIABLE=accel_scv_modified_is_print_move VALUE=0
	    {% endif %}
    {% endif %}
    G0.1 { rawparams }

[gcode_macro G1]
rename_existing: G1.1
gcode:
    {% if params.E is defined %}
        {% if printer["gcode_macro _global_variables"].accel_scv_modified_is_print_move == 0 %}
            SET_VELOCITY_LIMIT ACCEL={printer.configfile.settings.printer.max_accel}
            SET_VELOCITY_LIMIT ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel/2}
            SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={printer.configfile.settings.printer.square_corner_velocity}
		    SET_GCODE_VARIABLE MACRO=_global_variables VARIABLE=accel_scv_modified_is_print_move VALUE=1
	    {% endif %}		
    {% else %}
	    {% if printer["gcode_macro _global_variables"].accel_scv_modified_is_print_move == 1 %}
            SET_VELOCITY_LIMIT ACCEL=8000
            SET_VELOCITY_LIMIT ACCEL_TO_DECEL=8000
            SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY=100
		    SET_GCODE_VARIABLE MACRO=_global_variables VARIABLE=accel_scv_modified_is_print_move VALUE=0
	    {% endif %}
    {% endif %}
    G1.1 { rawparams }

Be aware of the 8000 acceleration set for travel moves!! Bed slingers might arent able to handle these high acceleration values

Of course you can copy and edit this macro also for the G2 or G3 commands

feedback appreciated :slight_smile:

That’s great thanks for sharing.

Thanks for sharing, and for the reminder to also modify g2 and g3 for these kinds Marcos.
Just for information G0 is just an alias for G1:
gcode.register_command('G0', self.cmd_G1)

So you could just call G0 in G1 with same parameters. But ofc the copy is valid one less function call :slight_smile:

But this could be optimization: I think there is no reason for rebuild all params. You could just call:
G1.1 {rawparams}

Ofc, it will perfectly work as it is, take this as possibly interesting information :slight_smile:

Best regards

Thanks for the input, i know about rawparams, but in this macro you can also modify other things for the G0 or G1 commands so its nice to have to be able to modify different otther parameters.

This was new to me, thanks:
gcode.register_command('G0', self.cmd_G1)

Mind you, you can just use { rawparams } to pass the same parameters instead of rebuilding it!

So you would just have this:

[gcode_macro G0]
rename_existing: G0.1
gcode:
    {% if params.E is defined %}
        SET_VELOCITY_LIMIT ACCEL={printer.configfile.settings.printer.max_accel}
        SET_VELOCITY_LIMIT ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel/2}
    {% endif %}
    {% if params.E is not defined %}
        SET_VELOCITY_LIMIT ACCEL=6000
        SET_VELOCITY_LIMIT ACCEL_TO_DECEL=6000
    {% endif %}
    G0.1 { rawparams }

[gcode_macro G1]
rename_existing: G1.1
gcode:
    {% if params.E is defined %}
        SET_VELOCITY_LIMIT ACCEL={printer.configfile.settings.printer.max_accel}
        SET_VELOCITY_LIMIT ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel/2}
    {% endif %}
    {% if params.E is not defined %}
        SET_VELOCITY_LIMIT ACCEL=6000
        SET_VELOCITY_LIMIT ACCEL_TO_DECEL=6000
    {% endif %}
    G1.1 { rawparams }
1 Like

I know what you mean, but with this way you aren’t be able to modify these parameters anymore.
I know this is 99,9% not used/necessary, but this macro should be a complete framework for G0/G1/G2/G3 modification. If someone wants a small/easy implementation, he can use your proposal.
Thanks again for your input :+1:

1 Like

Did you notice significant CPU usage increase on the Raspberry? I’m wondering because this macro will get called very often per second if the slicer generates G-Code with “high resolution” and there are lots of curves in the object.

Its during a print and with h264 ( yes, no mjpeg ) 720p CAM streaming

/edit: to be bit more optimized, we could use if else instead of checking 2 times with if

    {% if params.E is defined %}
        SET_VELOCITY_LIMIT ACCEL={printer.configfile.settings.printer.max_accel}
        SET_VELOCITY_LIMIT ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel/2}
    {% else %}
        SET_VELOCITY_LIMIT ACCEL=6000
        SET_VELOCITY_LIMIT ACCEL_TO_DECEL=6000
    {% endif %}

i created a more cpu ressource friendly version of this script. now the cpu usage by this script is not longer noticeable:

[gcode_macro _global_variables]
variable_accel_scv_modified_is_print_move: 1
gcode:
  ; must provide something
  
[gcode_macro G0]
rename_existing: G0.1
gcode:
    {% if params.E is defined %}
        {% if printer["gcode_macro _global_variables"].accel_scv_modified_is_print_move == 0 %}
            SET_VELOCITY_LIMIT ACCEL={printer.configfile.settings.printer.max_accel}
            SET_VELOCITY_LIMIT ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel/2}
            SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={printer.configfile.settings.printer.square_corner_velocity}
            SET_GCODE_VARIABLE MACRO=_global_variables VARIABLE=accel_scv_modified_is_print_move VALUE=1
	    {% endif %}		
    {% else %}
	    {% if printer["gcode_macro _global_variables"].accel_scv_modified_is_print_move == 1 %}
            SET_VELOCITY_LIMIT ACCEL=8000
            SET_VELOCITY_LIMIT ACCEL_TO_DECEL=8000
            SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY=100
            SET_GCODE_VARIABLE MACRO=_global_variables VARIABLE=accel_scv_modified_is_print_move VALUE=0
	    {% endif %}
    {% endif %}
    G0.1 { rawparams }

[gcode_macro G1]
rename_existing: G1.1
gcode:
    {% if params.E is defined %}
        {% if printer["gcode_macro _global_variables"].accel_scv_modified_is_print_move == 0 %}
            SET_VELOCITY_LIMIT ACCEL={printer.configfile.settings.printer.max_accel}
            SET_VELOCITY_LIMIT ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel/2}
            SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={printer.configfile.settings.printer.square_corner_velocity}
		    SET_GCODE_VARIABLE MACRO=_global_variables VARIABLE=accel_scv_modified_is_print_move VALUE=1
	    {% endif %}		
    {% else %}
	    {% if printer["gcode_macro _global_variables"].accel_scv_modified_is_print_move == 1 %}
            SET_VELOCITY_LIMIT ACCEL=8000
            SET_VELOCITY_LIMIT ACCEL_TO_DECEL=8000
            SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY=100
		    SET_GCODE_VARIABLE MACRO=_global_variables VARIABLE=accel_scv_modified_is_print_move VALUE=0
	    {% endif %}
    {% endif %}
    G1.1 { rawparams }

1 Like

Would it also be possible to check for first layer in the script and if it detected it’s on the first layer it’ll set lower acceleration and square corner speed values?

sorry i dont know off the cuff how to request/read the actual layer via script. maybe s.o. knows the variable how to get the current layer information?

Thank you for your macro.
I have a concert about the high value of 100 for SQUARE_CORNER_VELOCITY. This might result in rounding corners too much and therefore hitting objects if the slicer plans a motion path close to objects.

To prevent MCU overhead, why not use the slicer to set the acceleration with M204 and overload that macro to update the SQV? The advantage for overhead is big.
SuperSlicer and other slicers can set acceleration dynamically for differentiation moves like infill, perimeter and travel.