Advertisement
KirboWnz

gcode_macro.cfg

Sep 7th, 2023
1,991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 14.57 KB | None | 0 0
  1. root@creality /usr/share [#] cat klipper/config/K1_MAX_CR4CU220812S11/gcode_macro.cfg
  2. # K1-MAX
  3. # CreateDate: 2023/03/15
  4. # history: 1. date: 2023.03.17
  5. #             modify: [gcode_macro END_PRINT]
  6. #          2. date: 2023.03.20
  7. #             delete: [gcode_macro Qmode].printer_state
  8. #          3. date: 2023.03.23
  9. #             modify: [gcode_macro LOAD_MATERIAL]
  10. #                     [gcode_macro QUIT_MATERIAL]
  11.  
  12. [gcode_macro PRINTER_PARAM]
  13. variable_z_safe_pause: 0.0
  14. variable_z_safe_g28: 3.0
  15. variable_max_x_position: 300.0
  16. variable_max_y_position: 300.0
  17. variable_max_z_position: 300.0
  18. variable_fans: 3
  19. variable_auto_g29: 0
  20. variable_fan0_min: 50
  21. variable_fan1_min: 50
  22. variable_fan2_min: 180
  23. variable_fan2_speed: 0
  24. gcode:
  25. [gcode_macro AUTOTUNE_SHAPERS]
  26. variable_autotune_shapers: 'ei'
  27. gcode:
  28. [gcode_macro LOAD_MATERIAL_CLOSE_FAN2]
  29. variable_fan2_value: 0
  30. gcode:
  31.  SAVE_GCODE_STATE NAME=myMoveState
  32.   {% if printer['output_pin fan2'].value > 0.0 %}
  33.     SET_GCODE_VARIABLE MACRO=LOAD_MATERIAL_CLOSE_FAN2 VARIABLE=fan2_value VALUE={printer['output_pin fan2'].value}
  34.     M107 P2
  35.   {% endif %}
  36.  
  37. [gcode_macro LOAD_MATERIAL_RESTORE_FAN2]
  38. gcode:
  39.  {% set fan2_value = printer['gcode_macro LOAD_MATERIAL_CLOSE_FAN2'].fan2_value|float %}
  40.   RESTORE_GCODE_STATE NAME=myMoveState
  41.   {% if fan2_value > 0.0 %}
  42.     {% set s_value = (fan2_value * 255 - printer["gcode_macro PRINTER_PARAM"].fan2_min) * 255 / (255 - printer["gcode_macro PRINTER_PARAM"].fan2_min) %}
  43.     M106 P2 S{s_value}
  44.     SET_GCODE_VARIABLE MACRO=LOAD_MATERIAL_CLOSE_FAN2 VARIABLE=fan2_value VALUE=0
  45.   {% endif %}
  46.  
  47. [gcode_macro LOAD_MATERIAL]
  48. gcode:
  49.  LOAD_MATERIAL_CLOSE_FAN2
  50.   M109 S{printer.custom_macro.default_extruder_temp}
  51.   G91
  52.   G1 E150 F180
  53.   LOAD_MATERIAL_RESTORE_FAN2
  54.  
  55. [gcode_macro QUIT_MATERIAL]
  56. gcode:
  57.  SAVE_GCODE_STATE NAME=myMoveState
  58.   M109 S{printer.custom_macro.default_extruder_temp}
  59.   G91
  60.   G1 E20 F180
  61.   G1 E-30 F180
  62.   G1 E-50 F2000
  63.   RESTORE_GCODE_STATE NAME=myMoveState
  64.  
  65. [gcode_macro Qmode]
  66. variable_flag: 0
  67. variable_accel: 0
  68. variable_accel_to_decel: 0
  69. variable_velocity: 0
  70. variable_square_corner_velocity: 0
  71. variable_pressure_advance:0.0
  72. variable_fan0_value: 0.00
  73. variable_fan1_value: 0.00
  74. variable_fan2_value: 0.00
  75. variable_speed_factor: 0
  76. gcode:
  77.  {% set printer_state = printer.print_stats.state %}
  78.   {% if printer['gcode_macro Qmode'].flag|int == 0 %}
  79.     {% if printer_state == "printing" or printer_state == "paused" %}
  80.       SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=accel VALUE={printer.toolhead.max_accel}
  81.       SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=accel_to_decel VALUE={printer.toolhead.max_accel_to_decel}
  82.       SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=velocity VALUE={printer.toolhead.max_velocity}
  83.       SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=square_corner_velocity VALUE={printer.toolhead.square_corner_velocity}
  84.       SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=pressure_advance VALUE={printer.extruder.pressure_advance}
  85.       SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=speed_factor VALUE={printer.gcode_move.speed_factor}
  86.       SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=fan0_value VALUE={printer['output_pin fan0'].value}
  87.       SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=fan1_value VALUE={printer['output_pin fan1'].value}
  88.       SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=fan2_value VALUE={printer['output_pin fan2'].value}
  89.       SET_TMC_FIELD STEPPER=stepper_x FIELD=en_spreadcycle VALUE=0
  90.       SET_TMC_FIELD STEPPER=stepper_y FIELD=en_spreadcycle VALUE=0
  91.  
  92.       # Set Motion Parameters
  93.       SET_VELOCITY_LIMIT ACCEL=5000
  94.       SET_VELOCITY_LIMIT ACCEL_TO_DECEL=2500
  95.       SET_VELOCITY_LIMIT VELOCITY=200
  96.       SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY=5
  97.       SET_PRESSURE_ADVANCE ADVANCE=0.05
  98.       M220 S50
  99.       M106 P0 S80
  100.       M106 P1 S0
  101.       M106 P2 S0
  102.       SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=flag VALUE=1
  103.     {% endif %}
  104.   {% endif %}
  105.  
  106. [gcode_macro Qmode_exit]
  107. gcode:
  108.  {% set printer_state = printer.print_stats.state %}
  109.   {% if printer['gcode_macro Qmode'].flag|int == 1 %}
  110.     {% if printer_state == "printing" or printer_state == "paused" %}
  111.       SET_VELOCITY_LIMIT ACCEL={printer['gcode_macro Qmode'].accel}
  112.       SET_VELOCITY_LIMIT ACCEL_TO_DECEL={printer['gcode_macro Qmode'].accel_to_decel}
  113.       SET_VELOCITY_LIMIT VELOCITY={printer['gcode_macro Qmode'].velocity}
  114.       SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={printer['gcode_macro Qmode'].square_corner_velocity}
  115.       SET_PRESSURE_ADVANCE ADVANCE={printer['gcode_macro Qmode'].pressure_advance}
  116.       M220 S{printer['gcode_macro Qmode'].speed_factor * 100}
  117.       M106 P0 S{(printer['gcode_macro Qmode'].fan0_value * 255 + 0.5)|int}
  118.       M106 P1 S{(printer['gcode_macro Qmode'].fan1_value * 255 + 0.5)|int}
  119.       M106 P2 S{(printer['gcode_macro Qmode'].fan2_value * 255 + 0.5)|int}
  120.       SET_TMC_FIELD STEPPER=stepper_x FIELD=en_spreadcycle VALUE=1
  121.       SET_TMC_FIELD STEPPER=stepper_y FIELD=en_spreadcycle VALUE=1
  122.       SET_GCODE_VARIABLE MACRO=Qmode VARIABLE=flag VALUE=0
  123.     {% endif %}
  124.   {% endif %}
  125.  
  126. [gcode_macro M204]
  127. rename_existing: M204.1
  128. gcode:
  129.  {% if printer['gcode_macro Qmode'].flag|int == 0 %}
  130.     {% set get_params = "" %}
  131.     {% if 'S' in params|upper %}
  132.       {% set get_params = (get_params + ' ' + 'S' + params.S) %}
  133.     {% endif %}
  134.     {% if 'P' in params|upper %}
  135.       {% set get_params = (get_params + ' ' + 'P' + params.P) %}
  136.     {% endif %}
  137.     {% if 'T' in params|upper %}
  138.       {% set get_params = (get_params + ' ' + 'T' + params.T) %}
  139.     {% endif %}
  140.     M204.1 {get_params}
  141.   {% endif %}
  142.  
  143. [gcode_macro M205]
  144. gcode:
  145.  {% if 'X' in params %}
  146.     SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={params.X}
  147.   {% elif 'Y' in params %}
  148.     SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY={params.Y}
  149.   {% endif %}
  150.  
  151. [gcode_macro M106]
  152. gcode:
  153.  {% set fans = printer["gcode_macro PRINTER_PARAM"].fans|int %}
  154.   {% set fan = 0 %}
  155.   {% set value = 0 %}
  156.   {% if params.P is defined %}
  157.     {% set tmp = params.P|int %}
  158.     {% if tmp < fans %}
  159.       {% set fan = tmp %}
  160.     {% endif %}
  161.   {% endif %}
  162.   {% if params.S is defined %}
  163.     {% set tmp = params.S|float %}
  164.   {% else %}
  165.     {% set tmp = 255 %}
  166.   {% endif %}
  167.   {% if tmp > 0 %}
  168.     {% if fan == 0 %}
  169.       {% set value = printer["gcode_macro PRINTER_PARAM"].fan0_min + (255 - printer["gcode_macro PRINTER_PARAM"].fan0_min) / 255 * tmp %}
  170.     {% endif %}
  171.     {% if fan == 1 %}
  172.       {% set value = printer["gcode_macro PRINTER_PARAM"].fan1_min + (255 - printer["gcode_macro PRINTER_PARAM"].fan1_min) / 255 * tmp %}
  173.     {% endif %}
  174.     {% if fan == 2 %}
  175.       {% set value = printer["gcode_macro PRINTER_PARAM"].fan2_min + (255 - printer["gcode_macro PRINTER_PARAM"].fan2_min) / 255 * tmp %}
  176.     {% endif %}
  177.   {% endif %}
  178.   {% if value >= 255 %}
  179.     {% set value = 255 %}
  180.   {% endif %}
  181.   SET_PIN PIN=fan{fan} VALUE={value}
  182.  
  183. [gcode_macro M107]
  184. gcode:
  185.  {% if params.P is defined %}
  186.     SET_PIN PIN=fan{params.P|int} VALUE=0
  187.   {% else %}
  188.     SET_PIN PIN=fan0 VALUE=0
  189.     SET_PIN PIN=fan2 VALUE=0
  190.   {% endif %}
  191.  
  192. [gcode_macro M900]
  193. gcode:
  194.  {% if 'K' in params %}
  195.     {% if 'E' in params %}
  196.       SET_PRESSURE_ADVANCE EXTRUDER={params.E} ADVANCE={params.K}
  197.     {% else %}
  198.       SET_PRESSURE_ADVANCE ADVANCE={params.K}
  199.     {% endif %}
  200.   {% endif %}
  201.  
  202. [delayed_gcode wait_temp]
  203. # initial_duration: 2.
  204. gcode:
  205.  {% set cur_temp = printer.extruder.temperature %}
  206.   {% if cur_temp|int < 40 %}
  207.     {action_respond_info("end_temp!\n")}
  208.     WAIT_TEMP_END
  209.   {% else %}
  210.     {action_respond_info("cur_temp = %s \n" % (cur_temp))}
  211.     UPDATE_DELAYED_GCODE ID=wait_temp DURATION=5
  212.   {% endif %}
  213.  
  214. [gcode_macro WAIT_TEMP_START]
  215. gcode:
  216.  UPDATE_DELAYED_GCODE ID=wait_temp DURATION=1
  217.   M106 P0 S255
  218.   M106 P2 S255
  219.  
  220. [gcode_macro WAIT_TEMP_END]
  221. gcode:
  222.  UPDATE_DELAYED_GCODE ID=wait_temp DURATION=0
  223.   M106 P0 S0
  224.   M106 P2 S0
  225.  
  226. [gcode_macro PRINT_CALIBRATION]
  227. # This part of the command is replaced by the application side without passing parameters
  228. # The macro of LASER_CALIBRATION is for application use and has not been implemented
  229. # The macro of FLOW_DETECTION is for application use and has not been implemented
  230. gcode:
  231.  CX_PRINT_LEVELING_CALIBRATION
  232.   LASER_CALIBRATION
  233.   FLOW_DETECTION
  234.  
  235. [gcode_macro FIRST_FLOOR_PAUSE_POSITION]
  236. gcode:
  237.  {% set extruder_temp = printer.custom_macro.g28_ext_temp %}
  238.   M104 S{extruder_temp}
  239.   {% set y_park = printer.toolhead.axis_maximum.y/2 %}
  240.   {% set x_park = printer['gcode_macro PRINTER_PARAM'].max_x_position|float + 1 %}
  241.   G90
  242.   G1 X{x_park} Y{y_park} Z2.0 F6000
  243.   G1 Z0.2 F600
  244.  
  245. [gcode_macro ACCURATE_G28]
  246. gcode:
  247.  G28 Z
  248.  
  249. [gcode_macro START_PRINT]
  250. gcode:
  251.  WAIT_TEMP_END
  252.   CLEAR_PAUSE
  253.   {% set g28_extruder_temp = printer.custom_macro.g28_ext_temp %}
  254.   {% set bed_temp = printer.custom_macro.default_bed_temp %}
  255.   {% set extruder_temp = printer.custom_macro.default_extruder_temp %}
  256.  
  257.   {% if 'BED_TEMP' in params|upper and (params.BED_TEMP|float) %}
  258.     {% set bed_temp = params.BED_TEMP %}
  259.   {% endif %}
  260.  
  261.   {% if 'EXTRUDER_TEMP' in params|upper and (params.EXTRUDER_TEMP|float) %}
  262.     {% set extruder_temp = params.EXTRUDER_TEMP %}
  263.   {% endif %}
  264.  
  265.   CX_PRINT_DRAW_ONE_LINE
  266.  
  267. [gcode_macro END_PRINT_POINT]
  268. gcode:
  269.  {% if "xyz" in printer.toolhead.homed_axes %}
  270.     {% set max_z = printer["gcode_macro PRINTER_PARAM"].max_z_position|float %}
  271.     {% set act_z = printer.toolhead.position.z|float %}
  272.     {% set z_safe = 0.0 %}
  273.     {% if act_z < (max_z / 2) %}
  274.       {% set z_safe = (max_z / 2) - act_z %}
  275.     {% elif act_z < max_z %}
  276.       {% set z_safe = 2.0 %}
  277.     {% endif %}
  278.     G91
  279.     G1 Z{z_safe} F600
  280.     G90
  281.     {% set y_park = printer.toolhead.axis_maximum.y/2 %}
  282.     {% set x_park = printer.toolhead.axis_maximum.x|float - 10.0 %}
  283.     G1 X{x_park} Y{y_park} F6000
  284.   {% else %}
  285.     {action_respond_info("end print xyz_axes is NULL\n")}
  286.   {% endif %}
  287.  
  288. [gcode_macro END_PRINT]
  289. gcode:
  290.  # Qmode_exit
  291.   M220 S100
  292.   M204 S500
  293.   TURN_OFF_HEATERS
  294.   M107 P1
  295.   END_PRINT_POINT
  296.   WAIT_TEMP_START
  297.   M84
  298.  
  299. [gcode_macro PAUSE]
  300. description: Pause the actual running print
  301. rename_existing: PAUSE_BASE
  302. # change this if you need more or less extrusion
  303. variable_extrude: 1.0
  304. gcode:
  305.  ##### read E from pause macro #####
  306.   {% set E = printer["gcode_macro PAUSE"].extrude|float %}
  307.   ##### set park positon for x and y #####
  308.   # default is your max posion from your printer.cfg
  309.   {% set y_park = printer.toolhead.axis_maximum.y/2 %}
  310.   {% set x_park = printer.toolhead.axis_maximum.x|float - 10.0 %}
  311.   # save fan2 value and turn off fan2
  312.   SET_GCODE_VARIABLE MACRO=PRINTER_PARAM VARIABLE=fan2_speed VALUE={printer['output_pin fan2'].value}
  313.   # {% set fspeed = printer['gcode_macro PRINTER_PARAM'].fan2_speed %}
  314.   # {action_respond_info("fan2_value1 = %s \n" % (fspeed))}
  315.   # SET_PIN PIN=fan2 VALUE=0
  316.   M106 P2 S0
  317.   ##### calculate save lift position #####
  318.   {% set max_z = printer["gcode_macro PRINTER_PARAM"].max_z_position|float %}
  319.   {% set act_z = printer.toolhead.position.z|float %}
  320.   {% set z_safe = 0.0 %}
  321.   {% if act_z < (max_z - 2.0) %}
  322.     {% set z_safe = 2.0 %}
  323.   {% elif act_z < max_z %}
  324.     {% set z_safe = max_z - act_z %}
  325.   {% endif %}
  326.   ##### end of definitions #####
  327.   SET_GCODE_VARIABLE MACRO=PRINTER_PARAM VARIABLE=z_safe_pause VALUE={z_safe|float}
  328.   PAUSE_BASE
  329.   G91
  330.   {% if printer.extruder.can_extrude|lower == 'true' %}
  331.     G1 E-{E} F2100
  332.   {% else %}
  333.     {action_respond_info("Extruder not hot enough")}
  334.   {% endif %}
  335.   {% if "xyz" in printer.toolhead.homed_axes %}
  336.     G1 Z{z_safe} F600
  337.     G90
  338.     G1 X{x_park} Y{y_park} F6000
  339.   {% else %}
  340.     {action_respond_info("Printer not homed")}
  341.   {% endif %}
  342.  
  343. [gcode_macro INPUTSHAPER]
  344. gcode:
  345.  SET_FILAMENT_SENSOR SENSOR=filament_sensor ENABLE=0
  346.   G90
  347.   G28
  348.   {% set POSITION_X = printer.configfile.settings['stepper_x'].position_max/2 %}
  349.   {% set POSITION_Y = printer.configfile.settings['stepper_y'].position_max/2 %}
  350.   G1 X{POSITION_X} Y{POSITION_Y} Z5 F6000
  351.   SHAPER_CALIBRATE
  352.   CXSAVE_CONFIG
  353.   SET_FILAMENT_SENSOR SENSOR=filament_sensor ENABLE=1
  354.  
  355. [gcode_macro BEDPID]
  356. gcode:
  357.  PID_CALIBRATE HEATER=heater_bed TARGET=100
  358.   SAVE_CONFIG
  359.  
  360. [gcode_macro TUNOFFINPUTSHAPER]
  361. gcode:
  362.  SET_INPUT_SHAPER SHAPER_FREQ_X=0 SHAPER_FREQ_Y=0
  363.  
  364. [gcode_macro RESUME]
  365. description: Resume the actual running print
  366. rename_existing: RESUME_BASE
  367. gcode:
  368.  {% if printer['gcode_macro PRINTER_PARAM'].fan2_speed > 0 %}
  369.     # {% set fspeed = printer['gcode_macro PRINTER_PARAM'].fan2_speed %}
  370.     # {action_respond_info("fan2_value2 = %s \n" % (fspeed))}
  371.     # SET_PIN PIN=fan2 VALUE={(printer['gcode_macro PRINTER_PARAM'].fan2_speed * 255 + 0.5)|int}
  372.     {% set s_value = (printer['gcode_macro PRINTER_PARAM'].fan2_speed * 255 - printer['gcode_macro PRINTER_PARAM'].fan2_min) * 255 / (255 - printer['gcode_macro PRINTER_PARAM'].fan2_min)|float %}
  373.     M106 P2 S{s_value}
  374.   {% endif %}
  375.   ##### read E from pause macro #####
  376.   {% set E = printer["gcode_macro PAUSE"].extrude|float %}
  377.   #### get VELOCITY parameter if specified ####
  378.   {% if 'VELOCITY' in params|upper %}
  379.     {% set get_params = ('VELOCITY=' + params.VELOCITY) %}
  380.   {%else %}
  381.     {% set get_params = "" %}
  382.   {% endif %}
  383.   ##### end of definitions #####
  384.   {% if printer.extruder.can_extrude|lower == 'true' %}
  385.     G91
  386.     G1 E{E} F2100
  387.   {% else %}
  388.     {action_respond_info("Extruder not hot enough")}
  389.   {% endif %}
  390.   RESUME_BASE {get_params}
  391.  
  392. [gcode_macro CANCEL_PRINT]
  393. description: Cancel the actual running print
  394. rename_existing: CANCEL_PRINT_BASE
  395. gcode:
  396.  END_PRINT
  397.   CANCEL_PRINT_BASE
  398.  
  399. [gcode_macro G29]
  400. gcode:
  401.  {% if 'PROBE_COUNT' in params|upper %}
  402.     {% set get_count = ('PROBE_COUNT' + params.PROBE_COUNT) %}
  403.   {%else %}
  404.     {% set get_count = "" %}
  405.   {% endif %}
  406.  
  407.   {% set bed_temp = printer.custom_macro.default_bed_temp %}
  408.   {% set extruder_temp = printer.custom_macro.g28_ext_temp %}
  409.   {% set nozzle_clear_temp = printer.custom_macro.default_extruder_temp %}
  410.  
  411.   {% if 'BED_TEMP' in params|upper %}
  412.     {% set bed_temp = params.BED_TEMP %}
  413.   {% endif %}
  414.  
  415.   {% if 'EXTRUDER_TEMP' in params|upper %}
  416.     {% set nozzle_clear_temp = params.EXTRUDER_TEMP %}
  417.   {% endif %}
  418.  
  419.   G28
  420.   BED_MESH_CLEAR
  421.   NOZZLE_CLEAR HOT_MIN_TEMP={extruder_temp} HOT_MAX_TEMP={nozzle_clear_temp} BED_MAX_TEMP={bed_temp}
  422.   ACCURATE_G28
  423.   M204 S5000
  424.   SET_VELOCITY_LIMIT ACCEL_TO_DECEL=5000
  425.   BED_MESH_CALIBRATE {get_count}
  426.   BED_MESH_OUTPUT
  427.   {% set y_park = printer.toolhead.axis_maximum.y/2 %}
  428.   {% set x_park = printer.toolhead.axis_maximum.x|float - 10.0 %}
  429.   G1 X{x_park} Y{y_park} F2000
  430.   CXSAVE_CONFIG
  431.   TURN_OFF_HEATERS
  432.  
  433. # [gcode_macro G299]
  434. # gcode:
  435. #     BED_MESH_CLEAR
  436. #     G28
  437. #     PRTOUCH_READY
  438. #     BED_MESH_CALIBRATE
  439. #     BED_MESH_OUTPUT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement