Skip to content

Commit

Permalink
minor tweaks to encoder measurement feedback for better UI experience
Browse files Browse the repository at this point in the history
  • Loading branch information
moggieuk committed Feb 2, 2025
1 parent 11da72f commit f888be2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions extras/mmu/mmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ def get_status(self, eventtime):
'is_locked': self.is_mmu_paused(), # Alias for is_paused (deprecated)
'is_homed': self.selector.is_homed,
'is_in_print': self.is_in_print(),
'unit': self.unit_selected,
'tool': self.tool_selected,
'gate': self._next_gate if self._next_gate is not None else self.gate_selected,
'active_filament': self.active_filament,
Expand Down Expand Up @@ -1373,15 +1374,16 @@ def get_status(self, eventtime):
'sync_feedback_state': self._get_sync_feedback_string(),
'sync_feedback_enabled': bool(self.sync_feedback_enable),
'print_state': self.print_state,
'clog_detection': self.enable_clog_detection, # TODO: Rename clog_detection_enabled
'endless_spool': self.enable_endless_spool, # TODO: Rename endless_spool_enabled
'clog_detection': self.enable_clog_detection, # DEPRECATED use clog_detection_enabled
'clog_detection_enabled': self.enable_clog_detection,
'endless_spool': self.enable_endless_spool, # DEPRECATED use endless_spool_enabled
'endless_spool_enabled': self.enable_endless_spool,
'print_start_detection': self.print_start_detection, # For Klippain. Not really sure it is necessary
'reason_for_pause': self.reason_for_pause if self.is_mmu_paused() else "",
'extruder_filament_remaining': self.filament_remaining + self.toolhead_residual_filament,
'spoolman_support': self.spoolman_support,
'enable_spoolman': int(not self.spoolman_support == self.SPOOLMAN_OFF), # Legacy
'selector_type': self.mmu_machine.selector_type,
'bowden_progress': self._get_bowden_progress(),
'bowden_progress': self._get_bowden_progress(), # Simple 0-100%. -1 if not performing bowden move
'espooler_active': 'rewind' if self.espooler_active else '' # 'assist' not supported yet
}
status.update(self.selector.get_status())
Expand Down Expand Up @@ -2029,7 +2031,7 @@ def _get_encoder_summary(self, detail=False): # TODO move to mmu_sensor_manager?
msg += "\n- Runout detection: %s" % ("Enabled" if status['enabled'] else "Disabled")
clog = "Automatic" if status['detection_mode'] == 2 else "On" if status['detection_mode'] == 1 else "Off"
msg += "\n- Clog/Runout mode: %s (Detection length: %.1f)" % (clog, status['detection_length'])
msg += "\n- Trigger headroom: %.1f (Minimum observed: %.1f)" % (status['headroom'], status['min_headroom'])
msg += "\n- Remaining headroom before trigger: %.1f (min: %.1f)" % (status['headroom'], status['min_headroom'])
msg += "\n- Flowrate: %d %%" % status['flow_rate']
return msg

Expand Down Expand Up @@ -3110,7 +3112,8 @@ def _continue_after(self, operation, force_in_print=False, restore=True):
self._ensure_safe_extruder_temperature("pause", wait=True)
self.paused_extruder_temp = None
self._track_pause_end()
self._enable_runout() # Enable runout/clog detection while printing
if self.is_printing(force_in_print):
self._enable_runout() # Enable runout/clog detection while printing
self._set_print_state(self.resume_to_state)
self.resume_to_state = "ready"
self.printer.send_event("mmu:mmu_resumed")
Expand Down Expand Up @@ -3235,6 +3238,7 @@ def _clear_saved_toolhead_position(self):
def _disable_runout(self):
enabled = self.runout_enabled
if enabled:
logging.info("PAUL: Disabled runout detection")
self.log_trace("Disabled runout detection")
if self.has_encoder() and self.encoder_sensor.is_enabled():
self.encoder_sensor.disable()
Expand All @@ -3244,6 +3248,7 @@ def _disable_runout(self):

def _enable_runout(self):
self.runout_enabled = True
logging.info("PAUL: Enabled runout detection")
self.log_trace("Enabled runout detection")
if self.has_encoder() and not self.encoder_sensor.is_enabled():
self.encoder_sensor.enable()
Expand Down
4 changes: 2 additions & 2 deletions extras/mmu_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def _handle_connect(self):
self.extruder = self.printer.lookup_object(self.extruder_name)
except Exception:
pass # Can set this later
self.last_extruder_pos = 0.
self.filament_runout_pos = self.min_headroom = self.detection_length

def _handle_ready(self):
Expand Down Expand Up @@ -249,7 +250,6 @@ def enable(self):
self._enabled = True

def disable(self):
self.last_extruder_pos = self.filament_runout_pos = 0.
self._enabled = False

def is_enabled(self):
Expand Down Expand Up @@ -300,7 +300,7 @@ def get_status(self, eventtime):
'encoder_pos': round(self.get_distance(), 1),
'detection_length': round(self.detection_length, 1),
'min_headroom': round(self.min_headroom, 1),
'headroom': round(self.filament_runout_pos - self.last_extruder_pos, 1),
'headroom': round(min(self.filament_runout_pos - self.last_extruder_pos, self.detection_length),1),
'desired_headroom': round(self.desired_headroom, 1),
'detection_mode': self.detection_mode,
'enabled': self._enabled,
Expand Down

0 comments on commit f888be2

Please sign in to comment.