mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-23 14:44:19 -06:00
pa calib: print flow value and acceleration (#7178)
* pa calib: print flow value and acceleration Print flow value and acceleration for PA pattern calibration. This should help keep track during adaptive PA calibration. * pa pattern: fix legent section too wide in some cases Rework pa pattern legent generation to correctly estimate width of the legend section. Current flow value now has variable length which is a longest of PA value and the acceleration for a given test. Few examples: 1. PA value are 4 characters: 0.04 Acceleratioion 3 chars: 400 Flow value will be 4 chars long: 7.98, or 11.3 2. PA: 0.018 Accel: 1000 Flow: 12.35, or 6.345 3. PA: 0.04 Accel: 15000 Flow: 34.34, or 4.567 Rework number-to-string conversion flow to correctly round values at given precision.
This commit is contained in:
parent
be5bc632ad
commit
983f1a827e
2 changed files with 57 additions and 12 deletions
|
@ -46,13 +46,20 @@ double CalibPressureAdvance::e_per_mm(
|
||||||
return line_flow.mm3_per_mm() * print_flow_ratio / filament_area ;
|
return line_flow.mm3_per_mm() * print_flow_ratio / filament_area ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CalibPressureAdvance::convert_number_to_string(double num) const
|
std::string CalibPressureAdvance::convert_number_to_string(double num, unsigned int precision) const
|
||||||
{
|
{
|
||||||
auto sNumber = std::to_string(num);
|
std::ostringstream stream;
|
||||||
sNumber.erase(sNumber.find_last_not_of('0') + 1, std::string::npos);
|
|
||||||
sNumber.erase(sNumber.find_last_not_of('.') + 1, std::string::npos);
|
|
||||||
|
|
||||||
return sNumber;
|
if (precision) {
|
||||||
|
/* if number is > 1000 then there are no way we'll fit fractional part into 5 glyphs, so
|
||||||
|
* in this case we keep full precision.
|
||||||
|
* Otherwise we reduce precision by 1 to accomodate decimal separator */
|
||||||
|
stream << std::setprecision(num >= 1000 ? precision : precision - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
stream << num;
|
||||||
|
|
||||||
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CalibPressureAdvance::draw_digit(
|
std::string CalibPressureAdvance::draw_digit(
|
||||||
|
@ -201,12 +208,12 @@ std::string CalibPressureAdvance::draw_number(double
|
||||||
double speed,
|
double speed,
|
||||||
GCodeWriter &writer)
|
GCodeWriter &writer)
|
||||||
{
|
{
|
||||||
auto sNumber = convert_number_to_string(value);
|
auto sNumber = convert_number_to_string(value, m_number_len);
|
||||||
std::stringstream gcode;
|
std::stringstream gcode;
|
||||||
gcode << writer.set_speed(speed);
|
gcode << writer.set_speed(speed);
|
||||||
|
|
||||||
for (std::string::size_type i = 0; i < sNumber.length(); ++i) {
|
for (std::string::size_type i = 0; i < sNumber.length(); ++i) {
|
||||||
if (i > m_max_number_len) {
|
if (i >= m_number_len) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
@ -537,6 +544,18 @@ CalibPressureAdvancePattern::CalibPressureAdvancePattern(
|
||||||
this->m_draw_digit_mode = DrawDigitMode::Bottom_To_Top;
|
this->m_draw_digit_mode = DrawDigitMode::Bottom_To_Top;
|
||||||
|
|
||||||
refresh_setup(config, is_bbl_machine, model, origin);
|
refresh_setup(config, is_bbl_machine, model, origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
double CalibPressureAdvancePattern::flow_val() const
|
||||||
|
{
|
||||||
|
double flow_mult = m_config.option<ConfigOptionFloats>("filament_flow_ratio")->get_at(0);
|
||||||
|
double nozzle_diameter = m_config.option<ConfigOptionFloats>("nozzle_diameter")->get_at(0);
|
||||||
|
double line_width = m_config.get_abs_value("line_width", nozzle_diameter);
|
||||||
|
double layer_height = m_config.get_abs_value("layer_height");
|
||||||
|
double speed = m_config.opt_float("outer_wall_speed");
|
||||||
|
Flow pattern_line = Flow(line_width, layer_height, m_config.option<ConfigOptionFloats>("nozzle_diameter")->get_at(0));
|
||||||
|
|
||||||
|
return speed * pattern_line.mm3_per_mm() * flow_mult;
|
||||||
};
|
};
|
||||||
|
|
||||||
void CalibPressureAdvancePattern::generate_custom_gcodes(const DynamicPrintConfig &config,
|
void CalibPressureAdvancePattern::generate_custom_gcodes(const DynamicPrintConfig &config,
|
||||||
|
@ -564,7 +583,7 @@ void CalibPressureAdvancePattern::generate_custom_gcodes(const DynamicPrintConfi
|
||||||
draw_box_opt_args.is_filled = true;
|
draw_box_opt_args.is_filled = true;
|
||||||
draw_box_opt_args.num_perimeters = wall_count();
|
draw_box_opt_args.num_perimeters = wall_count();
|
||||||
gcode << draw_box(m_writer, m_starting_point.x(), m_starting_point.y() + frame_size_y() + line_spacing_first_layer(),
|
gcode << draw_box(m_writer, m_starting_point.x(), m_starting_point.y() + frame_size_y() + line_spacing_first_layer(),
|
||||||
glyph_tab_max_x() - m_starting_point.x(),
|
print_size_x(),
|
||||||
max_numbering_height() + line_spacing_first_layer() + m_glyph_padding_vertical * 2, draw_box_opt_args);
|
max_numbering_height() + line_spacing_first_layer() + m_glyph_padding_vertical * 2, draw_box_opt_args);
|
||||||
|
|
||||||
std::vector<CustomGCode::Item> gcode_items;
|
std::vector<CustomGCode::Item> gcode_items;
|
||||||
|
@ -593,6 +612,8 @@ void CalibPressureAdvancePattern::generate_custom_gcodes(const DynamicPrintConfi
|
||||||
|
|
||||||
// line numbering
|
// line numbering
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
|
m_number_len = max_numbering_length();
|
||||||
|
|
||||||
gcode << m_writer.set_pressure_advance(m_params.start);
|
gcode << m_writer.set_pressure_advance(m_params.start);
|
||||||
|
|
||||||
double number_e_per_mm = e_per_mm(line_width(), height_layer(),
|
double number_e_per_mm = e_per_mm(line_width(), height_layer(),
|
||||||
|
@ -606,6 +627,18 @@ void CalibPressureAdvancePattern::generate_custom_gcodes(const DynamicPrintConfi
|
||||||
m_params.start + (j * m_params.step), m_draw_digit_mode, line_width(), number_e_per_mm,
|
m_params.start + (j * m_params.step), m_draw_digit_mode, line_width(), number_e_per_mm,
|
||||||
speed_first_layer(), m_writer);
|
speed_first_layer(), m_writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// flow value
|
||||||
|
int line_num = num_patterns + 2;
|
||||||
|
gcode << draw_number(glyph_start_x(line_num), m_starting_point.y() + frame_size_y() + m_glyph_padding_vertical + line_width(),
|
||||||
|
flow_val(), m_draw_digit_mode, line_width(), number_e_per_mm,
|
||||||
|
speed_first_layer(), m_writer);
|
||||||
|
|
||||||
|
// acceleration
|
||||||
|
line_num = num_patterns + 4;
|
||||||
|
gcode << draw_number(glyph_start_x(line_num), m_starting_point.y() + frame_size_y() + m_glyph_padding_vertical + line_width(),
|
||||||
|
m_config.opt_float("default_acceleration"), m_draw_digit_mode, line_width(), number_e_per_mm,
|
||||||
|
speed_first_layer(), m_writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -790,7 +823,7 @@ double CalibPressureAdvancePattern::glyph_tab_max_x() const
|
||||||
(glyph_length_x() - line_width() / 2) + padding;
|
(glyph_length_x() - line_width() / 2) + padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
double CalibPressureAdvancePattern::max_numbering_height() const
|
size_t CalibPressureAdvancePattern::max_numbering_length() const
|
||||||
{
|
{
|
||||||
std::string::size_type most_characters = 0;
|
std::string::size_type most_characters = 0;
|
||||||
const int num_patterns = get_num_patterns();
|
const int num_patterns = get_num_patterns();
|
||||||
|
@ -804,9 +837,18 @@ double CalibPressureAdvancePattern::max_numbering_height() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
most_characters = std::min(most_characters, m_max_number_len);
|
std::string sAccel = convert_number_to_string(m_config.opt_float("default_acceleration"));
|
||||||
|
most_characters = std::max(most_characters, sAccel.length());
|
||||||
|
|
||||||
return (most_characters * m_digit_segment_len) + ((most_characters - 1) * m_digit_gap_len);
|
/* don't actually check flow value: we'll print as many fractional digits as fits */
|
||||||
|
|
||||||
|
return std::min(most_characters, m_max_number_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
double CalibPressureAdvancePattern::max_numbering_height() const
|
||||||
|
{
|
||||||
|
std::string::size_type num_characters = max_numbering_length();
|
||||||
|
return (num_characters * m_digit_segment_len) + ((num_characters - 1) * m_digit_gap_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
double CalibPressureAdvancePattern::pattern_shift() const
|
double CalibPressureAdvancePattern::pattern_shift() const
|
||||||
|
|
|
@ -155,7 +155,7 @@ protected:
|
||||||
double e_per_mm(double line_width, double layer_height, float nozzle_diameter, float filament_diameter, float print_flow_ratio) const;
|
double e_per_mm(double line_width, double layer_height, float nozzle_diameter, float filament_diameter, float print_flow_ratio) const;
|
||||||
double speed_adjust(int speed) const { return speed * 60; };
|
double speed_adjust(int speed) const { return speed * 60; };
|
||||||
|
|
||||||
std::string convert_number_to_string(double num) const;
|
std::string convert_number_to_string(double num, unsigned precision = 0) const;
|
||||||
double number_spacing() const { return m_digit_segment_len + m_digit_gap_len; };
|
double number_spacing() const { return m_digit_segment_len + m_digit_gap_len; };
|
||||||
std::string draw_digit(double startx,
|
std::string draw_digit(double startx,
|
||||||
double starty,
|
double starty,
|
||||||
|
@ -188,6 +188,7 @@ protected:
|
||||||
const double m_digit_segment_len{2};
|
const double m_digit_segment_len{2};
|
||||||
const double m_digit_gap_len{1};
|
const double m_digit_gap_len{1};
|
||||||
const std::string::size_type m_max_number_len{5};
|
const std::string::size_type m_max_number_len{5};
|
||||||
|
std::string::size_type m_number_len{m_max_number_len}; /* Current length of number labels */
|
||||||
};
|
};
|
||||||
|
|
||||||
class CalibPressureAdvanceLine : public CalibPressureAdvance
|
class CalibPressureAdvanceLine : public CalibPressureAdvance
|
||||||
|
@ -255,6 +256,7 @@ public:
|
||||||
double print_size_x() const { return object_size_x() + pattern_shift(); };
|
double print_size_x() const { return object_size_x() + pattern_shift(); };
|
||||||
double print_size_y() const { return object_size_y(); };
|
double print_size_y() const { return object_size_y(); };
|
||||||
double max_layer_z() const { return height_first_layer() + ((m_num_layers - 1) * height_layer()); };
|
double max_layer_z() const { return height_first_layer() + ((m_num_layers - 1) * height_layer()); };
|
||||||
|
double flow_val() const;
|
||||||
|
|
||||||
void generate_custom_gcodes(const DynamicPrintConfig &config, bool is_bbl_machine, Model &model, const Vec3d &origin);
|
void generate_custom_gcodes(const DynamicPrintConfig &config, bool is_bbl_machine, Model &model, const Vec3d &origin);
|
||||||
|
|
||||||
|
@ -296,6 +298,7 @@ private:
|
||||||
double glyph_length_x() const;
|
double glyph_length_x() const;
|
||||||
double glyph_tab_max_x() const;
|
double glyph_tab_max_x() const;
|
||||||
double max_numbering_height() const;
|
double max_numbering_height() const;
|
||||||
|
size_t max_numbering_length() const;
|
||||||
|
|
||||||
double pattern_shift() const;
|
double pattern_shift() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue