Skip to content
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

Enhancement: Adaptive Pressure advance #5609

Merged
merged 77 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
15d817c
Adaptive Pressure advance options setup
igiannakas Jun 6, 2024
c0aa34e
Dynamic PA - PCHIP interpolator code and tests
igiannakas Jun 6, 2024
755539f
Integrate dynamic PA with slicing code - emit new PA values per speed…
igiannakas Jun 6, 2024
257cdeb
Link adaptive PA to role change instead of speed change
igiannakas Jun 6, 2024
8b72f44
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jun 6, 2024
7364dfc
Adaptive PA - Alpha 2
igiannakas Jun 7, 2024
62c1ce7
Hide adaptive PA for overhangs
igiannakas Jun 7, 2024
f4bd8f0
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jun 7, 2024
75ac45b
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jun 7, 2024
6623beb
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jun 8, 2024
a379a09
Merge branch 'SoftFever:main' into Adaptive-Pressure-Advance
igiannakas Jun 8, 2024
98c9f06
Convert Adaptive PA to use volumetric flow model and start preparing …
igiannakas Jun 9, 2024
00a2ac4
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jun 9, 2024
a77b980
Converted Dynamic PA to a post processing filter. Reverted changes in…
igiannakas Jun 10, 2024
9b97d38
Removed adaptive PA for overhangs
igiannakas Jun 10, 2024
26ba3b8
Foundations for two dimensional adaptive PA based on acceleration and…
igiannakas Jun 11, 2024
1121b9e
Minor code cleanup and updating of tooltips
igiannakas Jun 12, 2024
f3894e5
Renaming files for better clarity and generate classes documentation
igiannakas Jun 12, 2024
940fc28
Merge branch 'SoftFever:main' into Adaptive-Pressure-Advance
igiannakas Jun 15, 2024
8f84d1b
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jun 16, 2024
7c974d3
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jun 17, 2024
015a5fa
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jun 19, 2024
f851d8e
Update src/libslic3r/PrintConfig.cpp
igiannakas Jun 20, 2024
8debf65
Update src/libslic3r/PrintConfig.cpp
igiannakas Jun 20, 2024
2363296
Update src/libslic3r/PrintConfig.cpp
igiannakas Jun 20, 2024
2617613
Merge branch 'SoftFever:main' into Adaptive-Pressure-Advance
igiannakas Jun 21, 2024
100a3a4
Introduce average mm3_mm over the length of a multipath for adaptive PA
igiannakas Jun 22, 2024
23cfd5c
Updates for multipath handling part 2
igiannakas Jun 22, 2024
e241172
Introduce average mm3_mm over the length of a multipath for adaptive PA
igiannakas Jun 22, 2024
b1a2be4
Trigger PA evaluation more frequently to catch edge cases where speed…
igiannakas Jun 22, 2024
4d19173
Updates for multipath handling part 2
igiannakas Jun 22, 2024
cf8c023
Adaptive PA: Implement average flow estimation on loops
igiannakas Jun 23, 2024
aec4969
Code formatting
igiannakas Jun 23, 2024
cecd1ac
Fix adaptive PA not adapting for small disconnected external wall lin…
igiannakas Jun 23, 2024
b1bc6a7
Updated to take max print speed of upcoming feature to calculate new …
igiannakas Jun 24, 2024
0c50606
Code clean up
igiannakas Jun 24, 2024
062ba5d
Performance tuning
igiannakas Jun 24, 2024
68dfa81
Further performance tuning by reducing use of regex commands in the n…
igiannakas Jun 24, 2024
b1cb6f3
Further performance tuning and tweaks to stop searching for max speed…
igiannakas Jun 24, 2024
7663e3a
Merge remote-tracking branch 'upstream/main' into Adaptive-Pressure-A…
igiannakas Jun 24, 2024
6f47b51
Merge remote-tracking branch 'upstream/main' into Adaptive-Pressure-A…
igiannakas Jun 24, 2024
8729f57
Reduce debug information
igiannakas Jun 25, 2024
1e24e3c
Updated debug info
igiannakas Jun 25, 2024
c519742
Merge remote-tracking branch 'upstream/main' into Adaptive-Pressure-A…
igiannakas Jun 25, 2024
41826e0
Merge branch 'SoftFever:main' into Adaptive-Pressure-Advance
igiannakas Jun 26, 2024
152b0f2
Fix an issue on seams on specific models when wipe before external pe…
igiannakas Jun 28, 2024
2825f8f
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jun 28, 2024
4983a4f
Prepare for adaptive PA for overhangs, fix wipe bug & clean up code a…
igiannakas Jun 28, 2024
7c776c6
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jun 28, 2024
0f4aef5
Initial commit for adapting PA when extruding fully overhanging perim…
igiannakas Jun 28, 2024
821ffc6
Ignore wipe command when identifying current print speed
igiannakas Jun 28, 2024
5ea2de6
Merge branch 'SoftFever:main' into Adaptive-Pressure-Advance
igiannakas Jun 29, 2024
50f2f01
Merge remote-tracking branch 'upstream/main' into Adaptive-Pressure-A…
igiannakas Jun 29, 2024
35a64d4
Merge branch 'SoftFever:main' into Adaptive-Pressure-Advance
igiannakas Jul 1, 2024
eef7c7e
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jul 1, 2024
79fbe3f
Option to evaluate adaptive PA on overhang regions in preparation for…
igiannakas Jul 1, 2024
5747b7c
Merge remote-tracking branch 'upstream/main' into Adaptive-Pressure-A…
igiannakas Jul 2, 2024
35dc6d9
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jul 2, 2024
bed4cc9
Update to issue PA changes for varying flow conditions within the sam…
igiannakas Jul 2, 2024
b587205
Fix bug where adaptive PA was enabled erroneously for role changes an…
igiannakas Jul 2, 2024
a646f30
Merge remote-tracking branch 'upstream/main' into Adaptive-Pressure-A…
igiannakas Jul 2, 2024
6f01cf1
Refactored some code
igiannakas Jul 2, 2024
57a2ab4
More refactoring
igiannakas Jul 2, 2024
9ff4c69
Merge branch 'main' into Adaptive-Pressure-Advance
igiannakas Jul 3, 2024
0a7429a
Some bug fixes and enabled comments only when verbose g-code is enabled
igiannakas Jul 4, 2024
f0df6a7
Introduced dedicated PA option for bridges
igiannakas Jul 4, 2024
27b9d75
Merge remote-tracking branch 'upstream/main' into Adaptive-Pressure-A…
igiannakas Jul 7, 2024
00ba09f
Code refactoring to optimise initialisation of PA processor (making i…
igiannakas Jul 8, 2024
82ed6eb
Merge branch 'SoftFever:main' into Adaptive-Pressure-Advance
igiannakas Jul 11, 2024
bd37e13
Merge remote-tracking branch 'upstream/main' into Adaptive-Pressure-A…
igiannakas Jul 14, 2024
24885ae
Merge remote-tracking branch 'upstream/main' into Adaptive-Pressure-A…
igiannakas Jul 16, 2024
cf15c84
Updates to adaptive PA tooltips
igiannakas Jul 23, 2024
60a4a13
Bridging PA check with Epsilon instead of 0.
igiannakas Jul 23, 2024
d85a891
Merge remote-tracking branch 'upstream/main' into Adaptive-Pressure-A…
igiannakas Jul 23, 2024
4fdf79e
Merge branch 'SoftFever:main' into Adaptive-Pressure-Advance
igiannakas Jul 26, 2024
64f1b60
Merge remote-tracking branch 'upstream/main' into Adaptive-Pressure-A…
igiannakas Jul 27, 2024
487722a
Adaptive PA: addressing comments
igiannakas Jul 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/libslic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ set(lisbslic3r_sources
GCode/RetractWhenCrossingPerimeters.hpp
GCode/SmallAreaInfillFlowCompensator.cpp
GCode/SmallAreaInfillFlowCompensator.hpp
GCode/PchipInterpolatorHelper.cpp
GCode/PchipInterpolatorHelper.hpp
GCode/AdaptivePAInterpolator.cpp
GCode/AdaptivePAInterpolator.hpp
GCode/AdaptivePAProcessor.cpp
GCode/AdaptivePAProcessor.hpp
GCode/SpiralVase.cpp
GCode/SpiralVase.hpp
GCode/SeamPlacer.cpp
Expand Down
239 changes: 234 additions & 5 deletions src/libslic3r/GCode.cpp

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion src/libslic3r/GCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "GCode/PressureEqualizer.hpp"
#include "GCode/SmallAreaInfillFlowCompensator.hpp"
// ORCA: post processor below used for Dynamic Pressure advance
#include "GCode/AdaptivePAProcessor.hpp"

#include <memory>
#include <map>
Expand Down Expand Up @@ -358,6 +360,19 @@ class GCode {
std::string extrude_loop(ExtrusionLoop loop, std::string description, double speed = -1., const ExtrusionEntitiesPtr& region_perimeters = ExtrusionEntitiesPtr());
std::string extrude_multi_path(ExtrusionMultiPath multipath, std::string description = "", double speed = -1.);
std::string extrude_path(ExtrusionPath path, std::string description = "", double speed = -1.);

// Orca: Adaptive PA variables
// Used for adaptive PA when extruding paths with multiple, varying flow segments.
// This contains the sum of the mm3_per_mm values weighted by the length of each path segment.
// The m_multi_flow_segment_path_pa_set constrains the PA change request to the first extrusion segment.
// It sets the mm3_mm value for the adaptive PA post processor to be the average of that path
// as calculated and stored in the m_multi_segment_path_average_mm3_per_mm value
double m_multi_flow_segment_path_average_mm3_per_mm = 0;
bool m_multi_flow_segment_path_pa_set = false;
// Adaptive PA last set flow to enable issuing of PA change commands when adaptive PA for overhangs
// is enabled
double m_last_mm3_mm = 0;
// Orca: Adaptive PA code segment end

// Extruding multiple objects with soluble / non-soluble / combined supports
// on a multi-material printer, trying to minimize tool switches.
Expand Down Expand Up @@ -540,11 +555,13 @@ class GCode {
std::unique_ptr<SpiralVase> m_spiral_vase;

std::unique_ptr<PressureEqualizer> m_pressure_equalizer;

std::unique_ptr<AdaptivePAProcessor> m_pa_processor;

std::unique_ptr<WipeTowerIntegration> m_wipe_tower;

std::unique_ptr<SmallAreaInfillFlowCompensator> m_small_area_infill_flow_compensator;

// Heights (print_z) at which the skirt has already been extruded.
std::vector<coordf_t> m_skirt_done;
// Has the brim been extruded already? Brim is being extruded only for the first object of a multi-object print.
Expand Down
114 changes: 114 additions & 0 deletions src/libslic3r/GCode/AdaptivePAInterpolator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// AdaptivePAInterpolator.cpp
// OrcaSlicer
//
// Implementation file for the AdaptivePAInterpolator class, providing methods to parse data and perform PA interpolation.

#include "AdaptivePAInterpolator.hpp"
#include <stdexcept>
#include <cmath>
#include <algorithm>
#include <sstream>

/**
* @brief Parses the input data and sets up the interpolators.
* @param data A string containing the data in CSV format (PA, flow rate, acceleration).
* @return 0 on success, -1 on error.
*/
int AdaptivePAInterpolator::parseAndSetData(const std::string& data) {
flow_interpolators_.clear();
accelerations_.clear();

try {
std::istringstream ss(data);
std::string line;
std::map<double, std::vector<std::pair<double, double>>> acc_to_flow_pa;

while (std::getline(ss, line)) {
std::istringstream lineStream(line);
std::string value;
double paValue, flowRate, acceleration;
paValue = flowRate = acceleration = 0.f; // initialize all to zero.

// Parse PA value
if (std::getline(lineStream, value, ',')) {
paValue = std::stod(value);
}

// Parse flow rate value
if (std::getline(lineStream, value, ',')) {
flowRate = std::stod(value);
}

// Parse acceleration value
if (std::getline(lineStream, value, ',')) {
acceleration = std::stod(value);
}

// Store the parsed values in a map with acceleration as the key
acc_to_flow_pa[acceleration].emplace_back(flowRate, paValue);
}

// Iterate through the map to set up the interpolators
for (const auto& kv : acc_to_flow_pa) {
double acceleration = kv.first;
const auto& data = kv.second;

std::vector<double> flowRates;
std::vector<double> paValues;

for (const auto& pair : data) {
flowRates.push_back(pair.first);
paValues.push_back(pair.second);
}

// Only set up the interpolator if there are enough data points
if (flowRates.size() > 1) {
PchipInterpolatorHelper interpolator(flowRates, paValues);
flow_interpolators_[acceleration] = interpolator;
accelerations_.push_back(acceleration);
}
}
} catch (const std::exception&) {
m_isInitialised = false;
return -1; // Error: Exception during parsing
}
m_isInitialised = true;
return 0; // Success
}

/**
* @brief Interpolates the PA value for the given flow rate and acceleration.
* @param flow_rate The flow rate at which to interpolate.
* @param acceleration The acceleration at which to interpolate.
* @return The interpolated PA value, or -1 if interpolation fails.
*/
double AdaptivePAInterpolator::operator()(double flow_rate, double acceleration) {
std::vector<double> pa_values;
std::vector<double> acc_values;

// Estimate PA value for every flow to PA model for the given flow rate
for (const auto& kv : flow_interpolators_) {
double pa_value = kv.second.interpolate(flow_rate);

// Check if the interpolated PA value is valid
if (pa_value != -1) {
pa_values.push_back(pa_value);
acc_values.push_back(kv.first);
}
}

// Check if there are enough acceleration values for interpolation
if (acc_values.size() < 2) {
// Special case: Only one acceleration value
if (acc_values.size() == 1) {
return std::round(pa_values[0] * 1000.0) / 1000.0; // Rounded to 3 decimal places
}
return -1; // Error: Not enough data points for interpolation
}

// Create a new PchipInterpolatorHelper for PA-acceleration interpolation
// Use the estimated PA values from the for loop above and their corresponding accelerations to
// generate the new PCHIP model. Then run this model to interpolate the PA value for the given acceleration value.
PchipInterpolatorHelper pa_accel_interpolator(acc_values, pa_values);
return std::round(pa_accel_interpolator.interpolate(acceleration) * 1000.0) / 1000.0; // Rounded to 3 decimal places
}
54 changes: 54 additions & 0 deletions src/libslic3r/GCode/AdaptivePAInterpolator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// AdaptivePAInterpolator.hpp
// OrcaSlicer
//
// Header file for the AdaptivePAInterpolator class, responsible for interpolating pressure advance (PA) values based on flow rate and acceleration using PCHIP interpolation.

#ifndef ADAPTIVEPAINTERPOLATOR_HPP
#define ADAPTIVEPAINTERPOLATOR_HPP

#include <vector>
#include <string>
#include <map>
#include "PchipInterpolatorHelper.hpp"

/**
* @class AdaptivePAInterpolator
* @brief A class to interpolate pressure advance (PA) values based on flow rate and acceleration using Piecewise Cubic Hermite Interpolating Polynomial (PCHIP) interpolation.
*/
class AdaptivePAInterpolator {
public:
/**
* @brief Default constructor.
*/
AdaptivePAInterpolator() : m_isInitialised(false) {}

/**
* @brief Parses the input data and sets up the interpolators.
* @param data A string containing the data in CSV format (PA, flow rate, acceleration).
* @return 0 on success, -1 on error.
*/
int parseAndSetData(const std::string& data);

/**
* @brief Interpolates the PA value for the given flow rate and acceleration.
* @param flow_rate The flow rate at which to interpolate.
* @param acceleration The acceleration at which to interpolate.
* @return The interpolated PA value, or -1 if interpolation fails.
*/
double operator()(double flow_rate, double acceleration);

/**
* @brief Returns the initialization status.
* @return The value of m_isInitialised.
*/
bool isInitialised() const {
return m_isInitialised;
}

private:
std::map<double, PchipInterpolatorHelper> flow_interpolators_; ///< Map each acceleration to a flow-rate-to-PA interpolator.
std::vector<double> accelerations_; ///< Store unique accelerations.
bool m_isInitialised;
};

#endif // ADAPTIVEPAINTERPOLATOR_HPP
Loading