-
-
Notifications
You must be signed in to change notification settings - Fork 420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filament manager #123
Filament manager #123
Conversation
Endpoints examples: List all spoolsGET http://octopi.local:7125/filament/spool/list List materialsGET http://octopi.local:7125/filament/materials Add SpoolPOST http://octopi.local:7125/filament/spool { Update SpoolPOST http://octopi.local:7125/filament/spool { Get spool detailsGET http://octopi.local:7125/filament/spool?id=000003 Delete spoolDELETE http://octopi.local:7125/filament/spool?id=00000E Get spool set as activeGET http://octopi.local:7125/filament/active_spool Set active spoolPOST http://octopi.local:7125/filament/active_spool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
I don't have enough time to put all my thoughts out at this moment. By here are a few thoughts: What about filament expended between jobs? It doesn't seem like this is tracking that and ideally a filament manager will track all actions, not just during a job. It would be ideal to have a field for starting_weight or something where we could track the weight of the filament+spool so if I weigh it later I know exactly how much is left of filament. I think having the ability to mark a spool as spent rather than having to delete it would also be nice. So you can track overall filament usage. When I have time to do a better review I'm make some more comments. |
@jordanruthe Not sure what you mean. Do you mean like manual filament extrude? Hmm not sure how to track that? If so these are rather small consumption, within the measurement error.
I can add spool weight field.
Delete option is rather for different purpose, just to delete spool.
Thanks |
I like the idea with spool weight. In my opinion we should not account for every possible input weight configuration. Because it gets complicated if you want to manually update the weight, because you removed some filament or just entered the wrong values at the beginning. Take a look at the Octoprint Spool Manager, in my Opinion it is overkill how many input options there are. Some are calculated based on others, but still can be set manually. At also it isn't working as expected. I think a spool creation should consist of selecting a Filament from a Database nothing more ideally. But if the filament is not in a database, i should be not more than Total Weight + Assumed Filament on Spool. Because that are the two things I can measure/know. Yes refill is a thing, where you could weight the filament on it's own, but you could also weight the spool before and after the refill is put on. But that's what I mean with it gets complicated with many input options. |
You could create and endpoint to get only spools with more than x meters left. So you don't have to load all spools into the front-end to filter than for spool which can be activated. But it is still possible to list all spools if desired. |
That might be good idea, actually when filament usage exceeds filament total weight, then it can be auto marked as active=false, and will add parameter |
metadata = {'spool_id': spool_id, | ||
'used_weight': used_weight, | ||
'cost': used_cost} | ||
history.add_job_metadata(job_id, {'filament': metadata}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the history module isn't configured this call will raise an exception. Generally speaking I don't think that the spool manager should rely on the history module. If we need to add some spool data to job history we can do that, however it would probably be better for the history module to look up this module and request the current spool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe spool_manager can publish event which can be consumed by history component? but anyway spool_manager depends on history component currently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can check if history == None and remove the metadata storage if the component isn't found.
A spool change notification would be good either way as it would notify front ends that they should update the active spool info (which I'm assuming will be shown).
I believe we should also allow for the case of multiple spools used during one print as changing colors/filaments mid-print seems to be a common thing (especially with the pause at layer feature in slicers). Which means you'd need to make a spools list in metadata rather than a spool dict. Spools would also have to be attached to jobs mid-print.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in an ideal scenario the history
module will look up spool_manager
and add a reference to the spool if it has been configured. The spool_manager
can emit a "spool_changed" event that that history
can register. When a spool change is noted then history
can add the current spool's reference to the ongoing job.
job_data = data['job'] | ||
job_id = job_data['job_id'] | ||
filament_used = job_data['filament_used'] | ||
self.filament_manager.track_filament_usage(job_id, filament_used) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think rather than tracking a job's filament usage it would be more accurate to track the toolhead`s E position. We may need to register a remote method that allows Klipper macros to toggle spool tracking off/on during a spool change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree on the tracking the E position. Tracking the E position would also allow for outside of job spool tracking. I realize you previously have said that outside of job lengths should be lost in the noise or error, but if I expend 1m of filament doing some calibration/testing, that could be the difference between me being able to use the last of the spool or not, depending on a job size.
Agreed for the macros on the spool change.
I left a few comments after an initial review. I'd like to get Jordan's feedback and make some decisions on what direction we want this to go before proceeding with a more detailed review. I think feedback from other client developers would be useful as well. Some things I would like to hammer out:
When working locally my commits look a lot like yours. However it is a good idea to squash them and create proper commit messages (as outlined in contributing.md) in a pull request, as it makes reviewing the code easier. Changes to any other modules (such as |
62963c7
to
f125fa8
Compare
Component to manage spools and track filament usage. Signed-off-by: Mateusz Brzezinski [email protected]
f125fa8
to
f837e10
Compare
df75dbf
to
bd2b5e6
Compare
yes, that makes sense, fixed that
fixed that
not sure if that is good idea, what if you want to add new spool to db, but is already used a bit, or sometimes partial spools are available for purchase, so I rather would not do that on configuration level. We can make the default value for total_weight to 1000g, diameter to 1.75, and let user to use that default values or edit that, that should be enough.
that is to consideration, but you would rather not add 1000000 spools, rather like 20-100
Definitely would squash commits on merging PR to master, but also squashed existing commits For now I left changes to history module here, until we sort everything, otherwise that PR at least for now would be withiout context Happy to get some comments from @jordanruthe |
I was thinking that specific manufacturers may produce materials with slightly different properties. For example, maybe Prusa PLA has a different density than ESun PLA. This information is static and could be templated through a config file. That said, I'm okay with just providing generic templates and allowing the user to add custom values.
I'm thinking that we max out on 1000 spool entries. I pushed a recent commit that sets a 10000 job limit for the |
Could you elaborate a bit more, how would you want to implement that?
That is a neat idea, in case of spools will be a bit more complex, as I guess we should pop off the oldest (last_used) inactive spool. But anyway that won't be a problem. EDIT: eventually I took different approach, as spools are managed by user, so just in case limit is reached, endpoint will return error, so user has to delete spool by himself. |
3e87724
to
405559d
Compare
Thank you so much for developing this! If there is any possibility to, please add the option to use the filament database across several klipper instances in a local network. |
that will be rather much more complicated, and I guess rather in another release, as currently Moonraker has only local db |
Regarding the database for default values for spools. I thought more about a public github repo with all sort of default data to choose from. Everybody can do a PR with new Spool Values, Filamenttypes, Densitys, Netto/Brutto Weight of the spools etc. Maybe you could add your own private Repo via the Config file. This could solve the MultiPrinter MultiClient issue and generate a big database (outside of Moonraker) which could even evolve into a bigger filament database as than just the data used by moonraker. |
Moonraker isn't aware of other instances on the network. Clients could possibly sync spools across instances, however this can get complex as they must deal with new instances added, some instances not having the spool manager configured, some instances not reachable.
Interesting idea, however I'm weary of having Moonraker rely on remote service. Some users have connection issues, it has already caused headaches with the update manager. In my view it would be better for clients to query such a service directly, they could then add these templates to the local instance when a user selects them. With regard the current state of the module, I have a few comments:
|
I'm playing around with an RDM6300 RFID reader and tags with the intention to track which spool is inserted. My use cases are:
I think all that should be possible once this PR is merged, however, a few things I noticed:
|
Hi everyone, any update on this ?? Is a very nice feature to have available for the klipper ecosystem |
Unfortunatly still not merged to moonraker, not know where is problem ;(( |
It would be very nice to see this happen. What are the merge conflicts ? |
I too am interested in this project, would love to contribute. Have emailed @mateuszbrzezinski but no response, know very little python but am learning for this very project. I have a hx711 filament weight scale and RFID as @Drachenkaetzchen mentioned, managed through home assistant and would like very much to see this usable in Klipper. @feniarus any updates? Thx all... |
This feature is the main reason I cannot switch from Octoprint. I have three printers and I need to coordinate the filament use between them. |
Since this seems like its been abandoned, I'm making an attempt at solving the last set of comments from @Arksine and creating a new PR. @Arksine I'm somewhat learning python and how the framework functions as I do this so a push in the right direction would help. I'm trying to remove the dependency on history and plan on setting up a similar number of event handlers. From examples in other components, it appears to me like once I subscribe to the tool head, I'll need to check "server:status_update" events for the epos updates? Am I guaranteed to get an event every time the epos changes or could I miss some steps if a retraction happens? Tracking the epos should also track usage outside of prints (right?) and my current plan is to update the usage every time a request is sent to get spool info, every time a job event happens and using an on_exit(). Are job events good to use like this or should I track printing status manually? Thanks! |
@jmccaull Could you build it in a way so that external databases can be used. If you have multiple printers it is important to share the same DB between them. |
@DerKnerd the "database" component used here is based on LMDB and from what I can gather only does local connections. It probably makes sense to get the use case working first for local, then figure out how to architect a distributed set up. There are a lot of problems to solve for when trying to set something like that up, maybe it make sense to set up some sort of filament server and have moonraker and front ends talk to that instead of directly to each other? |
@jmccaull I like the idea with a filament server. That would add more flexibility when you want to run multiple instances. I think the feature to run against an external database could be critical for many users. |
@Arksine , would you know a good macro for moonraker shutdown?? eg gcode: something simple for the slicer to run in G code at end print command |
I also like the idea of a server, possibly even a public one with user spool collections (in my use case would be to track empty spool weights for scale tare, could get an average brand weight report from anonymous data sharing)... few years down the road who knows? got 200 grams of glow in the dark left over, anyone have a similar weight of blue to trade? etc... also @jmccaull I know very little of python but if u would like any testing r/e weight scale or rfid tagging I'd be glad to help! pretty handy with YAML and esp32 also... |
Building something that can connect to https://www.3dprintlog.com/ might be an option. The Cura plugin can’t capture actual usage, and there’s nothing (yet)for Klipper. |
Integrating with some sort of service sounds cool, but I was more meaning something you would run locally, probably on one of the machines already running moonraker. The point is that functionality and the interaction between different systems is beyond the scope of moonraker. You probably don't want all the other printers dependent on a single moonraker instance and you probably don't want them all dependent on something connected over the internet either. If anything the local filament server could reach out to some service over the internet and periodically sync data. |
if I may drop my few cents here... while making/connecting to some kind of a centered filament database [preferably self-hosted] is a cool idea and could be as easy as just adding MySQL/MariaDB credentials to db that would keep those records, I think that most important think is to get filament manager working on a single, local installation first ;) as not-a-programmer guy, who had a real pain moving from octoprint to klipper/moonraker because the whole semi-automatic filament manager was lost I am happy to see the discussion about the possibilities, but I am starting to be afraid that the main goal can be lost and I'll stuck with my google-sheets based filament control log ;) |
Between vacation and life, I've not had much time to work on this. Digging through the code I'm pretty sure I've found where the status updates contain the subscribed objects, I'm just not sure how often these updates happen. I'm also having some issues getting pycharm and the tests working locally. If anyone wants to take this up, feel free, otherwise I'll get to it eventually. Per the server and multi-printer functionality, the more I think about it the more I want to say they should be different components. They would share minimal functionality but the desired flow would probably be pretty different, ie you might need to "check out" spools before using them, then release them on change or shutdown, etc. |
created #597 as a draft so far |
Component to manage spools and track usage This is forked from Arksine#123 and attempting to address the outstanding comments Allows configuring templates to add spools: [spool_manager template pla] vendor: vendor material: PLA density: 1.24 diameter: 1.75 filament_weight: 1000 spool_weight: 200 cost: 24.99 This exposes 4 endpoints: "/spool_manager/spool and "/spool_manager/spool/list supporting GET, POST and DELETE, "/spool_manager/spool/active" supporting GET and POST, and "/spool_manager/templates" supporting GET. example curl for each operation: curl --location --request POST 'http://localhost:7125/spool_manager/spool' \ --header 'Content-Type: application/json' \ --data-raw '{"name": "templateTest", "template": "PLA"}' curl --location --request GET 'http://localhost:7125/spool_manager/spool?id=000001' curl --location --request DELETE 'http://localhost:7125/spool_manager/spool?id=000001' curl --location --request GET 'http://localhost:7125/spool_manager/spool/active' curl --location --request POST 'http://localhost:7125/spool_manager/spool/active' \ --header 'Content-Type: application/json' \ --data-raw '{"id": "000001"}' curl --location --request POST 'http://localhost:7125/spool_manager/spool/list' \ --header 'Content-Type: application/json' \ --data-raw '{"spools" : [{"name": "templateTest", "template": "PLA"}, {"name": "templateTest", "template": "PLA"}]}' curl --location --request GET 'http://localhost:7125/spool_manager/spool/list' curl --location --request DELETE 'http://localhost:7125/spool_manager/spool/list' \ --header 'Content-Type: application/json' \ --data-raw '{"ids": ["000003", "000005"]}' curl --location --request GET 'http://10.0.0.248:7125/spool_manager/templates' Signed-off-by: John Mccaulley [email protected]
Component to manage spools and track usage This is forked from Arksine#123 and attempting to address the outstanding comments Allows configuring templates to add spools: [spool_manager template pla] vendor: vendor material: PLA density: 1.24 diameter: 1.75 filament_weight: 1000 spool_weight: 200 cost: 24.99 This exposes 4 endpoints: "/spool_manager/spool and "/spool_manager/spool/list supporting GET, POST and DELETE, "/spool_manager/spool/active" supporting GET and POST, and "/spool_manager/templates" supporting GET. example curl for each operation: curl --location --request POST 'http://localhost:7125/spool_manager/spool' \ --header 'Content-Type: application/json' \ --data-raw '{"name": "templateTest", "template": "PLA"}' curl --location --request GET 'http://localhost:7125/spool_manager/spool?id=000001' curl --location --request DELETE 'http://localhost:7125/spool_manager/spool?id=000001' curl --location --request GET 'http://localhost:7125/spool_manager/spool/active' curl --location --request POST 'http://localhost:7125/spool_manager/spool/active' \ --header 'Content-Type: application/json' \ --data-raw '{"id": "000001"}' curl --location --request POST 'http://localhost:7125/spool_manager/spool/list' \ --header 'Content-Type: application/json' \ --data-raw '{"spools" : [{"name": "templateTest", "template": "PLA"}, {"name": "templateTest", "template": "PLA"}]}' curl --location --request GET 'http://localhost:7125/spool_manager/spool/list' curl --location --request DELETE 'http://localhost:7125/spool_manager/spool/list' \ --header 'Content-Type: application/json' \ --data-raw '{"ids": ["000003", "000005"]}' curl --location --request GET 'http://10.0.0.248:7125/spool_manager/templates' Signed-off-by: John Mccaulley [email protected]
Would there be a way to print QR codes for the spools and then scan them with the chamber camera feed to identify which roll you are loading quickly? I tested this with
Guess that works then you could poke this pr's spool code some how? Is it possible to add this pr in it's current state to test this out? Would like to then add a custom button to the mainsail webui where I could command it to run those processes while holding the spool to the cam feed then pull this code with the correct spool. As I’ve tested this below. sudo apt install zbar-tools
cd /home/pi/klipper/klippy/extras/
wget https://raw.githubusercontent.com/th33xitus/kiauh/master/resources/gcode_shell_command.py [gcode_shell_command qrcode_snapshot]
command: wget http://IP/webcam/?action=snapshot -O /home/pi/printer_data/gcodes/qrcode.jpg
verbose: True
timeout: 2.
[gcode_shell_command qrcode_scanner]
command: zbarimg /home/pi/printer_data/gcodes/qrcode.jpg
verbose: True
timeout: 2.
[gcode_macro QRCode_Scan]
gcode:
RUN_SHELL_COMMAND CMD=qrcode_snapshot
RUN_SHELL_COMMAND CMD=qrcode_scanner I tested regular barcodes on most spools with this code above and enabling all barcodes in the apps arguments but for whatever reason maybe my camera isn’t clear enough for the library. It just says it can’t detect any code. QR codes almost always work no matter the weirdness of what it’s having with what it sees. |
Sorry to bother, but wondering where this stands...the lack of spool/filament management is the biggest (practically only) gap for me after leaving Octoprint for Klipper/Mainsail/Moonraker. Does this still have any likelihood of being implemented? I get folks' personal lives take priority, so please don't take this as a "hurry up, you owe me something" post. :) |
Please try to make it first simple and add some features like qr code scan later? :) |
It would be nice if there was a way to just read the btt smart filament sensors encoder wheel to understand consumption. |
As mentioned in this PR: #597 (comment) , I'm working on a separate web service to act as a database. Would be nice to get some feedback on the direction of this and whether @Arksine believes this is a good approach. |
Moonraker now supports interaction with Spoolman which fulfills the same goals, so I believe this PR could be closed. https://moonraker.readthedocs.io/en/latest/configuration/#spoolman |
Thanks. |
module name: filament manager
Component to manage filaments and track filament usage.
Signed-off-by: Mateusz Brzezinski [email protected]