ENH: write cumulative per-layer filament usage into slice_info.config - #12147
Open
jobshimo wants to merge 1 commit into
Open
ENH: write cumulative per-layer filament usage into slice_info.config#12147jobshimo wants to merge 1 commit into
jobshimo wants to merge 1 commit into
Conversation
slice_info.config carries each filament's plate total (used_g) and the printer reports layer_num while it prints, so estimating how much filament an interrupted print used means scaling the total linearly by layers. That is wrong by up to a third of the plate on parts with solid bottom layers and sparse infill (bambulab#12145). Record every filament's cumulative extruded volume at each layer change and once at the end, convert it to grams the way used_g is, and write it as <filament_layer_usage id="N" unit="g" values="..."/> after the <filament> elements. Entry 0 is what was extruded before the first layer, the last entry equals used_g, and layer_num indexes the list directly. The importer reads the element back so it survives a round trip.
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.
Implements #12145.
slice_info.configcarries each filament's plate total (used_g), and the printer reportslayer_numwhile it prints, so anyone estimating how much filament an interrupted print used has to scale the total linearly by layers. On real plates that is wrong by a wide margin, because the bottom layers are solid and the infill layers are light: measured on seven A1 plates in the issue, the linear estimate is off by up to 36 % of the plate on a 293-layer part and 70 % on a 26-layer one.This writes, per filament, the cumulative usage at the end of each layer:
Entry 0 is what was extruded before the first layer (purge line, priming); the last entry equals
used_g;layer_numfrom the printer indexes the list directly. The values are an attribute rather than text content so the element is read and written like every other element in the file.Changes
GCodeProcessor:UsedFilaments::record_layercommits the active filament's cache and snapshots every filament's cumulative total. It runs at each; CHANGE_LAYERtag, beforem_layer_idis bumped, and once infinalizeafterprocess_caches, so the series has total layer number + 1 entries. A filament first used later in the print is padded with zeros for the layers before it. The series travels inPrintEstimatedStatistics::layer_volumes_per_extrudernext tototal_volumes_per_extruder.PlateData::parse_filament_infoconverts the volumes to grams with the same density and diameter it uses forused_g, intoFilamentInfo::layer_used_g._add_slice_info_config_file_to_archivewrites the element after the<filament>elements;_handle_start_config_filament_layer_usagereads it back when a sliced project is opened.Size: about six bytes per layer per filament; a 1000-layer, four-filament plate adds roughly 25 KB to
slice_info.config.used_g,used_mand every existing element are unchanged, and a reader that does not know the new element is unaffected.Verification
Built on Ubuntu 22.04 with
BuildLinux.sh -son top of thedocker/BuildDepsDockerfileimage, then sliced a test part from the CLI with the A1 0.4 mm nozzle system presets (0.20 mm Standard, Generic PETG, textured PEI plate): a 60 × 60 × 3 mm base with a 12 × 12 × 30 mm pillar, 165 layers.slice_info.configgets<filament_layer_usage id="1" unit="g" values="0.09,0.96,1.83,2.70,...,10.85"/>: 166 entries for 165 layers, last entry equal toused_g(10.85).Emoves of the exportedplate_1.gcodebetween; CHANGE_LAYERmarkers and converting with the header's density and diameter reproduces the series to within 0.05 g at every entry. That residue is constant along the series and is the same difference that sum shows againstused_gitself.Not covered here: multi-filament plates (the zero padding for a filament first used after the first layers is written but was not exercised), and the importer side.
_handle_start_config_filament_layer_usagemirrors_handle_start_config_filament, but a CLI--export-3mfwithout slicing drops the sliced plate data, so there is no command-line round trip to observe it with.