Macro to calculate remaining filament on a spool
-
I did this macro to help calculate the remaining filament on a spool.
As it uses arrays, it will not work on earlier versions of RRF
As long as you retain the format, you can change the array contents to suit what you use.
If you only use one type, diameter etc, then use a single element array.I must admit when I started, I did not realise that Superslicer and Prusa slicer have the ability to give you what the spool should weigh (including the spool itself) if you set it up with all the details in your filament profiles.
You can optionally save the result as a global variable which could be used to check if there's enough filament at the start of the print, and could be updated at the end of the print by deducting the extruder position.
Anyway, for what it's worth
;calculate_remaining_filament.g ; Calculate filament length on spool var resultAsGlobal=false ; set to true f you want the result saved as a global variable called global.remainingFilament ; Set filaments to be included to true ; Array format = {"FilamentName",Density g/cm3 (nn.nn),Include(true/false)} ; no more than 250 characters allowed on line var FilamentDensities = {{"ABS",1.04,true,},{"ASA",1.07,false,},{"eFlex",1.12,true,},{"eLastic",1.14,true,},{"PA-CF",1.40,true,},{"PEEK",1.26,false,},{"PETG",1.27,true,},{"PLA",1.24,true,},{"TPU",1.21,true,},} ;create array with default empty spool weights var emptySpoolWeights={{"eSun Black",224},{"eSun Clear",248},{"Auraurum",250},{"Prusament",205},{"3D Fillies",250},} ; must be an array. Even if only one value, last value must be followed by a comma ; create an array for all filament diameters used var FilamentDiameters = {1.75,} ; must be an array. Even if only one value, last value must be followed by a comma ;var FilamentDiameters = {1.75,2.85} ; must be an array. Even if only one value, last value must be followed by a comma ;create an array with new spool weights (filament only) var newSpools = {1.0,} ; must be an array. Even if only one value, last value must be followed by a comma ; var newSpools = {0.25,0.3,0.5,1.0,2.0,5.0,} ; must be an array. Even if only one value, last value must be followed by a comma ; ############## Don't modify below here ################### var includedCount = 0 ; leave at zero ; Create an array with just our list of included filaments while iterations < #var.FilamentDensities if var.FilamentDensities[iterations][2] == true set var.includedCount = var.includedCount + 1 var displayList = vector(var.includedCount,null) var displayedData = vector(var.includedCount,{null,null,null}) var recordNum = 0 while iterations < #var.FilamentDensities if var.FilamentDensities[iterations][2] == true set var.displayList[var.recordNum] = var.FilamentDensities[iterations][0] set var.displayedData[var.recordNum] = var.FilamentDensities[iterations] set var.recordNum = var.recordNum + 1 ; display out choice list M291 S4 K{var.displayList} P"Choose Filament type" var ChosenType = input ; create an array of strings of the filament diameters for use by M291 var thisList = vector(#var.FilamentDiameters,null) while iterations < #var.FilamentDiameters set var.thisList[iterations] = var.FilamentDiameters[iterations] ^ "" var diameter = 0 ; If there's more than one diameter we'll display a choice if #var.thisList > 1 M291 S4 K{var.thisList} P"Choose diameter" F0 set var.diameter = var.FilamentDiameters[input] else set var.diameter = var.FilamentDiameters[0] ; check if it's a new spool or partial one var weight = 0 var isNewSpool = true M291 S4 K{"New spool", "Part spool",} P"Select amount left on spool" if input = 1 M291 S6 L250 H5500 P"Enter total spool + filament weight (grams)" F1000 set var.weight = input set var.isNewSpool = false else var spools = vector(#var.newSpools,null) while iterations < #var.newSpools set var.spools[iterations] = var.newSpools[iterations] ^ "" ; if we have more than one new spool weight, we'll show a choice if #var.newSpools > 1 M291 S4 K{var.spools} P"Select new filament weight (excluding spool) in KG's" set var.weight = var.newSpools[input]*1000 ; convert to grams else set var.weight = var.newSpools[0]*1000 ; convert to grams ;if there's more than one empty spool weight we'll dislay a choice set var.thisList = vector(#var.emptySpoolWeights,null) while iterations < #var.emptySpoolWeights set var.thisList[iterations] = var.emptySpoolWeights[iterations][0]] var spoolWeight= 0 if (#var.thisList > 1) && (var.isNewSpool=false) M291 S4 K{var.thisList} F0 P"Choose empty spool type" set var.spoolWeight = var.emptySpoolWeights[input][1]] else set var.spoolWeight = var.emptySpoolWeights[0][1]] var remaining = 0 if var.isNewSpool = true set var.remaining = var.weight else set var.remaining = var.weight - var.spoolWeight var ccLeft = var.remaining / var.displayedData[var.ChosenType][1] var CCperMM = (3.1416 * pow(var.diameter/2,2)/1000) var FilamentLeft = var.ccLeft / var.CCperMM M291 S2 P{"Remaining filament is aprox " ^ floor(var.FilamentLeft) ^ " mm (" ^ var.FilamentLeft/1000 ^ " meters)"} ; chck if we are to create a global variable if var.resultAsGlobal M291 S4 P"Create/update global variable?" K{"No","Yes"} R"global.remainingFilament" F1 if input = 1 if !exists(global.remainingFilament) global remainingFilament = floor(var.FilamentLeft) else set global.remainingFilament = floor(var.FilamentLeft) else echo "Global variable not set"
-
@OwenD Does it calculate when I have to change the spool, if there's not enough filament remaining?
So I can set my alarm clock instead of sleeping next to the printer -
@o_lampe You could always weigh the spool and know that there's enough filament before you start the print. I do that and sleep like a baby.
-
@mrehorstdmd That's true for prints that use less than 1kg or 5kg (depends on the spool). For big several_days_printjobs, if you want to keep energy cost low, you won't like to pause the printer over night but keep the bed heated all the time just because it ran out of filament.
I know, that rarely happens. Not everyone prints new car-bumpers or customized cargo boxes for e-bikes.
It's just for peace of mind, to know when you have to replace the spool. -
@o_lampe said in Macro to calculate remaining filament on a spool:
@OwenD Does it calculate when I have to change the spool, if there's not enough filament remaining?
So I can set my alarm clock instead of sleeping next to the printerI wasn't sure if your question was "tongue in cheek"
It probably wouldn't be hard to post process the job to see where the filament usage would be around the remaining on the spool.
But working out the time that would happen would probably require running the job in simulation mode.
I think it's doable, but a large job can take quite a while to simulate.
On my printer the filament spool is about 400mm from the extruder.
On that sort of system I think you could use home integration or maybe MQTT to alert you in plenty of time to get up and be ready to change rolls? -
@OwenD said in Macro to calculate remaining filament on a spool:
I wasn't sure if your question was "tongue in cheek"
It halfway was. I expected someone say: you can use two rolls and a dual extruder
I personally try to keep my printers low_tech. No acceleration sensor, no filament sensor and no load cell weighting the spool.
But for people who try to maximize tech-stuff, the question was valid.
IDK if slicers would be a better place to estimate spool-change time? But simulating a file is a good option too.
If I'd own a printer doing several days jobs, there would be a redundant Duet board around which can simulate the next file on the todo list. -
@o_lampe
Something like this (needs refinement) would give you the answers you seek; CalculateFilamentRunoutTime.g ; Calculate thn aproximate time filament will run out M291 S6 P"Enter weight of filament (excluding spool) in grams" F10 H1000 L1 var spoolWeight = input M291 S6 P"Enter filament density" F1.04 H2 L0.8 var filamentDensity = input M291 S7 P"Enter filename to simulate" F"cube.gcode" var fullName = directories.gCodes ^ input var filamentUsed = 0 var filamentRunout = false echo var.fullName var startTime = state.time var durationInSecs = 0 if !fileexists(var.fullName) abort "File not found : " ^ var.fullName else echo "Simulating " ^ var.fullName M37 P{var.fullName} S2 F1 while state.status ="simulating" set var.filamentUsed = move.extruders[0].position * (3.1416 * pow(1.75/2,2)/1000) * var.filamentDensity if var.filamentUsed > var.spoolWeight set var.durationInSecs = job.duration echo "Filament exceeded at aprox " ^ {floor(var.durationInSecs /60)} ^ " minutes after start" G4 S1 M25 set var.filamentRunout = true echo "If started now, print would run out of filament at aprox " ^ state.time + var.durationInSecs G4 S2 while state.status="pausing" G4 S1 M0 M37 S0 G4 P500 if var.filamentRunout = false echo "Simulation finished without filament runout"
-
@OwenD WOW , you absolutely nailed it. This macro can run on any old Duet2 powered by USB cable. The spool changing times are relative but universal for nn follow up prints
-
This reminds me of a video I did a couple of years ago where I described basically how you can get a pretty close estimate of how much filament is on a reel using nothing more than a ruler (and a spread sheet which I uploaded to my google drive for anyone to use). I still use this method and the results are pretty dam close.
Like most of my videos, it's had a whopping 600 or so views (I really don't know why I bother) but here is a link if anyone wants a quick and simple way to tell how much filament is on any randomly selected reel using nothing more than a ruler https://www.youtube.com/watch?v=1QIZ67XyJBE&t=73s
-
@deckingman
Definitely a valid method.
Did you calculate the center line of the helix?
YouTube views are more based on the "entertainment" value of the content than on the usefulness of the content.
I have a bunch of tutorials on some software I wrote which are as boring as bat shit even to people that are interested@o_lampe
I have an idea for an extension to actually notify you at the correct time.
I call it T-Frag
(testicular filament runout alarm generator)
All it requires is a large capacitor, some alligator clips and a relay.
I'm looking for beta testers! -
@OwenD said in Macro to calculate remaining filament on a spool:
@deckingman
Definitely a valid method.
Did you calculate the center line of the helix? ...........Yes, I use the centre line if the filament thread to calculate the circumference. I also make allowance for the fact that, after the first layer on a reel, subsequent layers sit between the " valley" of the underlying layer, rather than on the topmost peak of the previous filament thread. I'm not claiming that this method is the ultimate in accuracy, but it's close enough to answer the question "is there enough filament left on this reel to print what I want". The biggest cause of inaccuracy is after a reel has been used, the uppermost layer or two won't be as tightly wound as the underlying layers so I just take 2 or 3 metres off the calculated result. Now that I know the dimensions of all my filament reels, I only have to take one measurement to tell how much filament is left.
-
@deckingman I think there is no need to use filament length and diameter. Prusa Slicer tells us how much the part will weight.
Just calculate the volume of the filament on the spool ( hollow cylinder: outer diameter, inner diameter, spool-width).
Multiplying that by the right fill-grade factor and density would give you the real weight left on the spool. -
@OwenD said in Macro to calculate remaining filament on a spool:
(testicular filament runout alarm generator)
All it requires is a large capacitorI have a sound sleep, it would take a car battery to wake me up
-
@o_lampe said in Macro to calculate remaining filament on a spool:
@deckingman I think there is no need to use filament length and diameter. Prusa Slicer tells us how much the part will weight.
Just calculate the volume of the filament on the spool ( hollow cylinder: outer diameter, inner diameter, spool-width).
Multiplying that by the right fill-grade factor and density would give you the real weight left on the spool.That's another way of doing it but calculating the "fill grade factor" could be tricky. Also, you'd need to know the weight of an empty reel which is also tricky if you don't happen to have any scales to weigh one. You'd also need to look up the density of the filament. Rulers I have, scales I don't, which is why I wanted to use another method.
-
@deckingman said in Macro to calculate remaining filament on a spool:
Also, you'd need to know the weight of an empty reel which is also tricky if you don't happen to have any scales to weigh one.
If you don't have an empty spool then you could weigh the full spool when you open it and subtract the declared weight of filament.
-
@dc42 said in Macro to calculate remaining filament on a spool:
@deckingman said in Macro to calculate remaining filament on a spool:
Also, you'd need to know the weight of an empty reel which is also tricky if you don't happen to have any scales to weigh one.
If you don't have an empty spool then you could weigh the full spool when you open it and subtract the declared weight of filament.
As above - rulers (and empty spools) I have - scales I do not currently have.
-
@deckingman The $8 Amazon Basics kitchen scale I ordered years ago has been one of the more useful tools I've gotten.
-
@Phaedrux That's fascinating information I'm sure.
I'm starting to doubt my sanity but I'm pretty sure it's the rest of the world that's crazy.
I put out a post detailing a method I use to determine how much filament is left on a reel using nothing but a ruler. I state that this method works reliably and well for me. I post a link to a YouTube video I made which in turn links to spreadsheet that contains the necessary calculations for anyone who might be interested.
Ignoring all that, someone suggests that I should weigh the filament.
Then, still ignoring the fact that I have a relaliable method using a ruler, someone else suggests how I could determine the weight of an empty reel using scales.
Now, still ignoring the fact that I use a ruler, I have a suggestion as to where I could buy some suitable scales in order to make a measurement that I don't need.
-
@deckingman Just sharing Ian. No need to take it personally.
-
@dc42 said in Macro to calculate remaining filament on a spool:
@deckingman said in Macro to calculate remaining filament on a spool:
Also, you'd need to know the weight of an empty reel which is also tricky if you don't happen to have any scales to weigh one.
If you don't have an empty spool then you could weigh the full spool when you open it and subtract the declared weight of filament.
That's also a good way to figure out a value for (fill-rate + density). The initial filament volume on the spool is the starting point.
We don't need to know the real density or the real fill-rate, only the sum of it.
From there it's relative.