Skip to content

Commit

Permalink
start print behaviour improved
Browse files Browse the repository at this point in the history
  • Loading branch information
HelgeKeck committed Apr 27, 2024
1 parent 6f5628c commit 7441aac
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 67 deletions.
4 changes: 2 additions & 2 deletions klippy/rmmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def load_filament_from_parking_position_to_tx_parking_sensor(self, tool):

def load_filament_from_parking_sensor_to_toolhead_sensor(self, tool):
# echo
self.ratos_echo("Loading filament T" + str(tool) + " from parking sensor to parking position...")
self.ratos_echo("Loading filament T" + str(tool) + " from parking sensor to toolhead sensor...")

# enable toolhead sensor endstop
self.set_pulley_endstop(self.toolhead_sensor_endstop)
Expand All @@ -546,7 +546,7 @@ def load_filament_from_parking_sensor_to_toolhead_sensor(self, tool):
return False

# echo
self.ratos_echo("Filament T" + str(tool) + " loaded to parking position!")
self.ratos_echo("Filament T" + str(tool) + " loaded to toolhead sensor!")

# success
return True
Expand Down
33 changes: 15 additions & 18 deletions klippy/rmmu_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,58 +197,55 @@ def start_print(self, param):

# check for filament in hotend
for physical_toolhead in used_toolheads:
initial_tool = -1
for t in used_tools:
if physical_toolhead == int(self.mapping[str(t)]["TOOLHEAD"]):
initial_tool = int(self.mapping[str(t)]["FILAMENT"])
self.rmmu[physical_toolhead].initial_filament = t
break
# handle toolhead mapping
# self.initial_filament = self.get_remapped_toolhead(self.initial_filament)
rmmu = self.rmmu[physical_toolhead]
rmmu.initial_filament = initial_tool
rmmu.needs_initial_purging = True
if rmmu.is_sensor_triggered(rmmu.toolhead_filament_sensor):
loaded_filament = rmmu.get_status(self.toolhead.get_last_move_time())['loaded_filament']
loaded_filament_temp = rmmu.get_status(self.toolhead.get_last_move_time())['loaded_filament_temp']
self.rmmu[physical_toolhead].needs_initial_purging = True
if self.rmmu[physical_toolhead].is_sensor_triggered(self.rmmu[physical_toolhead].toolhead_filament_sensor):
loaded_filament = self.rmmu[physical_toolhead].get_status(self.toolhead.get_last_move_time())['loaded_filament']
loaded_filament_temp = self.rmmu[physical_toolhead].get_status(self.toolhead.get_last_move_time())['loaded_filament_temp']
if loaded_filament >=0 and loaded_filament <= self.total_tool_count:
if loaded_filament != rmmu.initial_filament:
if loaded_filament_temp > rmmu.heater.min_extrude_temp and loaded_filament_temp < rmmu.heater.max_temp:
if loaded_filament != self.rmmu[physical_toolhead].initial_filament:
if loaded_filament_temp > self.rmmu[physical_toolhead].heater.min_extrude_temp and loaded_filament_temp < self.rmmu[physical_toolhead].heater.max_temp:
# unloaded the filament that is already loaded
self.ratos_echo("Wrong filament detected in hotend!")
self.ratos_echo("Unloading filament T" + str(loaded_filament) + "! Please wait...")

# start heating up extruder but dont wait for it so we can save some time
self.ratos_echo("Preheating extruder to " + str(loaded_filament_temp) + "°C.")
rmmu.extruder_set_temperature(loaded_filament_temp, False)
self.rmmu[physical_toolhead].extruder_set_temperature(loaded_filament_temp, False)

# home printer if needed and move toolhead to its parking position
self.gcode.run_script_from_command('MAYBE_HOME')
if rmmu.initial_filament >= self.rmmu[0].tool_count:
if self.rmmu[physical_toolhead].initial_filament >= self.rmmu[0].tool_count:
self.gcode.run_script_from_command('_MOVE_TO_LOADING_POSITION TOOLHEAD=1')
else:
self.gcode.run_script_from_command('_MOVE_TO_LOADING_POSITION TOOLHEAD=0')

