Skip to content

Commit

Permalink
Add Ellis' pattern method for pressure advance calibration (SoftFever…
Browse files Browse the repository at this point in the history
…#1547)

* Add pattern method to Pressure Advance dialog

* Convert calib_pressure_advance to more unique calib_pressure_advance_line

* Share move_to function with PA lines and patterns

* Add PA pattern to calib.hpp

* Implement move_to(Vec3d). Combine with Vec2d version

* Add call to PA pattern in GCode.cpp

* Add helper functions

* Add directionality to draw_digit

* Extract shared number drawing variables

* Extract convert_number_to_string function

* Use in-class initializers for pattern variables

* Add max_numbering_height function

* Add helper functions

* Extract shared delta helper functions

* Add pattern generate_test() and associated helpers

* Clarify use of math functions

* Remove unused move_to overload, accept move_to comments

* Add get_distance() and draw_line()

* Extract set_nozzle_diameter()

* Clean up and simplify

* Rearrange and clean up

* Start work on print_pa_pattern

* Complete basic draw_box function

* Add more helper functions

* Add struct for pattern config, more helpers

* Rearrange

* Add encroachment member variable

* Add structs to manage optional arguments

* Simplify optional arguments structs

* Update opt args usage. Finish draw_box function

* Complete print_pa_pattern function

* Reuse PA Line STL

* Fix forward declaration error

* Fix invalid comparison

* Fixing complier errors

* Make DrawDigitMode options more clear

* More compilation error fixes

* Yet more compile error fixes

* Fix incorrect default step value

* Handle top-level dialog changes, consolidate params definitions

* Add layer change G-code, set more print variables

* Simplify optArgs constructors

* Fix pattern drawing, minor misc. clean up

* Make draw_box() G-code comments more helpful

* Make more of draw_line() const

* Fix sequential number draw direction

* Extract shared e_per_mm function

* Fix misplaced decimal in PA Line

* Move short constructor into .hpp

* Fix inverted Y direction in pattern digit drawing

* Use placeholder STL to create needed layers

* Rearrange and clean up

* Proof of concept: Adding custom G-Code at layer

* Use new scaling method

* Reorganize Plater::calib_pa()

* Restructure calib

* New strategy for adding custom G-code

* Remove redundant invocation

* Use cube primitive as positioning handle

* Move logic to Plater

Modifications to model in GCode cancelled _do_export from within itself

* Consolidate m_starting_point and pattern_start functions

* Replace bed_center() with m_starting_point

* Fix and consolidate number tab creation

* Fix off by one layer bug

* Use correct bounding box

* Use Vec3d instead of Vec2d for m_starting_point and m_last_pos

* Add translate_starting_point function

* Vec3d fix

* Store CalibPressureAdvancePattern with model

* Formatting adjustments

* Move pattern when handle moves

* Improve const correctness

* Improve/fix pattern writer and config

* Fix speed setting bug

* Pass model into generate_gcodes to improve consistency

* Re-generate pattern on reslice

* Make pattern actually move with handle

* Fix overzealous m_last_pos initialization

* Use clearer function names

* Use correct model

* Remove unused member variable

* Don't hard-code print config settings

* Remove unused lines, formatting clean up

* Make sure set_key_value operates on existing keys

* Remove asserts which limited life of key/value set

* Update Calibration.md

* Update licensing info

* Actually use speed in draw_line

* Don't speed_adjust twice

* doc: Make width and speed settings used more clear

* Bugfix: Shouldn't need to move handle to see pattern

* Clean up

* Move mp_gcodegen into line method alone

* Fix wrong number thickness in PA Line

* Remove unnecessary middleman PatternSettings

* Give value of config to const m_initial_config, not ref

* Fix incorrect DrawBoxOptArg default

* Use line_width_anchor() for all of initial layer

* Use clearer function name

* Replace "anchor" with "first_layer" for better consistency

* Update Calibration.md

* Update Calibration.md

* Make number tab infill explanation more clear

* (Hopefully) fix missing origin

* Add GCodeProcessor tags

* Fully refresh config

* Don't store is_bbl_printer

* Move set_starting_point to private

* Don't constantly recreate GCodeWriter

* Use different step value for pattern test

* Remove redundant processor tags

* Label glyph G-code

* Fix comparison typo

* Set number print speed

* Fix mixed up draw_number parameter

* Don't use line_width_first_layer for pattern

* (Hopefully) fix temp tower generating PA pattern

* Start with pattern centered on plate

* Add gap between pattern and handle

* Fix overly persistent pattern

