Prefer the matching AMS slot with the least remaining filament#11347
Open
ojimpo wants to merge 1 commit into
Open
Prefer the matching AMS slot with the least remaining filament#11347ojimpo wants to merge 1 commit into
ojimpo wants to merge 1 commit into
Conversation
When multiple AMS slots hold the same filament (same type + color), the auto-mapping picked the lowest-numbered slot, ignoring how much filament each spool had left. Add a secondary tie-break: on an exact distance tie among same-filament_id trays, prefer the tray with the smaller remain so partially-used spools are consumed first. Only applies when both trays report a valid remain (>= 0), i.e. genuine spools where the remaining amount is actually known; unknown remain (-1) keeps the previous lowest-slot-first behavior, so this is fully backward compatible. The scoring function and all other mapping decisions are untouched. Refs bambulab#992, bambulab#2075. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prefer the matching AMS slot with the least remaining filament
Problem
When two or more AMS slots are loaded with the same filament (same type + same color), Bambu Studio's auto-mapping always assigns the print to the lowest-numbered slot, regardless of how much filament each spool has left.
This is a long-standing annoyance for users who keep a partially-used spool and a fresh spool of the same filament in the AMS: the slicer maps to the full spool first, leaving the partial spool to linger forever. The only workarounds today are to manually remap on the send dialog every time (easy to miss, see #992) or to physically arrange spools so the emptier one sits in the lowest slot.
Refs #992, #2075.
Root cause
In
DevMappingUtil::ams_filament_mapping()(src/slic3r/GUI/DeviceCore/DevMapping.cpp), when several trays match a sliced filament with an identical color/type distance, the tie is broken only by exactfilament_idmatch. If that is still equal, the winner is simply whichever tray comes first in iteration order — i.e. the lowest slot index. Remaining amount is never considered.Fix
Add a secondary tie-break: when the color/type distance is equal and the
filament_idmatches, prefer the tray with the smallerremainvalue, so partially-used spools are consumed first.The printer already reports per-tray remaining percentage (
DevAmsTray::remain, populated from MQTT inDeviceManager.cpp). This value is propagated intoFilamentInfovia_parse_tray_info()and used in the tie-break.Safety / backward compatibility:
filament_idtrays. The scoring function and all existing mapping decisions are untouched.remain(>= 0). Spools that don't report a remaining amount (e.g. most non-genuine spools) keep the previous lowest-slot-first behavior. In practice this means the new behavior kicks in for genuine/RFID spools where the remaining amount is actually known — exactly the case where it is useful and correct.Changes
src/libslic3r/ProjectTask.hpp: addint remain{-1}toFilamentInfo.src/slic3r/GUI/DeviceCore/DevMapping.cpp: copytray.remainin_parse_tray_info(); add the remain-based tie-break in both mapping passes.Testing
Manual: load two slots with the same filament (one partial, one full) on an RFID-reporting AMS, slice a single-color model, and send. The mapping now targets the partial spool. With remain unavailable, mapping is unchanged.
Notes
This changes only the initial slot selection at send time. The mid-print auto-refill / backup failover order is firmware-controlled and out of scope.