# wait for the extruder to heat up
self.ratos_echo("Heating up extruder to " + str(loaded_filament_temp) + "°C! Please wait...")
rmmu.extruder_set_temperature(loaded_filament_temp, True)
self.rmmu[physical_toolhead].extruder_set_temperature(loaded_filament_temp, True)

# unload filament
if not rmmu.unload_filament(loaded_filament):
rmmu.extruder_set_temperature(0, False)
if not self.rmmu[physical_toolhead].unload_filament(loaded_filament):
self.rmmu[physical_toolhead].extruder_set_temperature(0, False)
raise self.printer.command_error("Could not unload filament! Please unload the filament and restart the print.")

# cool down extruder, dont wait for it
rmmu.extruder_set_temperature(0, False)
self.rmmu[physical_toolhead].extruder_set_temperature(0, False)
else:
raise self.printer.command_error("Unknown filament detected in toolhead! Please unload the filament and restart the print.")
else:
# tell RatOS that initial purging is not needed
rmmu.needs_initial_purging = False
self.rmmu[physical_toolhead].rmmu[physical_toolhead].needs_initial_purging = False
else:
raise self.printer.command_error("Unknown filament detected in toolhead! Please unload the filament and restart the print.")

# disable toolhead filament sensor
rmmu.toolhead_filament_sensor.runout_helper.sensor_enabled = False
self.rmmu[physical_toolhead].toolhead_filament_sensor.runout_helper.sensor_enabled = False

# test if all demanded filaments are available and raises an error if not
self.test_filaments(used_tools)
Expand Down
88 changes: 41 additions & 47 deletions macros.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,15 @@ gcode:
{% set both_toolheads = false %}
{% set physical_t0_used = false %}
{% set physical_t1_used = false %}
{% for t in range(printer["rmmu_hub"].total_tool_count) %}
{% set key = "T%s" % t|string %}
{% if params[key] is defined %}
{% if params[key]|default("true") == true %}
{% if printer["rmmu_hub"].mapping["%s" % t]["TOOLHEAD"]|int == 0 %}
{% set physical_t0_used = true %}
{% elif printer["rmmu_hub"].mapping["%s" % t]["TOOLHEAD"]|int == 1 %}
{% set physical_t1_used = true %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% if printer["rmmu RMMU_T0"].initial_filament|int != -1 %}
{% set physical_t0_used = true %}
{% endif %}
{% if printer["rmmu RMMU_T1"] is defined and printer["rmmu RMMU_T1"].initial_filament|int != -1 %}
{% set physical_t1_used = true %}
{% endif %}
{% if physical_t0_used and physical_t1_used %}
{% set both_toolheads = true %}
{% endif %}
{% endif %}

# cache print variables
Expand Down Expand Up @@ -569,22 +566,11 @@ gcode:
{% if idex_mode == '' %}
M104 S{extruder_temp}
{% else %}
{% if printer["rmmu_hub"] is not defined %}
# IDEX
{% if initial_tool == 0 or both_toolheads %}
M104 S{extruder_temp} T0
{% endif %}
{% if initial_tool == 1 or both_toolheads %}
M104 S{extruder_temp_1|default(printer.extruder1.target, true)} T1
{% endif %}
{% else %}
# IDEX RMMU
{% if initial_tool == 0 or (physical_t0_used and physical_t1_used) %}
M104 S{extruder_temp} T0
{% endif %}
{% if initial_tool == 1 or (physical_t0_used and physical_t1_used) %}
M104 S{extruder_temp_1|default(printer.extruder1.target, true)} T1
{% endif %}
{% if initial_tool == 0 or both_toolheads %}
M104 S{extruder_temp} T0
{% endif %}
{% if initial_tool == 1 or both_toolheads %}
M104 S{extruder_temp_1|default(printer.extruder1.target, true)} T1
{% endif %}
{% endif %}

