I have written a macro (attached below) to test my printing speed. However, in the for-loop, the variables in the G-code are not being output correctly. For example, there is no extrusion happening. Does anyone know why this might be happening? The fixed values seem to work fine.
# TEST_PRINT_SPEED SPEED=100 ACC=3000 TEMP_NOZZLE=200 TEMP_BED=50 DIA_FILAMENT=1.75 DIA_NOZZLE=0.6 LAYER_HEIGHT=0.3 CALIBRATE=1
# example: TEST_PRINT_SPEED SPEED=100 ACC=3000 TEMP_NOZZLE=200 TEMP_BED=50 DIA_FILAMENT=1.75 DIA_NOZZLE=0.4 LAYER_HEIGHT=0.2 CALIBRATE=1
[gcode_macro TEST_PRINT_SPEED]
gcode:
# define params
{% set SPEED = params.SPEED|default(100)|int %}
{% set ACC = params.ACC|default(3000)|int %}
{% set TEMP_NOZZLE = params.TEMP_NOZZLE|default(200)|int %}
{% set TEMP_BED = params.TEMP_BED|default(50)|int %}
{% set DIA_FILAMENT = params.DIA_FILAMENT|default(1.75)|float %}
{% set DIA_NOZZLE = params.DIA_NOZZLE|default(0.4)|float %}
{% set LAYER_HEIGHT = params.LAYER_HEIGHT|default(0.2)|float %}
{% set CALIBRATE = params.CALIBRATE|default(1)|int %}
{% set LAYER_WIDTH = DIA_NOZZLE * 1.2|float %}
{% set DISTANCE = 100|int %}
# calculate extrusion lengths
{% set extrusion_area = (LAYER_WIDTH - LAYER_HEIGHT) * LAYER_HEIGHT + 3.14159 * (LAYER_HEIGHT / 2) ** 2 %}
{% set filament_length = (extrusion_area * DISTANCE * 4 / (3.14159 * DIA_FILAMENT ** 2))|round(5) %}
{% set filament_prime_length = (extrusion_area * 50 * 4 / (3.14159 * DIA_FILAMENT ** 2))|round(5) %}
# calculate and display volumetric flowrate
{% set extrusion_volume = extrusion_area * DISTANCE %}
{% set time_for_extrusion = DISTANCE / SPEED %}
{% set volumetric_flow_rate = extrusion_volume / time_for_extrusion %}
{ action_respond_info("Volumetric E: %f mm³/s" % volumetric_flow_rate) }
# set acceleration
M204 S{ACC}
# homing
M107
G90
G28
G1 Z50
# preheat
M140 S{TEMP_BED}
M104 S130
M109 S130
M190 S{TEMP_BED}
{% if CALIBRATE == 1 %}
BED_MESH_CALIBRATE
{% endif %}
# go to start position
G1 X0 Y50 F{SPEED*60}
M109 S{TEMP_NOZZLE}
G1 Z{LAYER_HEIGHT}
# primeline
G1 E3 F500
G1 X50 E{filament_prime_length} F500
# print loop
{% for i in range(5) %}
# set first layer speed
{% if i == 0 %}
{% set layer_speed = 60 %}
{% else %}
{% set layer_speed = SPEED %}
{% endif %}
{ action_respond_info("Layer Speed %f" % layer_speed) }
{ action_respond_info("%f" % DIA_FILAMENT) }
{ action_respond_info("%f" % LAYER_HEIGHT) }
{ action_respond_info("%f" % LAYER_WIDTH) }
{ action_respond_info("%f" % filament_length) }
# move and extrude
G1 X{DISTANCE + 50} E{filament_length} F{layer_speed*60}
G1 Y{DISTANCE + 50} E{filament_length} F{layer_speed*60}
G1 X50 E{filament_length} F{layer_speed*60}
G1 Y50 E{filament_length} F{layer_speed*60}
G1 Z{LAYER_HEIGHT} F10000
# enable fan after first layer
{% if i == 0 %}
M106 S255
{% endif %}
{% endfor %}
# end position
G1 Z50 X0 Y100 F10000
M106 S0
print_speed.txt (3.0 KB)