Advertisement
rootiest

HEAT_SOAK.cfg

Aug 12th, 2022
1,131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.74 KB | None | 0 0
  1. # https://klipper.discourse.group/t/interruptible-heat-soak/1552
  2. [gcode_macro HEAT_SOAK]
  3. description: heats the bed for a while
  4.  
  5. variable_target_temp: 0
  6. variable_stage: None ## heating -> soaking -> done -> None
  7.  
  8. ## in seconds
  9. variable_check_interval: 10
  10. variable_soak_time_remaining: 0
  11. variable_total_time_elapsed: 0
  12.  
  13. gcode:
  14.    {% set TARGET = params.TARGET | default(0) | float %}
  15.     {% set DURATION = (params.DURATION | default(5) | int) * 60 %} ## minutes to seconds
  16.  
  17.     SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=target_temp         VALUE={ TARGET }
  18.     SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=stage               VALUE="'heating'"
  19.     SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE={ DURATION }
  20.     SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed  VALUE=0
  21.  
  22.     ;; fire up the heater
  23.     SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ TARGET }
  24.  
  25.     ;; run the fan to circulate air
  26.     _SET_FAN_SPEED PERCENT=50
  27.  
  28.     ;; put the bed and nozzle where they're a safe distance apart
  29.     G28
  30.     CENTER
  31.  
  32.     M84 ;; turn off steppers
  33.  
  34.     UPDATE_DELAYED_GCODE ID=heat_soaker DURATION={ check_interval }
  35.  
  36. [gcode_macro CANCEL_HEAT_SOAK]
  37. description: cancels an in-progress HEAT_SOAK cycle
  38. gcode:
  39.    SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=stage VALUE="'cancel'"
  40.     UPDATE_DELAYED_GCODE ID=heat_soaker DURATION=1
  41.  
  42. [delayed_gcode heat_soaker]
  43. ; ## debug
  44. ; { action_respond_info( printer['gcode_macro HEAT_SOAK'] | tojson )}
  45. gcode:
  46.    {% set heat_soak = printer['gcode_macro HEAT_SOAK'] %}
  47.  
  48.     ## update total time elapsed
  49.     {% set total_time_elapsed = heat_soak.total_time_elapsed + heat_soak.check_interval %}
  50.     SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed VALUE={ total_time_elapsed }
  51.  
  52.     {% set stage = heat_soak.stage %}
  53.     {% if stage == "heating" and printer.heater_bed.temperature >= heat_soak.target_temp %}
  54.         {% set stage = "soaking" %}
  55.     {% endif %}
  56.  
  57.     {% if stage == "soaking" %}
  58.         ## update soak countdown
  59.         {% set soak_time_remaining = [heat_soak.soak_time_remaining - heat_soak.check_interval, 0] | max %}
  60.         SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE={ soak_time_remaining }
  61.  
  62.         {% if soak_time_remaining == 0 %}
  63.             {% set stage = "done" %}
  64.         {% endif %}
  65.     {% endif %}
  66.  
  67.     SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=stage VALUE="'{ stage }'"
  68.  
  69.     {% if stage in ("done", "cancel") %}
  70.  
  71.         {% if stage == "cancel" %}
  72.             {% set stage = "done" %}
  73.             TURN_OFF_HEATERS
  74.             M107 ; turn off fan
  75.  
  76.             M117 { "soak cancelled after ~%.1fm" | format(total_time_elapsed / 60.0) }
  77.         {% else %}
  78.             M117 { "soak complete after %.1fm" | format(total_time_elapsed / 60.0) }
  79.         {% endif %}
  80.  
  81.         ## reset all state vars, except stage, which may be queried via the api
  82.         SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=target_temp         VALUE=0
  83.         SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=soak_time_remaining VALUE=0
  84.         SET_GCODE_VARIABLE MACRO=HEAT_SOAK VARIABLE=total_time_elapsed  VALUE=0
  85.  
  86.     {% else %}
  87.  
  88.         {% if total_time_elapsed % 90 == 0 %}
  89.             ## output status periodically
  90.             {% if stage == "heating" %}
  91.                 M117 { "heating -- %.1fm elapsed" | format(total_time_elapsed / 60.0) }
  92.             {% elif stage == "soaking" %}
  93.                 M117 { "soaking -- %.1fm remaining" | format(soak_time_remaining / 60.0) }
  94.             {% endif %}
  95.         {% endif %}
  96.  
  97.         ## trigger ourselves again
  98.         UPDATE_DELAYED_GCODE ID=heat_soaker DURATION={ heat_soak.check_interval }
  99.  
  100.         ## dwell for 1ms to prevent from going idle
  101.         G4 P1
  102.  
  103.     {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement