Reviewingspy

Ellis speeds test code

Sep 23rd, 2025
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | Software | 0 0
  1. [gcode_macro TEST_SPEED]
  2. # Home, get position, throw around toolhead, home again.
  3. # If MCU stepper positions (first line in GET_POSITION) are greater than a full step different (your number of microsteps), then skipping occured.
  4. # We only measure to a full step to accomodate for endstop variance.
  5. # Example: TEST_SPEED SPEED=300 ACCEL=5000 ITERATIONS=10
  6.  
  7. description: Test for max speed and acceleration parameters for the printer. Procedure: Home -> ReadPositionFromMCU -> MovesToolhead@Vel&Accel -> Home -> ReadPositionfromMCU
  8.  
  9. gcode:
  10. # Speed
  11. {% set speed = params.SPEED|default(printer.configfile.settings.printer.max_velocity)|int %}
  12. # Iterations
  13. {% set iterations = params.ITERATIONS|default(5)|int %}
  14. # Acceleration
  15. {% set accel = params.ACCEL|default(printer.configfile.settings.printer.max_accel)|int %}
  16. # Minimum Cruise Ratio
  17. {% set min_cruise_ratio = params.MIN_CRUISE_RATIO|default(0.5)|float %}
  18. # Bounding inset for large pattern (helps prevent slamming the toolhead into the sides after small skips, and helps to account for machines with imperfectly set dimensions)
  19. {% set bound = params.BOUND|default(20)|int %}
  20. # Size for small pattern box
  21. {% set smallpatternsize = SMALLPATTERNSIZE|default(20)|int %}
  22.  
  23. # Large pattern
  24. # Max positions, inset by BOUND
  25. {% set x_min = printer.toolhead.axis_minimum.x %}
  26. {% if x_min < 0 %}
  27. {% set x_min = 0 %}
  28. {% endif %}
  29.  
  30. {% set y_min = printer.toolhead.axis_minimum.y %}
  31. {% if y_min < 0 %}
  32. {% set y_min = 0 %}
  33. {% endif %}
  34.  
  35. {% set x_min = x_min + bound %}
  36. {% set x_max = printer.toolhead.axis_maximum.x - bound %}
  37. {% set y_min = y_min + bound %}
  38. {% set y_max = printer.toolhead.axis_maximum.y - bound %}
  39.  
  40. # Small pattern at center
  41. # Find X/Y center point
  42. {% set x_center = (printer.toolhead.axis_minimum.x|float + printer.toolhead.axis_maximum.x|float ) / 2 %}
  43. {% set y_center = (printer.toolhead.axis_minimum.y|float + printer.toolhead.axis_maximum.y|float ) / 2 %}
  44.  
  45. # Set small pattern box around center point
  46. {% set x_center_min = x_center - (smallpatternsize/2) %}
  47. {% set x_center_max = x_center + (smallpatternsize/2) %}
  48. {% set y_center_min = y_center - (smallpatternsize/2) %}
  49. {% set y_center_max = y_center + (smallpatternsize/2) %}
  50.  
  51. # Save current gcode state (absolute/relative, etc)
  52. SAVE_GCODE_STATE NAME=TEST_SPEED
  53.  
  54. # Output parameters to g-code terminal
  55. { action_respond_info("TEST_SPEED: starting %d iterations at speed %d, accel %d" % (iterations, speed, accel)) }
  56.  
  57. # Home and get position for comparison later:
  58. M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66
  59. G28
  60. # QGL if not already QGLd (only if QGL section exists in config)
  61. {% if printer.configfile.settings.quad_gantry_level %}
  62. {% if printer.quad_gantry_level.applied == False %}
  63. QUAD_GANTRY_LEVEL
  64. G28 Z
  65. {% endif %}
  66. {% endif %}
  67. # Move 50mm away from max position and home again (to help with hall effect endstop accuracy - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/24)
  68. G90
  69. G1 X{printer.toolhead.axis_maximum.x-50} Y{printer.toolhead.axis_maximum.y-50} F{30*60}
  70. M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66
  71. G28 X Y
  72. G0 X{printer.toolhead.axis_maximum.x-1} Y{printer.toolhead.axis_maximum.y-1} F{30*60}
  73. G4 P1000
  74. GET_POSITION
  75.  
  76. # Go to starting position
  77. G0 X{x_min} Y{y_min} Z{bound + 10} F{speed*60}
  78.  
  79. # Set new limits
  80. {% if printer.configfile.settings.printer.minimum_cruise_ratio is defined %}
  81. SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} MINIMUM_CRUISE_RATIO={min_cruise_ratio}
  82. {% else %}
  83. SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} ACCEL_TO_DECEL={accel / 2}
  84. {% endif %}
  85.  
  86. {% for i in range(iterations) %}
  87. # Large pattern diagonals
  88. G0 X{x_min} Y{y_min} F{speed*60}
  89. G0 X{x_max} Y{y_max} F{speed*60}
  90. G0 X{x_min} Y{y_min} F{speed*60}
  91. G0 X{x_max} Y{y_min} F{speed*60}
  92. G0 X{x_min} Y{y_max} F{speed*60}
  93. G0 X{x_max} Y{y_min} F{speed*60}
  94.  
  95. # Large pattern box
  96. G0 X{x_min} Y{y_min} F{speed*60}
  97. G0 X{x_min} Y{y_max} F{speed*60}
  98. G0 X{x_max} Y{y_max} F{speed*60}
  99. G0 X{x_max} Y{y_min} F{speed*60}
  100.  
  101. # Small pattern diagonals
  102. G0 X{x_center_min} Y{y_center_min} F{speed*60}
  103. G0 X{x_center_max} Y{y_center_max} F{speed*60}
  104. G0 X{x_center_min} Y{y_center_min} F{speed*60}
  105. G0 X{x_center_max} Y{y_center_min} F{speed*60}
  106. G0 X{x_center_min} Y{y_center_max} F{speed*60}
  107. G0 X{x_center_max} Y{y_center_min} F{speed*60}
  108.  
  109. # Small pattern box
  110. G0 X{x_center_min} Y{y_center_min} F{speed*60}
  111. G0 X{x_center_min} Y{y_center_max} F{speed*60}
  112. G0 X{x_center_max} Y{y_center_max} F{speed*60}
  113. G0 X{x_center_max} Y{y_center_min} F{speed*60}
  114. {% endfor %}
  115.  
  116. # Restore max speed/accel/accel_to_decel to their configured values
  117. {% if printer.configfile.settings.printer.minimum_cruise_ratio is defined %}
  118. SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} MINIMUM_CRUISE_RATIO={printer.configfile.settings.printer.minimum_cruise_ratio}
  119. {% else %}
  120. SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel}
  121. {% endif %}
  122.  
  123. # Re-home and get position again for comparison:
  124. M400 # Finish moves - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/66
  125. G28 # This is a full G28 to fix an issue with CoreXZ - https://github.com/AndrewEllis93/Print-Tuning-Guide/issues/12
  126. # Go to XY home positions (in case your homing override leaves it elsewhere)
  127. G90
  128. G0 X{printer.toolhead.axis_maximum.x-1} Y{printer.toolhead.axis_maximum.y-1} F{30*60}
  129. G4 P1000
  130. GET_POSITION
  131.  
  132. # Restore previous gcode state (absolute/relative, etc)
  133. RESTORE_GCODE_STATE NAME=TEST_SPEED
Advertisement
Add Comment
Please, Sign In to add comment