Skip to content

Prefer the matching AMS slot with the least remaining filament#11347

Open
ojimpo wants to merge 1 commit into
bambulab:masterfrom
ojimpo:feature/ams-prefer-emptier-slot
Open

Prefer the matching AMS slot with the least remaining filament#11347
ojimpo wants to merge 1 commit into
bambulab:masterfrom
ojimpo:feature/ams-prefer-emptier-slot

Conversation

@ojimpo

@ojimpo ojimpo commented Jun 29, 2026

Copy link
Copy Markdown

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 exact filament_id match. 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_id matches, prefer the tray with the smaller remain value, so partially-used spools are consumed first.

The printer already reports per-tray remaining percentage (DevAmsTray::remain, populated from MQTT in DeviceManager.cpp). This value is propagated into FilamentInfo via _parse_tray_info() and used in the tie-break.

Safety / backward compatibility:

  • The new rule only fires on an exact distance tie among same-filament_id trays. The scoring function and all existing mapping decisions are untouched.
  • It only applies when both candidate trays report a valid 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: add int remain{-1} to FilamentInfo.
  • src/slic3r/GUI/DeviceCore/DevMapping.cpp: copy tray.remain in _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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant