Fix filament accounting with spoolman on mmu setups (happy hare, afc)
### Summary:
Rebase E high-water mark on active spool change to prevent spoolman undercount after tool changes
### Issue description:
The spoolman integration tracks filament usage using a global “high-water mark” of toolhead E position (_highest_epos). This works for single-material prints, but in MMU (filament swap) scenarios, the E position can be lower than the previous peak at the moment a new spool is activated. This happens due to retract/state-restore/unload sequencing and extruder moves split between macros (for unloading) and direct extruder control in the MMU control software python files.
As a result, the first portion of extrusion on the new spool (often ~tens of mm) only brings E back up to the old peak and is therefore not counted, leading to consistent undercounting on the newly activated spool (e.g. ~45mm missing after a 336mm purge).
### Data gathered:
By adding the below statement at the def set_active_spool(self, spool_id: Union[int, None]) function we can track whether there is any deviation between the high water mark e position (_highest_epos) and the last observed e position (_last_epos)
`logging.info(f"Spool change: new={spool_id}, last_epos={self._last_epos:.3f}, highest={self._highest_epos:.3f}")`

### Fix:
Track the latest observed E position (_last_epos) and rebase _highest_epos to the current E whenever the active spool changes. This ensures usage accounting for a new spool starts immediately from the activation point rather than being blocked by an old E peak.
### Implementation details
- Add self._last_epos to SpoolManager.
- Update _last_epos on every toolhead status update.
- Initialize _last_epos alongside _highest_epos in _handle_klippy_ready (so spool activation cannot rebase to 0 before the first status callback).
- In set_active_spool(), after updating self.spool_id, set: self._highest_epos = self._last_epos
合并状态:未合并 关闭于 2026-01-06 4 条评论