diff --git a/macros/overrides.cfg b/macros/overrides.cfg index 1eadbf56..2b39e9b5 100644 --- a/macros/overrides.cfg +++ b/macros/overrides.cfg @@ -221,3 +221,39 @@ gcode: {% else %} SDCARD_PRINT_FILE_BASE { rawparams } {% endif %} + + +[gcode_macro SET_VELOCITY_LIMIT] +rename_existing: SET_VELOCITY_LIMIT_BASE +gcode: + {% if params.ACCEL_TO_DECEL is defined %} + + {% if params.ACCEL is defined %} + {% set accel = params.ACCEL|float %} + {% else %} + {% set accel = printer.toolhead.max_accel|float %} + {% endif %} + + {% if params.VELOCITY is defined %} + {% set velocity = params.VELOCITY|float %} + {% else %} + {% set velocity = printer.toolhead.max_velocity|float %} + {% endif %} + + {% if params.SQUARE_CORNER_VELOCITY is defined %} + {% set scv = params.SQUARE_CORNER_VELOCITY|float %} + {% else %} + {% set scv = printer.toolhead.square_corner_velocity|float %} + {% endif %} + + {% set mcr = params.ACCEL_TO_DECEL|float / accel %} + + DEBUG_ECHO PREFIX="SET_VELOCITY_LIMIT" MSG="ACCEL={accel}, VELOCITY={velocity}, SQUARE_CORNER_VELOCITY={scv}, MINIMUM_CRUISE_RATIO={mcr}" + + SET_VELOCITY_LIMIT_BASE ACCEL={accel} VELOCITY={velocity} SQUARE_CORNER_VELOCITY={scv} MINIMUM_CRUISE_RATIO={mcr} + + {% else %} + + SET_VELOCITY_LIMIT_BASE { rawparams } + + {% endif %}