Expand All @@ -599,51 +585,54 @@ gcode:
{% if idex_mode == '' %}
M109 S{extruder_temp}
{% else %}
{% if printer["rmmu_hub"] is not defined %}
# IDEX
{% if initial_tool == 0 or both_toolheads %}
M109 S{extruder_temp} T0
{% endif %}
{% if initial_tool == 1 or both_toolheads %}
M109 S{extruder_temp_1|default(printer.extruder1.target, true)} T1
{% endif %}
{% else %}
# IDEX RMMU
{% if initial_tool == 0 or (physical_t0_used and physical_t1_used) %}
M109 S{extruder_temp} T0
{% endif %}
{% if initial_tool == 1 or (physical_t0_used and physical_t1_used) %}
M109 S{extruder_temp_1|default(printer.extruder1.target, true)} T1
{% endif %}
{% if initial_tool == 0 or both_toolheads %}
M109 S{extruder_temp} T0
{% endif %}
{% if initial_tool == 1 or both_toolheads %}
M109 S{extruder_temp_1|default(printer.extruder1.target, true)} T1
{% endif %}
{% endif %}

# rmmu load initial tool
{% if printer["rmmu_hub"] is defined %}
{% if physical_t0_used and printer["rmmu RMMU_T0"] is defined and printer["rmmu RMMU_T0"].loaded_filament|int != printer["rmmu RMMU_T0"].initial_filament|int %}
RATOS_ECHO MSG="1"
{% if initial_tool == 1 %}
RATOS_ECHO MSG="2"
SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY
{% endif %}
RATOS_ECHO MSG="3"
M118 FILAMENT {printer["rmmu RMMU_T0"].initial_filament|int}
_MOVE_TO_LOADING_POSITION TOOLHEAD=0
RMMU_LOAD_FILAMENT FILAMENT={printer["rmmu RMMU_T0"].initial_filament|int}
{% if printer["dual_carriage"] is defined %}
RATOS_ECHO MSG="4"
PARK_TOOLHEAD
{% endif %}
{% if initial_tool == 1 %}
RATOS_ECHO MSG="5"
SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY
ACTIVATE_EXTRUDER EXTRUDER=extruder1
{% endif %}
{% endif %}
{% if physical_t1_used and printer["rmmu RMMU_T1"] is defined and printer["rmmu RMMU_T1"].loaded_filament|int != printer["rmmu RMMU_T1"].initial_filament|int %}
RATOS_ECHO MSG="6"
{% if initial_tool == 0 %}
RATOS_ECHO MSG="7"
SET_DUAL_CARRIAGE CARRIAGE=1 MODE=PRIMARY
{% endif %}
RATOS_ECHO MSG="8"
M118 FILAMENT {printer["rmmu RMMU_T1"].initial_filament|int}
_MOVE_TO_LOADING_POSITION TOOLHEAD=1
RMMU_LOAD_FILAMENT FILAMENT={printer["rmmu RMMU_T1"].initial_filament|int}
{% if printer["dual_carriage"] is defined %}
RATOS_ECHO MSG="9"
PARK_TOOLHEAD
{% endif %}
{% if initial_tool == 0 %}
RATOS_ECHO MSG="10"
SET_DUAL_CARRIAGE CARRIAGE=0 MODE=PRIMARY
ACTIVATE_EXTRUDER EXTRUDER=extruder
{% endif %}
{% endif %}
{% endif %}
Expand Down Expand Up @@ -747,15 +736,20 @@ gcode:
# config
{% set min_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float %}
{% set max_temp = printer["gcode_macro RatOS"].preheat_extruder_temp|float + 5 %}
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}

# preheat extruder
{% if printer["gcode_macro RatOS"].preheat_extruder|lower == 'true' %}
RATOS_ECHO MSG="Pre-heating extruder..."
# Wait for extruder to reach a predefined preheat temp so an inductive probe (if present) is at a predictable temp.
# Also allows the bed heat to spread a little, and softens any plastic that might be stuck to the nozzle.
M104 S{min_temp} T{default_toolhead}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp}
{% if printer["dual_carriage"] is defined %}
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}
M104 S{min_temp} T{default_toolhead}
TEMPERATURE_WAIT SENSOR=extruder1 MINIMUM={min_temp} MAXIMUM={max_temp}
{% else %}
M104 S{min_temp}
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={min_temp} MAXIMUM={max_temp}
{% endif %}
{% endif %}

[gcode_macro _START_PRINT_AFTER_HEATING_EXTRUDER]
Expand Down

0 comments on commit 7441aac

Please sign in to comment.