* Revert "(Hopefully) fix temp tower generating PA pattern"

This reverts commit 0aa1206.

---------

Co-authored-by: SoftFever <[email protected]>
  • Loading branch information
thewildmage and SoftFever authored Jul 22, 2023
1 parent 87f6c43 commit 777c7c6
Show file tree
Hide file tree
Showing 12 changed files with 1,388 additions and 288 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,7 @@ Slic3r is licensed under the GNU Affero General Public License, version 3. Slic3
The GNU Affero General Public License, version 3 ensures that if you use any part of this software in any way (even behind a web server), your software must be released under the same license.
Orca Slicer includes a pressure advance calibration pattern test adapted from Andrew Ellis' generator, which is licensed under GNU General Public License, version 3. Ellis' generator is itself adapted from a generator developed by Sineos for Marlin, which is licensed under GNU General Public License, version 3.
The bambu networking plugin is based on non-free libraries. It is optional to the Orca Slicer and provides extended functionalities for users.
30 changes: 27 additions & 3 deletions doc/Calibration.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
- [Flow rate](#Flow-rate)
- [Pressure Advance](#Pressure-Advance)
1. [Line method](#Line-method)
2. [Tower method](#Tower-method)
2. [Pattern method](#Pattern-method)
3. [Tower method](#Tower-method)
- [Temp tower](#Temp-tower)
- [Retraction test](#Retraction-test)
- [Orca Tolerance Test](#Orca-Tolerance-Test)
Expand Down Expand Up @@ -32,10 +33,13 @@ Steps
![image](https://user-images.githubusercontent.com/103989404/210139721-919be130-fbba-4e3a-aa58-8a563e8c7792.png)

# Pressure Advance
I will present two approaches for calibrating the pressure advance value. Both methods have their own advantages and disadvantages. It is important to note that each method has two versions: one for a direct drive extruder and one for a Bowden extruder. Make sure to select the appropriate version for your test.
##### *NOTE: For Bambulab X1/X1C users, make sure you do not select the 'Flow calibration' option.*

Orca Slicer includes three approaches for calibrating the pressure advance value. Each method has its own advantages and disadvantages. It is important to note that each method has two versions: one for a direct drive extruder and one for a Bowden extruder. Make sure to select the appropriate version for your test.
##### *NOTE: For Bambulab X1/X1C users, make sure you do not select the 'Flow calibration' option when printings.*
![uncheck](https://user-images.githubusercontent.com/103989404/221345187-3c317a46-4d85-4221-99b9-adb5c7f48026.jpeg)

### Line method

The line method is quick and straightforward to test. However, its accuracy highly depends on your first layer quality. It is suggested to turn on the bed mesh leveling for this test.
Steps:
1. Select the printer, filament, and process you would like to use for the test.
Expand All @@ -48,7 +52,27 @@ Steps:
![line_0 016](https://user-images.githubusercontent.com/103989404/210140046-dc5adf6a-42e8-48cd-950c-5e81558da967.jpg)
![image](https://user-images.githubusercontent.com/103989404/210140079-61a4aba4-ae01-4988-9f8e-2a45a90cdb7d.png)

### Pattern method

The pattern method is adapted from [Andrew Ellis' pattern method generator](https://ellis3dp.com/Pressure_Linear_Advance_Tool/), which was itself derived from the [Marlin pattern method](https://marlinfw.org/tools/lin_advance/k-factor.html) developed by [Sineos](https://github.com/Sineos/k-factorjs).

[Instructions for using and reading the pattern method](https://ellis3dp.com/Print-Tuning-Guide/articles/pressure_linear_advance/pattern_method.html) are provided in [Ellis' Print Tuning Guide](https://ellis3dp.com/Print-Tuning-Guide/), with only a few Orca Slicer differences to note.

First and foremost, when you initiate the test, you'll only see a small rectangular prism on the plate. This object serves a few purposes:

1. The test pattern itself is added in as custom G-Code at each layer, same as you could do by hand actually. The rectangular prism gives us the layers in which to insert that G-Code. This also means that **you'll see the full test pattern when you move to the Preview pane**
2. The prism acts as a handle, enabling you to move the test pattern wherever you'd like on the plate by moving the prism
3. The filament selected for the prism is also used for the test pattern

Next, Ellis' generator provided the ability to adjust specific printer, filament, and print profile settings. You can make these same changes in Orca Slicer by adjusting the settings in the Prepare pane as you would with any other print. When you initiate the calibration test, Ellis' default settings are applied. A few things to note about these settings:

1. Ellis specified line widths as a percent of filament diameter. The Orca pattern method does the same to provide its suggested defaults, making use of Ellis' percentages in combination with your specified nozzle diameter
2. In terms of line width, the pattern only makes use of the `Default` and `First layer` widths
3. In terms of speed, the pattern only uses the `First layer speed -> First layer` and `Other layers speed -> Outer wall` speeds
4. The infill pattern beneath the numbers cannot be changed becuase it's not actually an infill pattern pulled from the settings. All of the pattern G-Code is custom written, so that "infill" is, effectively, hand-drawn and so not processed through the usual channels that would enable Orca to recognize it as infill

### Tower method

The tower method may take a bit more time to complete, but it does not rely on the quality of the first layer.
The PA value for this test will be increased by 0.002 for every 1 mm increase in height. (**NOTE** 0.02 for Bowden)
Steps:
Expand Down
10 changes: 6 additions & 4 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "Print.hpp"
#include "Utils.hpp"
#include "ClipperUtils.hpp"
#include "libslic3r.h"
#include "LocalesUtils.hpp"
#include "libslic3r/format.hpp"
#include "Time.hpp"
Expand Down Expand Up @@ -1056,7 +1055,6 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu
GCodeProcessor::s_IsBBLPrinter = print->is_BBL_printer();
print->set_started(psGCodeExport);


// check if any custom gcode contains keywords used by the gcode processor to
// produce time estimation and gcode toolpaths
std::vector<std::pair<std::string, std::string>> validation_res = DoExport::validate_custom_gcode(*print);
Expand Down Expand Up @@ -1886,14 +1884,18 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
gcode += m_writer.set_jerk_xy(jerk);
}

calib_pressure_advance pa_test(this);
auto params = print.calib_params();

CalibPressureAdvanceLine pa_test(this);

double filament_max_volumetric_speed = m_config.option<ConfigOptionFloats>("filament_max_volumetric_speed")->get_at(initial_extruder_id);
Flow pattern_line = Flow(pa_test.line_width(), 0.2, m_config.nozzle_diameter.get_at(0));
auto fast_speed = std::min(print.default_region_config().outer_wall_speed.value, filament_max_volumetric_speed / pattern_line.mm3_per_mm());
auto slow_speed = std::max(20.0, fast_speed / 10.0);

pa_test.set_speed(fast_speed, slow_speed);
pa_test.draw_numbers() = print.calib_params().print_numbers;
auto params = print.calib_params();

gcode += pa_test.generate_test(params.start, params.step, std::llround(std::ceil((params.end - params.start) / params.step)));

file.write(gcode);
Expand Down
8 changes: 8 additions & 0 deletions src/libslic3r/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ Model& Model::assign_copy(const Model &rhs)
this->plates_custom_gcodes = rhs.plates_custom_gcodes;
this->curr_plate_index = rhs.curr_plate_index;

if (rhs.calib_pa_pattern) {
this->calib_pa_pattern = std::make_unique<CalibPressureAdvancePattern>(
CalibPressureAdvancePattern(*rhs.calib_pa_pattern)
);
}

// BBS: for design info
this->design_info = rhs.design_info;
this->model_info = rhs.model_info;
Expand Down Expand Up @@ -100,6 +106,7 @@ Model& Model::assign_copy(Model &&rhs)
// BBS
this->plates_custom_gcodes = std::move(rhs.plates_custom_gcodes);
this->curr_plate_index = rhs.curr_plate_index;
this->calib_pa_pattern = std::move(rhs.calib_pa_pattern);

//BBS: add auxiliary path logic
// BBS: backup, all in one temp dir
Expand Down Expand Up @@ -893,6 +900,7 @@ void Model::load_from(Model& model)
model.design_info.reset();
model.model_info.reset();
model.profile_info.reset();
model.calib_pa_pattern.reset();
}

// BBS: backup
Expand Down
3 changes: 3 additions & 0 deletions src/libslic3r/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "SLA/Hollowing.hpp"
#include "TriangleMesh.hpp"
#include "CustomGCode.hpp"
#include "calib.hpp"
#include "enum_bitmask.hpp"

//BBS: add bbs 3mf
Expand Down Expand Up @@ -1608,6 +1609,8 @@ class Model final : public ObjectBase
// Checks if any of objects is painted using the multi-material painting gizmo.
bool is_mm_painted() const;

std::unique_ptr<CalibPressureAdvancePattern> calib_pa_pattern;

private:
explicit Model(int) : ObjectBase(-1)
{
Expand Down
Loading

0 comments on commit 777c7c6

Please sign in to comment.