0
$\begingroup$

It is my vague understanding that the following macro somehow controls acceleration and accel to decel.

  1. How do I set the speed I want for say, acceleration in this macro?

  2. If acceleration is set in this macro and also set in a slicer like Cura, which value will end up being implemented?

I would greatly appreciate it if someone were to walk me through whats happening in the macro conditional. I have experience with php bot nil with Python.

[gcode_macro M204]
rename_existing: M204.1
gcode:
  {% set f = params.F|default(0.5)|float %}

  {% if 'S' in params %}
    {% set s = params.S|float %}
    SET_VELOCITY_LIMIT ACCEL={s} ACCEL_TO_DECEL={ s * f }
  {% else %}
    {% if 'P' in params %}
  {% set p = params.P|float %}
  {% if 'T' in params %}
    {% set t = params.T|float %}
    {% if p < t %}
      SET_VELOCITY_LIMIT ACCEL={p} ACCEL_TO_DECEL={ p * f }
    {% else %}
      SET_VELOCITY_LIMIT ACCEL={t} ACCEL_TO_DECEL={ t * f }
    {% endif %}
  {% else %}
    SET_VELOCITY_LIMIT ACCEL={p} ACCEL_TO_DECEL={ p * f }
  {% endif %}
{% elif 'T' in params %}
  {% set t = params.T|float %}
  SET_VELOCITY_LIMIT ACCEL={t} ACCEL_TO_DECEL={ t * f }
{% endif %}
{% endif %}
$\endgroup$

1 Answer 1

0
$\begingroup$

The M204 command is how gcode sets the acceleration for moves that follow (up until the next M204 command changes it). This command appears in gcode generated by a slicer with "acceleration control" enabled. You can also write it manually in your start gcode (not very useful unless acceleration control is off, since the first slicer-emitted M204 will override it, but may be useful for priming line, etc.) or send it manually over a terminal session/via Octoprint terminal/etc.

The macro you're looking at overrides the M204 command and replaces it with one that does several things:

  • Does an over-complicated staircase of if/else clauses to accept the Marlin P and T parameters to the M204 command for separate print and travel accelerations, but then ignores them and just uses the min of the two.

  • Accepts a new F parameter (likely meaning factor) and sets Klipper's "accel to decel" setting to this factor times the requested acceleration. This allows "accel to decel" to be kept consistently to whatever the desired percentage of the acceleration limit is, even under changes in acceleration.

Aside from the if/else staircase being a mess, this macro fails to save the factor passed by F, so unless the slicer knows to emit F each time it emits an M204 command, it's always going to be resetting the factor to 0.5 (the default above) each time acceleration changes. Klipper allows definition of persistent variables for gcode macros; this is probably what the author intended to do but didn't know how to do.

Overall, the above looks not-very-useful. "Accel to decel" is a questionable feature to begin with, and with input shaper, it arguably just makes your prints a lot slower with no benefit. The modern recommendation of most folks is that you just set max_accel_to_decel to 999999999 in your configuration to turn it off, rather than going through hoops to change it dynamically like this, as long as you have turned on input shaping.

In any case, the presence of this macro in no ways interferes with acceleration control by the slicer, and you don't have to "use" this macro at all. It's purpose is not for you to "use" it but for it to hook the M204 commands the slicer emitted and make them do something extra.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .