GithubHelp home page GithubHelp logo

pedrolamas / klipper-preprocessor Goto Github PK

View Code? Open in Web Editor NEW
133.0 8.0 12.0 148 KB

Klipper Preprocessor script for Cura

License: MIT License

Python 100.00%
cura klipper moonraker ultimaker-cura

klipper-preprocessor's Introduction

Klipper Preprocessor script for Cura

Project Maintenance License

Follow pedrolamas on Twitter Follow pedrolamas on Mastodon

Klipper Preprocessor is a Cura Post Processing Script to improve the output G-Code for Klipper usage.

Currently it allows the following improvements:

  • Add SET_PRINT_STATS_INFO so that Klipper can know what is the exact total layer count, and the current layer number in real-time.
  • Add TIMELAPSE_TAKE_FRAME so that Klipper together with moonraker-timelapse can take snapshots on each layer change to make timelapse videos.
  • Run preprocess_cancellation tool to add object cancellation data to the resulting G-Code, enabling Klipper to cancel any specific single object while printing.
  • Run klipper_estimator to add a more accurate time estimation to the resulting G-Code.

Klipper Preprocessor script for Cura

Initial setup

  1. Open Cura
  2. Open the "Help" menu and click "Show Configuration Folder"
  3. On the file list, open the "scripts" folder
  4. Download KlipperPreprocessor.py to the "scripts" folder
  5. Close the file list
  6. Close Cura
  7. (optional) Download preprocess_cancellation to a folder of your choice
  8. (optional) Download klipper_estimator to a folder of your choice
  9. Open Cura
  10. Open the "Extensions" menu, then "Post Processing", and click on "Modify G-Code"
  11. Click on "Add a script" and select "Klipper Preprocessor"
  12. Set options acording to your needs (hover any option to view the description)
  13. Click "Close" when ready

Recommended Cura settings for Klipper

Klipper documentation includes some generic slicer recommended settings that must be followed.

Below are some other settings that will improve your Cura slicing results while using Klipper.

Disable Jerk

Klipper does not support Jerk and instead relies on square_corner_velocity.

Is is recommended to untick the "Enable Jerk Control" option in the "Speed" section in Cura.

Adding extra metadata for Moonraker

Moonraker actively reads metadata from all sliced files, but there is some missing data in Cura sliced files.

To make sure you get all possible metadata on these files, add this to the top of your "Start G-code" in Cura, before any other instructions:

;Nozzle diameter = {machine_nozzle_size}
;Filament type = {material_type}
;Filament name = {material_name}
;Filament weight = {filament_weight}
; M190 S{material_bed_temperature_layer_0}
; M109 S{material_print_temperature_layer_0}

These lines are marked as comments, so they have no impact on the g-code, but Moonraker will still be able to find and use those values.

Improving Cura print time estimations

The default printer (machine) profiles in Cura have fixed values for max-acceleration and max-speed, so when we set values above those defaults while slicing a file, Cura will ignore when estimating the printing time and use the default ones instead, so the estimation will be off.

To fix this, follow these steps:

  1. Open Cura
  2. Click on the "Marketplace" button on the top right of the window
  3. On the Plugins list, select the "Printer Settings"
  4. Click "Install"
  5. Restart Cura
  6. On the "Print settings" flyout, there should now be a new section called "Printer Settings" (you might need to ensure they are visible by clicking the "hamburger" menu on the top right and selecting "All")
  7. Expand that section and change the "Maximum Speed..." and "Maximum Acceleration..." fields to match the values you are using in your Klipper configuration

FAQ

Why am I seeing "Unknown Command M205" while printing?

That will be because you have jerk enabled in Cura. You can safely disable jerk to fix it.

What is the "NOMESH" object that shows on my prints?

Cura 5.3.0 was released with a known bug that causes the identification of a "NOMESH" object.

This bug was fixed in Cura 5.3.1, so all you need to do is update to a more recent version.

I get some strange artifacts on the outer walls of my prints

Cura 5.3.0 was released with a known bug that causes some print quality issues.

This bug was fixed in Cura 5.4.0, so all you need to do is update to a more recent version.

Support my work

A lot of time and effort goes into the development of this and other open-source projects.

If you find this project valuable, please consider supporting my work by making a donation.

Donate on Paypal Buy me a coffee Support me on Patreon Sponsor me on GitHub

Thank you for your generosity and support! ๐Ÿ™

Credits and Acknowledgements

License

MIT

klipper-preprocessor's People

Contributors

gio3k avatar pedrolamas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

klipper-preprocessor's Issues

Timeout for preprocess_cancellation and klipper_estimator is too short

What happened

When slicing a large file (~50 objects), preprocess_cancellation and klipper_estimator may take longer to run than the hardcoded timeout of 10 seconds, generating an error.

What did you expect to happen

Large files should be correctly processed.

How to reproduce

I was able to cause this by slicing a file with 50 Benchys. Note that this is on my 8th gen i7 laptop; YMMV as it's obviously dependent on CPU performance.

Additional information

I increased the timeouts manually to 600 seconds and the file was postprocessed correctly.

Error with SET_PRINT_STATS_INFO

What happened

Goodnight. I don't really know if this is a bug, but anything (if it does), move it to the correct place.
I installed the plugin and, when I activate SET_PRINT_STATS_INFO, the printer does the entire heating and leveling process, however, when it starts printing, the Klipper console returns an error saying: !! Error on 'SET_PRINT_STATS_INFO_BASE CURRENT_LAYER=-4': CURRENT_LAYER must have minimum of 0
I went to check gcode and noticed that the first layers are numbered starting with ;LAYER:-6
SET_PRINT_STATS_INFO CURRENT_LAYER=-5
Is it my mistake?
Anyway, thanks for the help...

image

What did you expect to happen

Just let the printing begin... xD

How to reproduce

I just installed the plugin and in the EXTENSIONS >> POST PROCESSING >> MODIFY G-CODE menu, I enabled Klipper PreProcessor v1.2.2 and checked the Add SET_PRINT_STATS_INFO option. All other options are disabled.

image

Additional information

CE3S1_Townsfolke_Woman.zip

Here is the g-code it is generating.

Klipper preprocessor makes saving/uploading from Cura extremely slow on larger files

What happened

I am running Klipper preprocessor with klipper_estimator and "add SET_PRINT_STATS_INFO" enabled. While smaller files (with slicer time estimate of about 1h) the plugin works as expected, the time required by the plugin increases exponentially, when a larger object is sliced (and one can notice that CPU becomes very busy). For moderately sized object the delay might be 1-5 minutes, but for larger files the time becomes unbearable.

For example a file "ap1.stl" from https://www.thingiverse.com/thing:3063072/files, the plugin did not complete within an hour. Using klipper_estimator separately on the same stl file takes about 1 second.

I am using Cura 5.2.1 under Ubuntu 20.04.

What did you expect to happen

The plugin would handle the file within couple of seconds.

How to reproduce

For example a file "ap1.stl" from https://www.thingiverse.com/thing:3063072/files, the plugin did not complete within an hour. Using klipper_estimator separately on the same stl file takes about 1 second.

Additional information

No response

Bed Cooldown towards the end of a print

Is your feature request related to a problem? Please describe

In OctoPrint i loved to cooldown the bed towards the end of a print to

  1. Save Energy
  2. Make it easier to detach your print from the build plate (as mine is always super sticky when hot)

This is the link to the OctoPrint plugin, which allows for the same
https://plugins.octoprint.org/plugins/bedcooldown/

There it is solved by monitoring the print, but as klipper_estimator creates such perfect estimations, one would know that layer beforehand.

Describe the solution you'd like

Identical to the OctoPrint Plugin, it would be perfect to have two additional fields for the configuration

  1. Print time left threshold [s] (Default = 300)
  2. Print completion threshold [%] (Default = 90)
  3. Cooldown temp [ยฐC] (Default = 0)

