# Custom Travel Acceleration

**URL:** <https://klipper.discourse.group/t/custom-travel-acceleration/2789>\
**Category:** Macros\
**Created:** [May 4, 2022, 2:22pm UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789 "2022-05-04T14:22:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hundsbuah](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Hundsbuah](https://klipper.discourse.group/u/Hundsbuah)\
**Post date:** [May 4, 2022, 2:22pm UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/1 "2022-05-04T14:22:41Z")

</div>

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

```auto

[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 🙂

---

<div class="post-metadata">

**Author:** ![enderbender](https://avatars.discourse-cdn.com/v4/letter/e/9de053/32.png) [@enderbender](https://klipper.discourse.group/u/enderbender)\
**Post date:** [May 4, 2022, 6:54pm UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/2 "2022-05-04T18:54:26Z")

</div>

That’s great thanks for sharing.

---

<div class="post-metadata">

**Author:** ![masterq](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@masterq](https://klipper.discourse.group/u/masterq)\
**Post date:** [May 6, 2022, 10:23pm UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/3 "2022-05-06T22:23:22Z")

</div>

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 🙂

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 🙂

Best regards

---

<div class="post-metadata">

**Author:** ![Hundsbuah](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Hundsbuah](https://klipper.discourse.group/u/Hundsbuah)\
**Post date:** [May 7, 2022, 4:26pm UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/4 "2022-05-07T16:26:39Z")

</div>

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)`

---

<div class="post-metadata">

**Author:** ![pedrolamas](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/pedrolamas/32/22261_2.png) [@pedrolamas](https://klipper.discourse.group/u/pedrolamas)\
**Post date:** [May 8, 2022, 9:05am UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/5 "2022-05-08T09:05:33Z")

</div>

> [@Hundsbuah](#):
>
> `G0.1 { p|join(" ") }`

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

So you would just have this:

```auto
[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 }

```

---

<div class="post-metadata">

**Author:** ![Hundsbuah](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Hundsbuah](https://klipper.discourse.group/u/Hundsbuah)\
**Post date:** [May 8, 2022, 9:24am UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/6 "2022-05-08T09:24:36Z")

</div>

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 👍

---

<div class="post-metadata">

**Author:** ![enderbender](https://avatars.discourse-cdn.com/v4/letter/e/9de053/32.png) [@enderbender](https://klipper.discourse.group/u/enderbender)\
**Post date:** [May 9, 2022, 12:16pm UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/7 "2022-05-09T12:16:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Hundsbuah](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Hundsbuah](https://klipper.discourse.group/u/Hundsbuah)\
**Post date:** [May 9, 2022, 1:42pm UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/8 "2022-05-09T13:42:12Z")

</div>

![2022-05-09 15_39_49-9% _ Princore ONE _ System](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/5/527f039cc360816bb705814ef0522e7a82436b16.png)

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

```auto
    {% 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 %}

```

---

<div class="post-metadata">

**Author:** ![Hundsbuah](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Hundsbuah](https://klipper.discourse.group/u/Hundsbuah)\
**Post date:** [July 12, 2022, 7:44am UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/9 "2022-07-12T07:44:19Z")

</div>

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

```auto
[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 }

```

 ![image](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/c/c580fb8b6b166f7ece2da735ab269e9f2179dfa4.png)

---

<div class="post-metadata">

**Author:** ![enderbender](https://avatars.discourse-cdn.com/v4/letter/e/9de053/32.png) [@enderbender](https://klipper.discourse.group/u/enderbender)\
**Post date:** [September 16, 2022, 1:50pm UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/11 "2022-09-16T13:50:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Hundsbuah](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@Hundsbuah](https://klipper.discourse.group/u/Hundsbuah)\
**Post date:** [October 13, 2022, 8:19am UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/12 "2022-10-13T08:19:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Henkie](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@Henkie](https://klipper.discourse.group/u/Henkie)\
**Post date:** [January 5, 2023, 11:20am UTC](https://klipper.discourse.group/t/custom-travel-acceleration/2789/13 "2023-01-05T11:20:47Z")

</div>

> [@Hundsbuah](#):
>
> ```auto
> SET_VELOCITY_LIMIT ACCEL=8000
> SET_VELOCITY_LIMIT ACCEL_TO_DECEL=8000
> SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY=100
> 
> ```

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.