After the klipper_estimator has run, the script knows the exact time which a print durates. Based on this time, the script would insert
M140 S<COOLDOWNTEMP>
when both conditions are met. The question is how to get the right position (maybe sum up times ?) or maybe cooperate with the maker of klipper_estimator? One would need a table with layer_num;progress;elapsed_time. Based on this and the total print duration the correct layer_num to insert can be identified and the GCODE can be implemented.

Describe alternatives you've considered

  1. slice Model in Cura
  2. see resulting layer count
  3. Calculate layer where to insert the bed cooldown, e.g. 45
  4. Insert Post Processing Plugin 'Search and Replace'
    Search: ;LAYER:(45)
    Replace: ;LAYER:(45)\nM140 S0

Additional information

I would REALLY REALLY love this (and my friends as well)

Possible to add total filament usage to script?

Is your feature request related to a problem? Please describe

Yes, when wanting to switch a spool that will be running out it is nice to be able to plan the pause for a number of reasons. Knowing when to pause requires (for me) knowing how much of the cumulative filament has been used up, at each layer. Currently Cura doesn't provide this info.

Describe the solution you'd like

A simple comment at the end of each layer saying how much cumulative filament has been used. The comment should be unique so it is searchable.

Describe alternatives you've considered

Adding it with a spread sheet. echh.

Additional information

The new Pause @ layer functionality is fantastic. I was discussing with the developers at mainsail if it was possible to delay the pause until the infill section of that layer.

Please see the brief discussion.
mainsail-crew/mainsail#1283

Maybe it would be a possible option that could be integrated into the preprocessor rather than klipper/mainsail.

Thanks for your work!!!

klipper-preprocessor does not appear in "add a script" list

What happened

Placed the file in the script folder but get nothing in the add a script list in Cura 5.3.0

What did you expect to happen

Expected the script to appear in the post processing script list as per instructions.

How to reproduce

install cura 5.3.0 add KlipperPreprocessor.py to scripts folder.

Additional information

No response

Object cancelation doesn't properly recognize and label groups.

What happened

In Cura......

I have some groups/assemblies. If I want to cancel one ideally it should show as a single 'object' for cancelation, but this doesn't happen. With 4 groups I end up with 7 objects.

Also, none of the objects takes the name of the group in cura ( i.e. 'group 1'), instead the object names are based on the name of the file ( object_file name_i, object_file name_i+1, object_file name_i+2) , making it even harder to identify what I would like to cancel.

Finally, the groups all show as overlapping polygons in mainsail making it impossible to identify and cancel the relevant group/object.

What did you expect to happen

Objects based on grouping, with the object name matching that of the group in the cura object list.

How to reproduce

Group a few things, slice and cancel.

Additional information

Hi Pedro, I know your script only routes to the the cancelation preprocessor. But I thought maybe I should raise the issue with you first. I imagine this is likely an issue that must be fixed with the cancelation preprocessor exe?

Not Working for me - Cura 5.2.1

What happened

I followed your settup steps but it is not adding anything to the GCode not even the Timelapse code. I manually checked and nothing is their. I am pretty new to all this so forgive me if I am making a stupid mistake. Below are the paths I used and screen shots of all the folders and the setup.

Path to Cancellation: C:\Users\Louis\AppData\Roaming\cura\5.2\Object_Cancellation\preprocess_cancellation-windows.exe

Path to Estimator: C:\Users\Louis\AppData\Roaming\cura\5.2\Klipper_Estimator\klipper_estimator.exe
Moonraker URL: http://XXX.XXX.XX.XXX:7125

Path to Config: /home/LCasadia/printer_data/config/klipper_estimator.json

Capture
Capture4
Capture3
Capture2

Moonraker URL: http://XXX.XXX.XX.XXX:7125

Path to Config: /home/LCasadia/printer_data/config/klipper_estimator.json

What did you expect to happen

See Above

How to reproduce

See Above

Additional information

No response

Failing to load on macOS, Cura 1.4

What happened

Installing the script doesn't do anything - it errors at line 274 because macOS doesn't support subprocess.STARTUPINFO

What did you expect to happen

The script works

How to reproduce

Install the script on Cura 1.4, macOS 13.0.1

Additional information

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.