From 97c4c0200180c461a0d2504b2fe1ef6f3f6f9163 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 22 Mar 2021 13:23:24 +0100 Subject: [PATCH 01/10] Wipe tower: don't do sparse infill when there is a soluble filament above it --- src/libslic3r/GCode/WipeTower.cpp | 51 ++++++++++++++++++++++++------- src/libslic3r/GCode/WipeTower.hpp | 1 + 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index f3ecd2cf33..8385375bb8 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -556,6 +556,7 @@ void WipeTower::set_extruder(size_t idx, const PrintConfig& config) m_filpar.push_back(FilamentParameters()); m_filpar[idx].material = config.filament_type.get_at(idx); + m_filpar[idx].is_soluble = config.filament_soluble.get_at(idx); m_filpar[idx].temperature = config.temperature.get_at(idx); m_filpar[idx].first_layer_temperature = config.first_layer_temperature.get_at(idx); @@ -1192,19 +1193,47 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() const float right = fill_box.ru.x() - 2 * m_perimeter_width; if (dy > m_perimeter_width) { - // Extrude an inverse U at the left of the region. - writer.travel(fill_box.ld + Vec2f(m_perimeter_width * 2, 0.f)) - .extrude(fill_box.lu + Vec2f(m_perimeter_width * 2, 0.f), 2900 * speed_factor); + writer.travel(fill_box.ld + Vec2f(m_perimeter_width * 2, 0.f)); - const int n = 1+int((right-left)/m_bridging); - const float dx = (right-left)/n; - for (int i=1;i<=n;++i) { - float x=left+dx*i; - writer.travel(x,writer.y()); - writer.extrude(x,i%2 ? fill_box.rd.y() : fill_box.ru.y()); + // Is there a soluble filament wiped/rammed at the next layer? + // If so, the infill should not be sparse. + bool solid_infill = m_layer_info+1 == m_plan.end() + ? false + : std::any_of((m_layer_info+1)->tool_changes.begin(), + (m_layer_info+1)->tool_changes.end(), + [this](const WipeTowerInfo::ToolChange& tch) { + return m_filpar[tch.new_tool].is_soluble + || m_filpar[tch.old_tool].is_soluble; + }); + + if (solid_infill) { + const float sparse_factor = 1.5f; // 1=solid, 2=every other line, etc. + float y = fill_box.ld.y() + m_perimeter_width; + int n = dy / (m_perimeter_width * sparse_factor); + float spacing = (dy-m_perimeter_width)/(n-1); + int i = 0; + for (i=0; i Date: Wed, 17 Mar 2021 17:42:07 +0100 Subject: [PATCH 02/10] Wipe tower: remove unfinished square wipe tower option --- src/libslic3r/GCode/WipeTower.cpp | 65 +++++-------------------------- src/libslic3r/GCode/WipeTower.hpp | 1 - src/libslic3r/Print.cpp | 4 +- 3 files changed, 10 insertions(+), 60 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 8385375bb8..35e4e7091f 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -9,17 +9,6 @@ #include "BoundingBox.hpp" -// Experimental "Peter's wipe tower" feature was partially implemented, inspired by -// PJR's idea of alternating two perpendicular wiping directions on a square tower. -// It is probably never going to be finished, there are multiple remaining issues -// and there is probably no need to go down this way. m_peters_wipe_tower variable -// turns this on, maybe it should just be removed. Anyway, the issues are -// - layer's are not exactly square -// - variable width for higher levels -// - make sure it is not too sparse (apply max_bridge_distance and make last wipe longer) -// - enable enhanced first layer adhesion - - namespace Slic3r { @@ -738,7 +727,7 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) writer.set_extrusion_flow(m_extrusion_flow) .set_z(m_z_pos) .set_initial_tool(m_current_tool) - .set_y_shift(m_y_shift + (tool!=(unsigned int)(-1) && (m_current_shape == SHAPE_REVERSED && !m_peters_wipe_tower) ? m_layer_info->depth - m_layer_info->toolchanges_depth(): 0.f)) + .set_y_shift(m_y_shift + (tool!=(unsigned int)(-1) && (m_current_shape == SHAPE_REVERSED) ? m_layer_info->depth - m_layer_info->toolchanges_depth(): 0.f)) .append(";--------------------\n" "; CP TOOLCHANGE START\n") .comment_with_value(" toolchange #", m_num_tool_changes + 1); // the number is zero-based @@ -773,15 +762,11 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) if (last_change_in_layer) {// draw perimeter line writer.set_y_shift(m_y_shift); - if (m_peters_wipe_tower) - writer.rectangle(Vec2f::Zero(), m_layer_info->depth + 3*m_perimeter_width, m_wipe_tower_depth); - else { - writer.rectangle(Vec2f::Zero(), m_wipe_tower_width, m_layer_info->depth + m_perimeter_width); - if (layer_finished()) { // no finish_layer will be called, we must wipe the nozzle - writer.add_wipe_point(writer.x(), writer.y()) - .add_wipe_point(writer.x()> m_wipe_tower_width / 2.f ? 0.f : m_wipe_tower_width, writer.y()); + writer.rectangle(Vec2f::Zero(), m_wipe_tower_width, m_layer_info->depth + m_perimeter_width); + if (layer_finished()) { // no finish_layer will be called, we must wipe the nozzle + writer.add_wipe_point(writer.x(), writer.y()) + .add_wipe_point(writer.x()> m_wipe_tower_width / 2.f ? 0.f : m_wipe_tower_width, writer.y()); - } } } @@ -1141,7 +1126,7 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() writer.set_extrusion_flow(m_extrusion_flow) .set_z(m_z_pos) .set_initial_tool(m_current_tool) - .set_y_shift(m_y_shift - (m_current_shape == SHAPE_REVERSED && !m_peters_wipe_tower ? m_layer_info->toolchanges_depth() : 0.f)) + .set_y_shift(m_y_shift - (m_current_shape == SHAPE_REVERSED ? m_layer_info->toolchanges_depth() : 0.f)) .append(";--------------------\n" "; CP EMPTY GRID START\n") .comment_with_value(" layer #", m_num_layer_changes + 1); @@ -1174,7 +1159,7 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() if (m_is_first_layer && m_adhesion) { // Extrude a dense infill at the 1st layer to improve 1st layer adhesion of the wipe tower. box.expand(-m_perimeter_width/2.f); - int nsteps = int(floor((box.lu.y() - box.ld.y()) / (2*m_perimeter_width))); + int nsteps = int(std::floor((box.lu.y() - box.ld.y()) / (2*m_perimeter_width))); float step = (box.lu.y() - box.ld.y()) / nsteps; writer.travel(box.ld - Vec2f(m_perimeter_width/2.f, m_perimeter_width/2.f)); if (nsteps >= 0) @@ -1354,9 +1339,6 @@ void WipeTower::generate(std::vector> & plan_tower(); } - if (m_peters_wipe_tower) - make_wipe_tower_square(); - m_layer_info = m_plan.begin(); // we don't know which extruder to start with - we'll set it according to the first toolchange @@ -1376,12 +1358,9 @@ void WipeTower::generate(std::vector> & for (auto layer : m_plan) { set_layer(layer.z,layer.height,0,layer.z == m_plan.front().z,layer.z == m_plan.back().z); - if (m_peters_wipe_tower) - m_internal_rotation += 90.f; - else - m_internal_rotation += 180.f; + m_internal_rotation += 180.f; - if (!m_peters_wipe_tower && m_layer_info->depth < m_wipe_tower_depth - m_perimeter_width) + if (m_layer_info->depth < m_wipe_tower_depth - m_perimeter_width) m_y_shift = (m_wipe_tower_depth-m_layer_info->depth-m_perimeter_width)/2.f; for (const auto &toolchange : layer.tool_changes) @@ -1410,30 +1389,4 @@ void WipeTower::generate(std::vector> & } } -void WipeTower::make_wipe_tower_square() -{ - const float width = m_wipe_tower_width - 3 * m_perimeter_width; - const float depth = m_wipe_tower_depth - m_perimeter_width; - // area that we actually print into is width*depth - float side = sqrt(depth * width); - - m_wipe_tower_width = side + 3 * m_perimeter_width; - m_wipe_tower_depth = side + 2 * m_perimeter_width; - // For all layers, find how depth changed and update all toolchange depths - for (auto &lay : m_plan) - { - side = sqrt(lay.depth * width); - float width_ratio = width / side; - - //lay.extra_spacing = width_ratio; - for (auto &tch : lay.tool_changes) - tch.required_depth *= width_ratio; - } - - plan_tower(); // propagates depth downwards again (width has changed) - for (auto& lay : m_plan) // depths set, now the spacing - lay.extra_spacing = lay.depth / lay.toolchanges_depth(); -} - - } // namespace Slic3r diff --git a/src/libslic3r/GCode/WipeTower.hpp b/src/libslic3r/GCode/WipeTower.hpp index 5110a49cfe..4661f5f5ca 100644 --- a/src/libslic3r/GCode/WipeTower.hpp +++ b/src/libslic3r/GCode/WipeTower.hpp @@ -209,7 +209,6 @@ private: SHAPE_REVERSED = -1 }; - const bool m_peters_wipe_tower = false; // sparse wipe tower inspired by Peter's post processor - not finished yet const float Width_To_Nozzle_Ratio = 1.25f; // desired line width (oval) in multiples of nozzle diameter - may not be actually neccessary to adjust const float WT_EPSILON = 1e-3f; float filament_area() const { diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index e39fd8685e..b701897649 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1987,9 +1987,7 @@ void Print::_make_wipe_tower() // Set the extruder & material properties at the wipe tower object. for (size_t i = 0; i < number_of_extruders; ++ i) - - wipe_tower.set_extruder( - i, m_config); + wipe_tower.set_extruder(i, m_config); m_wipe_tower_data.priming = Slic3r::make_unique>( wipe_tower.prime((float)this->skirt_first_layer_height(), m_wipe_tower_data.tool_ordering.all_extruders(), false)); From 3ed68ac28a99225b27b1bd8ee805e3ea24fe47e6 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 22 Mar 2021 14:09:19 +0100 Subject: [PATCH 03/10] Wipe tower: slightly changed finish_layer logic so it can be called after any toolchange --- src/libslic3r/GCode/WipeTower.cpp | 33 ++++++++++++++++--------------- src/libslic3r/GCode/WipeTower.hpp | 7 ++++++- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 35e4e7091f..c155a96a58 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -717,10 +717,10 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) // Otherwise we are going to Unload only. And m_layer_info would be invalid. } - box_coordinates cleaning_box( + box_coordinates cleaning_box( Vec2f(m_perimeter_width / 2.f, m_perimeter_width / 2.f), m_wipe_tower_width - m_perimeter_width, - (tool != (unsigned int)(-1) ? /*m_layer_info->depth*/wipe_area+m_depth_traversed-0.5f*m_perimeter_width + (tool != (unsigned int)(-1) ? wipe_area+m_depth_traversed-0.5f*m_perimeter_width : m_wipe_tower_depth-m_perimeter_width)); WipeTowerWriter writer(m_layer_height, m_perimeter_width, m_gcode_flavor, m_filpar); @@ -760,7 +760,7 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) m_depth_traversed += wipe_area; - if (last_change_in_layer) {// draw perimeter line + /*if (last_change_in_layer) {// draw perimeter line writer.set_y_shift(m_y_shift); writer.rectangle(Vec2f::Zero(), m_wipe_tower_width, m_layer_info->depth + m_perimeter_width); if (layer_finished()) { // no finish_layer will be called, we must wipe the nozzle @@ -768,7 +768,7 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) .add_wipe_point(writer.x()> m_wipe_tower_width / 2.f ? 0.f : m_wipe_tower_width, writer.y()); } - } + }*/ if (m_set_extruder_trimpot) writer.set_extruder_trimpot(550); // Reset the extruder current to a normal value. @@ -1116,9 +1116,8 @@ void WipeTower::toolchange_Wipe( WipeTower::ToolChangeResult WipeTower::finish_layer() { - // This should only be called if the layer is not finished yet. - // Otherwise the caller would likely travel to the wipe tower in vain. assert(! this->layer_finished()); + m_current_layer_finished = true; size_t old_tool = m_current_tool; @@ -1134,8 +1133,8 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() // Slow down on the 1st layer. float speed_factor = m_is_first_layer ? 0.5f : 1.f; float current_depth = m_layer_info->depth - m_layer_info->toolchanges_depth(); - box_coordinates fill_box(Vec2f(m_perimeter_width, m_depth_traversed + m_perimeter_width), - m_wipe_tower_width - 2 * m_perimeter_width, current_depth-m_perimeter_width); + box_coordinates fill_box(Vec2f(m_perimeter_width, m_layer_info->depth-(current_depth-m_perimeter_width)), + m_wipe_tower_width - 2 * m_perimeter_width, current_depth-m_perimeter_width); writer.set_initial_position((m_left_to_right ? fill_box.ru : fill_box.lu), // so there is never a diagonal travel @@ -1143,14 +1142,15 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() bool toolchanges_on_layer = m_layer_info->toolchanges_depth() > WT_EPSILON; box_coordinates box = fill_box; - for (int i=0;i<2;++i) { - if (! toolchanges_on_layer) { - if (i==0) box.expand(m_perimeter_width); - else box.expand(-m_perimeter_width); - } - else i=2; // only draw the inner perimeter, outer has been already drawn by tool_change(...) + + // inner perimeter of the sparse section, if there is space for it: + if (fill_box.lu.y() - fill_box.ld.y() > m_perimeter_width) writer.rectangle(box.ld, box.rd.x()-box.ld.x(), box.ru.y()-box.rd.y(), 2900*speed_factor); - } + + // outer perimeter (always): + writer.rectangle(Vec2f(0.f, (m_current_shape == SHAPE_REVERSED ? m_layer_info->toolchanges_depth() : 0.f)), + m_wipe_tower_width, m_layer_info->depth + m_perimeter_width); + // we are in one of the corners, travel to ld along the perimeter: if (writer.x() > fill_box.ld.x()+EPSILON) writer.travel(fill_box.ld.x(),writer.y()); @@ -1311,7 +1311,8 @@ void WipeTower::save_on_last_wipe() tool_change(toolchange.new_tool); float width = m_wipe_tower_width - 3*m_perimeter_width; // width we draw into - float length_to_save = 2*(m_wipe_tower_width+m_wipe_tower_depth) + (!layer_finished() ? finish_layer().total_extrusion_length_in_plane() : 0.f); + //float length_to_save = 2*(m_wipe_tower_width+m_wipe_tower_depth) + (!layer_finished() ? finish_layer().total_extrusion_length_in_plane() : 0.f); + float length_to_save = finish_layer().total_extrusion_length_in_plane(); float length_to_wipe = volume_to_length(m_layer_info->tool_changes.back().wipe_volume, m_perimeter_width,m_layer_info->height) - m_layer_info->tool_changes.back().first_wipe_line - length_to_save; diff --git a/src/libslic3r/GCode/WipeTower.hpp b/src/libslic3r/GCode/WipeTower.hpp index 4661f5f5ca..e423aa3982 100644 --- a/src/libslic3r/GCode/WipeTower.hpp +++ b/src/libslic3r/GCode/WipeTower.hpp @@ -132,6 +132,7 @@ public: m_is_first_layer = is_first_layer; m_print_brim = is_first_layer; m_depth_traversed = 0.f; + m_current_layer_finished = false; m_current_shape = (! is_first_layer && m_current_shape == SHAPE_NORMAL) ? SHAPE_REVERSED : SHAPE_NORMAL; if (is_first_layer) { this->m_num_layer_changes = 0; @@ -175,7 +176,10 @@ public: // Is the current layer finished? bool layer_finished() const { - return ( (m_is_first_layer ? m_wipe_tower_depth - m_perimeter_width : m_layer_info->depth) - WT_EPSILON < m_depth_traversed); + return m_current_layer_finished;/*( (m_is_first_layer + ? m_wipe_tower_depth - m_perimeter_width + : m_layer_info->depth + ) < m_depth_traversed + WT_EPSILON);*/ } std::vector get_used_filament() const { return m_used_filament_length; } @@ -268,6 +272,7 @@ private: const std::vector> wipe_volumes; float m_depth_traversed = 0.f; // Current y position at the wipe tower. + bool m_current_layer_finished = false; bool m_left_to_right = true; float m_extra_spacing = 1.f; From f6de946dd72bd6de46612c20998ccf2b55d2a134 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 19 Mar 2021 15:26:55 +0100 Subject: [PATCH 04/10] Wipe tower: don't use soluble filament for perimeters, sparse infill or first layer --- src/libslic3r/GCode/WipeTower.cpp | 122 ++++++++++++++++++++---------- src/libslic3r/GCode/WipeTower.hpp | 5 ++ 2 files changed, 87 insertions(+), 40 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index c155a96a58..c5c7c0e308 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -1125,10 +1125,8 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() writer.set_extrusion_flow(m_extrusion_flow) .set_z(m_z_pos) .set_initial_tool(m_current_tool) - .set_y_shift(m_y_shift - (m_current_shape == SHAPE_REVERSED ? m_layer_info->toolchanges_depth() : 0.f)) - .append(";--------------------\n" - "; CP EMPTY GRID START\n") - .comment_with_value(" layer #", m_num_layer_changes + 1); + .set_y_shift(m_y_shift - (m_current_shape == SHAPE_REVERSED ? m_layer_info->toolchanges_depth() : 0.f)); + // Slow down on the 1st layer. float speed_factor = m_is_first_layer ? 0.5f : 1.f; @@ -1141,23 +1139,22 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() m_wipe_tower_width, m_wipe_tower_depth, m_internal_rotation); bool toolchanges_on_layer = m_layer_info->toolchanges_depth() > WT_EPSILON; - box_coordinates box = fill_box; // inner perimeter of the sparse section, if there is space for it: - if (fill_box.lu.y() - fill_box.ld.y() > m_perimeter_width) - writer.rectangle(box.ld, box.rd.x()-box.ld.x(), box.ru.y()-box.rd.y(), 2900*speed_factor); + if (fill_box.ru.y() - fill_box.rd.y() > m_perimeter_width - WT_EPSILON) + writer.rectangle(fill_box.ld, fill_box.rd.x()-fill_box.ld.x(), fill_box.ru.y()-fill_box.rd.y(), 2900*speed_factor); // outer perimeter (always): writer.rectangle(Vec2f(0.f, (m_current_shape == SHAPE_REVERSED ? m_layer_info->toolchanges_depth() : 0.f)), m_wipe_tower_width, m_layer_info->depth + m_perimeter_width); - // we are in one of the corners, travel to ld along the perimeter: if (writer.x() > fill_box.ld.x()+EPSILON) writer.travel(fill_box.ld.x(),writer.y()); if (writer.y() > fill_box.ld.y()+EPSILON) writer.travel(writer.x(),fill_box.ld.y()); if (m_is_first_layer && m_adhesion) { // Extrude a dense infill at the 1st layer to improve 1st layer adhesion of the wipe tower. + box_coordinates box = fill_box; box.expand(-m_perimeter_width/2.f); int nsteps = int(std::floor((box.lu.y() - box.ld.y()) / (2*m_perimeter_width))); float step = (box.lu.y() - box.ld.y()) / nsteps; @@ -1178,7 +1175,10 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() const float right = fill_box.ru.x() - 2 * m_perimeter_width; if (dy > m_perimeter_width) { - writer.travel(fill_box.ld + Vec2f(m_perimeter_width * 2, 0.f)); + writer.travel(fill_box.ld + Vec2f(m_perimeter_width * 2, 0.f)) + .append(";--------------------\n" + "; CP EMPTY GRID START\n") + .comment_with_value(" layer #", m_num_layer_changes + 1); // Is there a soluble filament wiped/rammed at the next layer? // If so, the infill should not be sparse. @@ -1219,16 +1219,15 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() writer.add_wipe_point(Vec2f(writer.x(), writer.y())) .add_wipe_point(Vec2f(left, writer.y())); } + + writer.append("; CP EMPTY GRID END\n" + ";------------------\n\n\n\n\n\n\n"); } else { writer.add_wipe_point(Vec2f(writer.x(), writer.y())) .add_wipe_point(Vec2f(right, writer.y())); } } - writer.append("; CP EMPTY GRID END\n" - ";------------------\n\n\n\n\n\n\n"); - - m_depth_traversed = m_wipe_tower_depth-m_perimeter_width; // Ask our writer about how much material was consumed. @@ -1307,23 +1306,60 @@ void WipeTower::save_on_last_wipe() if (m_layer_info->tool_changes.size()==0) // we have no way to save anything on an empty layer continue; - for (const auto &toolchange : m_layer_info->tool_changes) + // Which toolchange will finish_layer extrusions be subtracted from? + int idx = first_toolchange_to_nonsoluble(m_layer_info->tool_changes); + + for (int i=0; itool_changes.size()); ++i) { + auto& toolchange = m_layer_info->tool_changes[i]; tool_change(toolchange.new_tool); - float width = m_wipe_tower_width - 3*m_perimeter_width; // width we draw into - //float length_to_save = 2*(m_wipe_tower_width+m_wipe_tower_depth) + (!layer_finished() ? finish_layer().total_extrusion_length_in_plane() : 0.f); - float length_to_save = finish_layer().total_extrusion_length_in_plane(); - float length_to_wipe = volume_to_length(m_layer_info->tool_changes.back().wipe_volume, - m_perimeter_width,m_layer_info->height) - m_layer_info->tool_changes.back().first_wipe_line - length_to_save; + if (i == idx) { + float width = m_wipe_tower_width - 3*m_perimeter_width; // width we draw into + float length_to_save = finish_layer().total_extrusion_length_in_plane(); + float length_to_wipe = volume_to_length(toolchange.wipe_volume, + m_perimeter_width, m_layer_info->height) - toolchange.first_wipe_line - length_to_save; - length_to_wipe = std::max(length_to_wipe,0.f); - float depth_to_wipe = m_perimeter_width * (std::floor(length_to_wipe/width) + ( length_to_wipe > 0.f ? 1.f : 0.f ) ) * m_extra_spacing; + length_to_wipe = std::max(length_to_wipe,0.f); + float depth_to_wipe = m_perimeter_width * (std::floor(length_to_wipe/width) + ( length_to_wipe > 0.f ? 1.f : 0.f ) ) * m_extra_spacing; - //depth += (int(length_to_extrude / width) + 1) * m_perimeter_width; - m_layer_info->tool_changes.back().required_depth = m_layer_info->tool_changes.back().ramming_depth + depth_to_wipe; + toolchange.required_depth = toolchange.ramming_depth + depth_to_wipe; + } + } } } + +// Return index of first toolchange that switches to non-soluble extruder +// ot -1 if there is no such toolchange. +int WipeTower::first_toolchange_to_nonsoluble( + const std::vector& tool_changes) const +{ + for (size_t idx=0; idx> &result) @@ -1364,25 +1400,31 @@ void WipeTower::generate(std::vector> & if (m_layer_info->depth < m_wipe_tower_depth - m_perimeter_width) m_y_shift = (m_wipe_tower_depth-m_layer_info->depth-m_perimeter_width)/2.f; - for (const auto &toolchange : layer.tool_changes) - layer_result.emplace_back(tool_change(toolchange.new_tool)); + int idx = first_toolchange_to_nonsoluble(layer.tool_changes); + ToolChangeResult finish_layer_tcr; - if (! layer_finished()) { - auto finish_layer_toolchange = finish_layer(); - if ( ! layer.tool_changes.empty() ) { // we will merge it to the last toolchange - auto& last_toolchange = layer_result.back(); - if (last_toolchange.end_pos != finish_layer_toolchange.start_pos) { - char buf[2048]; // Add a travel move from tc1.end_pos to tc2.start_pos. - sprintf(buf, "G1 X%.3f Y%.3f F7200\n", finish_layer_toolchange.start_pos.x(), finish_layer_toolchange.start_pos.y()); - last_toolchange.gcode += buf; - } - last_toolchange.gcode += finish_layer_toolchange.gcode; - last_toolchange.extrusions.insert(last_toolchange.extrusions.end(), finish_layer_toolchange.extrusions.begin(), finish_layer_toolchange.extrusions.end()); - last_toolchange.end_pos = finish_layer_toolchange.end_pos; - last_toolchange.wipe_path = finish_layer_toolchange.wipe_path; - } + if (idx == -1) { + // if there is no toolchange switching to non-soluble, finish layer + // will be called at the very beginning. That's the last possibility + // where a nonsoluble tool can be. + finish_layer_tcr = finish_layer(); + } + + for (int i=0; i m_used_filament_length; + // Return index of first toolchange that switches to non-soluble extruder + // ot -1 if there is no such toolchange. + int first_toolchange_to_nonsoluble( + const std::vector& tool_changes) const; + // Returns gcode for wipe tower brim // sideOnly -- set to false -- experimental, draw brim on sides of wipe tower From a6ddab856bbde6c5790d1268ea315fbaa884816d Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 22 Mar 2021 14:13:53 +0100 Subject: [PATCH 05/10] Wipe tower: refactoring of brim and solid infill on first layer --- src/libslic3r/GCode.cpp | 6 +- src/libslic3r/GCode.hpp | 6 +- src/libslic3r/GCode/WipeTower.cpp | 277 +++++++++++------------------- src/libslic3r/GCode/WipeTower.hpp | 81 ++++----- src/libslic3r/Print.cpp | 4 +- 5 files changed, 145 insertions(+), 229 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index d7e72b4ade..0e464ee6d2 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -435,19 +435,18 @@ namespace Slic3r { { std::string gcode; assert(m_layer_idx >= 0); - if (!m_brim_done || gcodegen.writer().need_toolchange(extruder_id) || finish_layer) { + if (gcodegen.writer().need_toolchange(extruder_id) || finish_layer) { if (m_layer_idx < (int)m_tool_changes.size()) { if (!(size_t(m_tool_change_idx) < m_tool_changes[m_layer_idx].size())) throw Slic3r::RuntimeError("Wipe tower generation failed, possibly due to empty first layer."); - // Calculate where the wipe tower layer will be printed. -1 means that print z will not change, // resulting in a wipe tower with sparse layers. double wipe_tower_z = -1; bool ignore_sparse = false; if (gcodegen.config().wipe_tower_no_sparse_layers.value) { wipe_tower_z = m_last_wipe_tower_print_z; - ignore_sparse = (m_brim_done && m_tool_changes[m_layer_idx].size() == 1 && m_tool_changes[m_layer_idx].front().initial_tool == m_tool_changes[m_layer_idx].front().new_tool); + ignore_sparse = (m_tool_changes[m_layer_idx].size() == 1 && m_tool_changes[m_layer_idx].front().initial_tool == m_tool_changes[m_layer_idx].front().new_tool); if (m_tool_change_idx == 0 && !ignore_sparse) wipe_tower_z = m_last_wipe_tower_print_z + m_tool_changes[m_layer_idx].front().layer_height; } @@ -457,7 +456,6 @@ namespace Slic3r { m_last_wipe_tower_print_z = wipe_tower_z; } } - m_brim_done = true; } return gcode; } diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 9ecabd47df..08ab830024 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -75,8 +75,8 @@ public: m_tool_changes(tool_changes), m_final_purge(final_purge), m_layer_idx(-1), - m_tool_change_idx(0), - m_brim_done(false) {} + m_tool_change_idx(0) + {} std::string prime(GCode &gcodegen); void next_layer() { ++ m_layer_idx; m_tool_change_idx = 0; } @@ -105,8 +105,6 @@ private: // Current layer index. int m_layer_idx; int m_tool_change_idx; - bool m_brim_done; - bool i_have_brim = false; double m_last_wipe_tower_print_z = 0.f; }; diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index c5c7c0e308..8e7f003615 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -205,7 +205,7 @@ public: WipeTowerWriter& extrude(const Vec2f &dest, const float f = 0.f) { return extrude(dest.x(), dest.y(), f); } - + WipeTowerWriter& rectangle(const Vec2f& ld,float width,float height,const float f = 0.f) { Vec2f corners[4]; @@ -231,6 +231,14 @@ public: return (*this); } + WipeTowerWriter& rectangle(const WipeTower::box_coordinates& box, const float f = 0.f) + { + rectangle(Vec2f(box.ld.x(), box.ld.y()), + box.ru.x() - box.lu.x(), + box.ru.y() - box.rd.y(), f); + return (*this); + } + WipeTowerWriter& load(float e, float f = 0.f) { if (e == 0.f && (f == 0.f || f == m_current_feedrate)) @@ -512,7 +520,6 @@ WipeTower::WipeTower(const PrintConfig& config, const std::vector WipeTower::prime( m_old_temperature = -1; // If the priming is turned off in config, the temperature changing commands will not actually appear // in the output gcode - we should not remember emitting them (we will output them twice in the worst case) - // so that tool_change() will know to extrude the wipe tower brim: - m_print_brim = true; - return results; } WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) { - if ( m_print_brim ) - return toolchange_Brim(); - size_t old_tool = m_current_tool; + bool first_layer = m_layer_info == m_plan.begin(); - float wipe_area = 0.f; - bool last_change_in_layer = false; + float wipe_area = 0.f; float wipe_volume = 0.f; // Finds this toolchange info @@ -706,9 +707,7 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) { for (const auto &b : m_layer_info->tool_changes) if ( b.new_tool == tool ) { - wipe_volume = b.wipe_volume; - if (tool == m_layer_info->tool_changes.back().new_tool) - last_change_in_layer = true; + wipe_volume = b.wipe_volume; wipe_area = b.required_depth * m_layer_info->extra_spacing; break; } @@ -749,7 +748,7 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) // Ram the hot material out of the melt zone, retract the filament into the cooling tubes and let it cool. if (tool != (unsigned int)-1){ // This is not the last change. toolchange_Unload(writer, cleaning_box, m_filpar[m_current_tool].material, - m_is_first_layer ? m_filpar[tool].first_layer_temperature : m_filpar[tool].temperature); + first_layer ? m_filpar[tool].first_layer_temperature : m_filpar[tool].temperature); toolchange_Change(writer, tool, m_filpar[tool].material); // Change the tool, set a speed override for soluble and flex materials. toolchange_Load(writer, cleaning_box); writer.travel(writer.x(), writer.y()-m_perimeter_width); // cooling and loading were done a bit down the road @@ -760,16 +759,6 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) m_depth_traversed += wipe_area; - /*if (last_change_in_layer) {// draw perimeter line - writer.set_y_shift(m_y_shift); - writer.rectangle(Vec2f::Zero(), m_wipe_tower_width, m_layer_info->depth + m_perimeter_width); - if (layer_finished()) { // no finish_layer will be called, we must wipe the nozzle - writer.add_wipe_point(writer.x(), writer.y()) - .add_wipe_point(writer.x()> m_wipe_tower_width / 2.f ? 0.f : m_wipe_tower_width, writer.y()); - - } - }*/ - if (m_set_extruder_trimpot) writer.set_extruder_trimpot(550); // Reset the extruder current to a normal value. writer.speed_override_restore(); @@ -787,66 +776,6 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) return construct_tcr(writer, false, old_tool); } -WipeTower::ToolChangeResult WipeTower::toolchange_Brim(bool sideOnly, float y_offset) -{ - size_t old_tool = m_current_tool; - - const box_coordinates wipeTower_box( - Vec2f::Zero(), - m_wipe_tower_width, - m_wipe_tower_depth); - - WipeTowerWriter writer(m_layer_height, m_perimeter_width, m_gcode_flavor, m_filpar); - writer.set_extrusion_flow(m_extrusion_flow * 1.1f) - .set_z(m_z_pos) // Let the writer know the current Z position as a base for Z-hop. - .set_initial_tool(m_current_tool) - .append(";-------------------------------------\n" - "; CP WIPE TOWER FIRST LAYER BRIM START\n"); - - Vec2f initial_position = wipeTower_box.lu - Vec2f(m_wipe_tower_brim_width + 2*m_perimeter_width, 0); - writer.set_initial_position(initial_position, m_wipe_tower_width, m_wipe_tower_depth, m_internal_rotation); - - // Prime the extruder left of the wipe tower. - writer.extrude_explicit(wipeTower_box.ld - Vec2f(m_wipe_tower_brim_width + 2*m_perimeter_width, 0), - 1.5f * m_extrusion_flow * (wipeTower_box.lu.y() - wipeTower_box.ld.y()), 2400); - - // The tool is supposed to be active and primed at the time when the wipe tower brim is extruded. - // Extrude brim around the future wipe tower ('normal' spacing with no extra void space). - box_coordinates box(wipeTower_box); - float spacing = m_perimeter_width - m_layer_height*float(1.-M_PI_4); - - // How many perimeters shall the brim have? - size_t loops_num = (m_wipe_tower_brim_width + spacing/2.f) / spacing; - - for (size_t i = 0; i < loops_num; ++ i) { - box.expand(spacing); - writer.travel (box.ld, 7000) - .extrude(box.lu, 2100).extrude(box.ru) - .extrude(box.rd ).extrude(box.ld); - } - - // Save actual brim width to be later passed to the Print object, which will use it - // for skirt calculation and pass it to GLCanvas for precise preview box - m_wipe_tower_brim_width_real = wipeTower_box.ld.x() - box.ld.x() + spacing/2.f; - - box.expand(-spacing); - writer.add_wipe_point(writer.x(), writer.y()) - .add_wipe_point(box.ld) - .add_wipe_point(box.rd); - - writer.append("; CP WIPE TOWER FIRST LAYER BRIM END\n" - ";-----------------------------------\n"); - - m_print_brim = false; // Mark the brim as extruded - - // Ask our writer about how much material was consumed: - if (m_current_tool < m_used_filament_length.size()) - m_used_filament_length[m_current_tool] += writer.get_and_reset_used_filament_length(); - - return construct_tcr(writer, false, old_tool); -} - - // Ram the hot material out of the melt zone, retract the filament into the cooling tubes and let it cool. void WipeTower::toolchange_Unload( @@ -855,6 +784,7 @@ void WipeTower::toolchange_Unload( const std::string& current_material, const int new_temperature) { + bool first_layer = m_layer_info == m_plan.begin(); float xl = cleaning_box.ld.x() + 1.f * m_perimeter_width; float xr = cleaning_box.rd.x() - 1.f * m_perimeter_width; @@ -943,7 +873,7 @@ void WipeTower::toolchange_Unload( // be already set and there is no need to change anything. Also, the temperature could be changed // for wrong extruder. if (m_semm) { - if (new_temperature != 0 && (new_temperature != m_old_temperature || m_is_first_layer) ) { // Set the extruder temperature, but don't wait. + if (new_temperature != 0 && (new_temperature != m_old_temperature || first_layer) ) { // Set the extruder temperature, but don't wait. // If the required temperature is the same as last time, don't emit the M104 again (if user adjusted the value, it would be reset) // However, always change temperatures on the first layer (this is to avoid issues with priming lines turned off). writer.set_extruder_temp(new_temperature, false); @@ -1049,9 +979,10 @@ void WipeTower::toolchange_Wipe( float wipe_volume) { // Increase flow on first layer, slow down print. - writer.set_extrusion_flow(m_extrusion_flow * (m_is_first_layer ? 1.18f : 1.f)) + bool first_layer = m_layer_info == m_plan.begin(); + writer.set_extrusion_flow(m_extrusion_flow * (first_layer ? 1.18f : 1.f)) .append("; CP TOOLCHANGE WIPE\n"); - float wipe_coeff = m_is_first_layer ? 0.5f : 1.f; + float wipe_coeff = first_layer ? 0.5f : 1.f; const float& xl = cleaning_box.ld.x(); const float& xr = cleaning_box.rd.x(); @@ -1129,7 +1060,8 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() // Slow down on the 1st layer. - float speed_factor = m_is_first_layer ? 0.5f : 1.f; + bool first_layer = m_layer_info == m_plan.begin(); + float speed_factor = first_layer ? 0.5f : 1.f; float current_depth = m_layer_info->depth - m_layer_info->toolchanges_depth(); box_coordinates fill_box(Vec2f(m_perimeter_width, m_layer_info->depth-(current_depth-m_perimeter_width)), m_wipe_tower_width - 2 * m_perimeter_width, current_depth-m_perimeter_width); @@ -1139,96 +1071,103 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() m_wipe_tower_width, m_wipe_tower_depth, m_internal_rotation); bool toolchanges_on_layer = m_layer_info->toolchanges_depth() > WT_EPSILON; + box_coordinates wipeTower_box(Vec2f(0.f, (m_current_shape == SHAPE_REVERSED ? m_layer_info->toolchanges_depth() : 0.f)), + m_wipe_tower_width, m_layer_info->depth + m_perimeter_width); // inner perimeter of the sparse section, if there is space for it: if (fill_box.ru.y() - fill_box.rd.y() > m_perimeter_width - WT_EPSILON) writer.rectangle(fill_box.ld, fill_box.rd.x()-fill_box.ld.x(), fill_box.ru.y()-fill_box.rd.y(), 2900*speed_factor); - // outer perimeter (always): - writer.rectangle(Vec2f(0.f, (m_current_shape == SHAPE_REVERSED ? m_layer_info->toolchanges_depth() : 0.f)), - m_wipe_tower_width, m_layer_info->depth + m_perimeter_width); - // we are in one of the corners, travel to ld along the perimeter: if (writer.x() > fill_box.ld.x()+EPSILON) writer.travel(fill_box.ld.x(),writer.y()); if (writer.y() > fill_box.ld.y()+EPSILON) writer.travel(writer.x(),fill_box.ld.y()); - if (m_is_first_layer && m_adhesion) { - // Extrude a dense infill at the 1st layer to improve 1st layer adhesion of the wipe tower. - box_coordinates box = fill_box; - box.expand(-m_perimeter_width/2.f); - int nsteps = int(std::floor((box.lu.y() - box.ld.y()) / (2*m_perimeter_width))); - float step = (box.lu.y() - box.ld.y()) / nsteps; - writer.travel(box.ld - Vec2f(m_perimeter_width/2.f, m_perimeter_width/2.f)); - if (nsteps >= 0) - for (int i = 0; i < nsteps; ++i) { - writer.extrude(box.ld.x()+m_perimeter_width/2.f, writer.y() + 0.5f * step); - writer.extrude(box.rd.x() - m_perimeter_width / 2.f, writer.y()); - writer.extrude(box.rd.x() - m_perimeter_width / 2.f, writer.y() + 0.5f * step); - writer.extrude(box.ld.x() + m_perimeter_width / 2.f, writer.y()); + // Extrude infill to support the material to be printed above. + const float dy = (fill_box.lu.y() - fill_box.ld.y() - m_perimeter_width); + float left = fill_box.lu.x() + 2*m_perimeter_width; + float right = fill_box.ru.x() - 2 * m_perimeter_width; + if (dy > m_perimeter_width) + { + writer.travel(fill_box.ld + Vec2f(m_perimeter_width * 2, 0.f)) + .append(";--------------------\n" + "; CP EMPTY GRID START\n") + .comment_with_value(" layer #", m_num_layer_changes + 1); + + // Is there a soluble filament wiped/rammed at the next layer? + // If so, the infill should not be sparse. + bool solid_infill = m_layer_info+1 == m_plan.end() + ? false + : std::any_of((m_layer_info+1)->tool_changes.begin(), + (m_layer_info+1)->tool_changes.end(), + [this](const WipeTowerInfo::ToolChange& tch) { + return m_filpar[tch.new_tool].is_soluble + || m_filpar[tch.old_tool].is_soluble; + }); + solid_infill |= first_layer && m_adhesion; + + if (solid_infill) { + float sparse_factor = 1.5f; // 1=solid, 2=every other line, etc. + if (first_layer) { // the infill should touch perimeters + left -= m_perimeter_width; + right += m_perimeter_width; + sparse_factor = 1.f; } - writer.add_wipe_point(writer.x(), writer.y()) - .add_wipe_point(box.rd.x()-m_perimeter_width/2.f,writer.y()); - } - else { // Extrude a sparse infill to support the material to be printed above. - const float dy = (fill_box.lu.y() - fill_box.ld.y() - m_perimeter_width); - const float left = fill_box.lu.x() + 2*m_perimeter_width; - const float right = fill_box.ru.x() - 2 * m_perimeter_width; - if (dy > m_perimeter_width) - { - writer.travel(fill_box.ld + Vec2f(m_perimeter_width * 2, 0.f)) - .append(";--------------------\n" - "; CP EMPTY GRID START\n") - .comment_with_value(" layer #", m_num_layer_changes + 1); - - // Is there a soluble filament wiped/rammed at the next layer? - // If so, the infill should not be sparse. - bool solid_infill = m_layer_info+1 == m_plan.end() - ? false - : std::any_of((m_layer_info+1)->tool_changes.begin(), - (m_layer_info+1)->tool_changes.end(), - [this](const WipeTowerInfo::ToolChange& tch) { - return m_filpar[tch.new_tool].is_soluble - || m_filpar[tch.old_tool].is_soluble; - }); - - if (solid_infill) { - const float sparse_factor = 1.5f; // 1=solid, 2=every other line, etc. - float y = fill_box.ld.y() + m_perimeter_width; - int n = dy / (m_perimeter_width * sparse_factor); - float spacing = (dy-m_perimeter_width)/(n-1); - int i = 0; - for (i=0; i> &result) { if (m_plan.empty()) - return; m_extra_spacing = 1.f; @@ -1394,7 +1328,7 @@ void WipeTower::generate(std::vector> & std::vector layer_result; for (auto layer : m_plan) { - set_layer(layer.z,layer.height,0,layer.z == m_plan.front().z,layer.z == m_plan.back().z); + set_layer(layer.z, layer.height, 0, false/*layer.z == m_plan.front().z*/, layer.z == m_plan.back().z); m_internal_rotation += 180.f; if (m_layer_info->depth < m_wipe_tower_depth - m_perimeter_width) @@ -1428,7 +1362,6 @@ void WipeTower::generate(std::vector> & } result.emplace_back(std::move(layer_result)); - m_is_first_layer = false; } } diff --git a/src/libslic3r/GCode/WipeTower.hpp b/src/libslic3r/GCode/WipeTower.hpp index 4fec64b333..cfd3a9e116 100644 --- a/src/libslic3r/GCode/WipeTower.hpp +++ b/src/libslic3r/GCode/WipeTower.hpp @@ -84,6 +84,37 @@ public: } }; + struct box_coordinates + { + box_coordinates(float left, float bottom, float width, float height) : + ld(left , bottom ), + lu(left , bottom + height), + rd(left + width, bottom ), + ru(left + width, bottom + height) {} + box_coordinates(const Vec2f &pos, float width, float height) : box_coordinates(pos(0), pos(1), width, height) {} + void translate(const Vec2f &shift) { + ld += shift; lu += shift; + rd += shift; ru += shift; + } + void translate(const float dx, const float dy) { translate(Vec2f(dx, dy)); } + void expand(const float offset) { + ld += Vec2f(- offset, - offset); + lu += Vec2f(- offset, offset); + rd += Vec2f( offset, - offset); + ru += Vec2f( offset, offset); + } + void expand(const float offset_x, const float offset_y) { + ld += Vec2f(- offset_x, - offset_y); + lu += Vec2f(- offset_x, offset_y); + rd += Vec2f( offset_x, - offset_y); + ru += Vec2f( offset_x, offset_y); + } + Vec2f ld; // left down + Vec2f lu; // left upper + Vec2f rd; // right lower + Vec2f ru; // right upper + }; + // Construct ToolChangeResult from current state of WipeTower and WipeTowerWriter. // WipeTowerWriter is moved from ! ToolChangeResult construct_tcr(WipeTowerWriter& writer, @@ -102,7 +133,7 @@ public: // Appends into internal structure m_plan containing info about the future wipe tower // to be used before building begins. The entries must be added ordered in z. - void plan_toolchange(float z_par, float layer_height_par, unsigned int old_tool, unsigned int new_tool, bool brim, float wipe_volume = 0.f); + void plan_toolchange(float z_par, float layer_height_par, unsigned int old_tool, unsigned int new_tool, float wipe_volume = 0.f); // Iterates through prepared m_plan, generates ToolChangeResults and appends them to "result" void generate(std::vector> &result); @@ -129,8 +160,6 @@ public: { m_z_pos = print_z; m_layer_height = layer_height; - m_is_first_layer = is_first_layer; - m_print_brim = is_first_layer; m_depth_traversed = 0.f; m_current_layer_finished = false; m_current_shape = (! is_first_layer && m_current_shape == SHAPE_NORMAL) ? SHAPE_REVERSED : SHAPE_NORMAL; @@ -176,10 +205,7 @@ public: // Is the current layer finished? bool layer_finished() const { - return m_current_layer_finished;/*( (m_is_first_layer - ? m_wipe_tower_depth - m_perimeter_width - : m_layer_info->depth - ) < m_depth_traversed + WT_EPSILON);*/ + return m_current_layer_finished; } std::vector get_used_filament() const { return m_used_filament_length; } @@ -232,7 +258,6 @@ private: float m_z_pos = 0.f; // Current Z position. float m_layer_height = 0.f; // Current layer height. size_t m_max_color_changes = 0; // Maximum number of color changes per layer. - bool m_is_first_layer = false;// Is this the 1st layer of the print? If so, print the brim around the waste tower. int m_old_temperature = -1; // To keep track of what was the last temp that we set (so we don't issue the command when not neccessary) // G-code generator parameters. @@ -299,39 +324,7 @@ private: void save_on_last_wipe(); - struct box_coordinates - { - box_coordinates(float left, float bottom, float width, float height) : - ld(left , bottom ), - lu(left , bottom + height), - rd(left + width, bottom ), - ru(left + width, bottom + height) {} - box_coordinates(const Vec2f &pos, float width, float height) : box_coordinates(pos(0), pos(1), width, height) {} - void translate(const Vec2f &shift) { - ld += shift; lu += shift; - rd += shift; ru += shift; - } - void translate(const float dx, const float dy) { translate(Vec2f(dx, dy)); } - void expand(const float offset) { - ld += Vec2f(- offset, - offset); - lu += Vec2f(- offset, offset); - rd += Vec2f( offset, - offset); - ru += Vec2f( offset, offset); - } - void expand(const float offset_x, const float offset_y) { - ld += Vec2f(- offset_x, - offset_y); - lu += Vec2f(- offset_x, offset_y); - rd += Vec2f( offset_x, - offset_y); - ru += Vec2f( offset_x, offset_y); - } - Vec2f ld; // left down - Vec2f lu; // left upper - Vec2f rd; // right lower - Vec2f ru; // right upper - }; - - - // to store information about tool changes for a given layer + // to store information about tool changes for a given layer struct WipeTowerInfo{ struct ToolChange { size_t old_tool; @@ -366,12 +359,6 @@ private: int first_toolchange_to_nonsoluble( const std::vector& tool_changes) const; - - // Returns gcode for wipe tower brim - // sideOnly -- set to false -- experimental, draw brim on sides of wipe tower - // offset -- set to 0 -- experimental, offset to replace brim in front / rear of wipe tower - ToolChangeResult toolchange_Brim(bool sideOnly = false, float y_offset = 0.f); - void toolchange_Unload( WipeTowerWriter &writer, const box_coordinates &cleaning_box, diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index b701897649..975d40208c 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -2013,8 +2013,8 @@ void Print::_make_wipe_tower() volume_to_wipe += (float)m_config.filament_minimal_purge_on_wipe_tower.get_at(extruder_id); // request a toolchange at the wipe tower with at least volume_to_wipe purging amount - wipe_tower.plan_toolchange((float)layer_tools.print_z, (float)layer_tools.wipe_tower_layer_height, current_extruder_id, extruder_id, - first_layer && extruder_id == m_wipe_tower_data.tool_ordering.all_extruders().back(), volume_to_wipe); + wipe_tower.plan_toolchange((float)layer_tools.print_z, (float)layer_tools.wipe_tower_layer_height, + current_extruder_id, extruder_id, volume_to_wipe); current_extruder_id = extruder_id; } } From 67bc2e472f1348e0364bd65a70aaa619a02e2229 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 22 Mar 2021 09:23:46 +0100 Subject: [PATCH 06/10] Wipe tower: fix wipe moves after recent changes --- src/libslic3r/GCode/WipeTower.cpp | 47 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 8e7f003615..b0bc50aeeb 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -1029,17 +1029,16 @@ void WipeTower::toolchange_Wipe( m_left_to_right = !m_left_to_right; } - // this is neither priming nor not the last toolchange on this layer - we are - // going back to the model - wipe the nozzle. - if (m_layer_info != m_plan.end() && m_current_tool != m_layer_info->tool_changes.back().new_tool) { + // We may be going back to the model - wipe the nozzle. If this is followed + // by finish_layer, this wipe path will be overwritten. + writer.add_wipe_point(writer.x(), writer.y()) + .add_wipe_point(writer.x(), writer.y() - dy) + .add_wipe_point(! m_left_to_right ? m_wipe_tower_width : 0.f, writer.y() - dy); + + if (m_layer_info != m_plan.end() && m_current_tool != m_layer_info->tool_changes.back().new_tool) m_left_to_right = !m_left_to_right; - writer.add_wipe_point(writer.x(), writer.y()) - .add_wipe_point(writer.x(), writer.y() - dy) - .add_wipe_point(m_left_to_right ? m_wipe_tower_width : 0.f, writer.y() - dy); - } - - writer.set_extrusion_flow(m_extrusion_flow); // Reset the extrusion flow. + writer.set_extrusion_flow(m_extrusion_flow); // Reset the extrusion flow. } @@ -1071,7 +1070,7 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() m_wipe_tower_width, m_wipe_tower_depth, m_internal_rotation); bool toolchanges_on_layer = m_layer_info->toolchanges_depth() > WT_EPSILON; - box_coordinates wipeTower_box(Vec2f(0.f, (m_current_shape == SHAPE_REVERSED ? m_layer_info->toolchanges_depth() : 0.f)), + box_coordinates wt_box(Vec2f(0.f, (m_current_shape == SHAPE_REVERSED ? m_layer_info->toolchanges_depth() : 0.f)), m_wipe_tower_width, m_layer_info->depth + m_perimeter_width); // inner perimeter of the sparse section, if there is space for it: @@ -1121,9 +1120,7 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() .extrude(i%2 ? left : right, y); y = y + spacing; } - writer.extrude(writer.x(), fill_box.lu.y()) - .add_wipe_point(Vec2f(writer.x(), writer.y())) - .add_wipe_point(Vec2f(i%2 ? left : right, writer.y())); + writer.extrude(writer.x(), fill_box.lu.y()); } else { // Extrude an inverse U at the left of the region and the sparse infill. writer.extrude(fill_box.lu + Vec2f(m_perimeter_width * 2, 0.f), 2900 * speed_factor); @@ -1135,26 +1132,18 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() writer.travel(x,writer.y()); writer.extrude(x,i%2 ? fill_box.rd.y() : fill_box.ru.y()); } - writer.add_wipe_point(Vec2f(writer.x(), writer.y())) - .add_wipe_point(Vec2f(left, writer.y())); } writer.append("; CP EMPTY GRID END\n" ";------------------\n\n\n\n\n\n\n"); } - else { - writer.add_wipe_point(Vec2f(writer.x(), writer.y())) - .add_wipe_point(Vec2f(right, writer.y())); - } - // TODO: - wipe path je potřeba nastavit níž - // - kouknout na wipe_tower_error.3mf // outer perimeter (always): - writer.rectangle(wipeTower_box); + writer.rectangle(wt_box); // brim (first layer only) if (first_layer) { - box_coordinates box = wipeTower_box; + box_coordinates box = wt_box; float spacing = m_perimeter_width - m_layer_height*float(1.-M_PI_4); // How many perimeters shall the brim have? size_t loops_num = (m_wipe_tower_brim_width + spacing/2.f) / spacing; @@ -1166,9 +1155,19 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() // Save actual brim width to be later passed to the Print object, which will use it // for skirt calculation and pass it to GLCanvas for precise preview box - m_wipe_tower_brim_width_real = wipeTower_box.ld.x() - box.ld.x() + spacing/2.f; + m_wipe_tower_brim_width_real = wt_box.ld.x() - box.ld.x() + spacing/2.f; + wt_box = box; } + // Now prepare future wipe. box contains rectangle that was extruded last (ccw). + Vec2f target = (writer.pos() == wt_box.ld ? wt_box.rd : + (writer.pos() == wt_box.rd ? wt_box.ru : + (writer.pos() == wt_box.ru ? wt_box.lu : + wt_box.ld))); + writer.add_wipe_point(writer.pos()) + .add_wipe_point(target); + + // Ask our writer about how much material was consumed. // Skip this in case the layer is sparse and config option to not print sparse layers is enabled. if (! m_no_sparse_layers || toolchanges_on_layer) From 345923111189501bb2f54921eb0c75996299a817 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 22 Mar 2021 14:07:28 +0100 Subject: [PATCH 07/10] Wipe tower: set travel feedrate for a move from custom toolchange position to the wipe tower (#5483) --- src/libslic3r/GCode/WipeTower.cpp | 18 ++++++++++++++---- src/libslic3r/GCode/WipeTower.hpp | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index b0bc50aeeb..81b87f7150 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -111,8 +111,10 @@ public: WipeTowerWriter& feedrate(float f) { - if (f != m_current_feedrate) + if (f != m_current_feedrate) { m_gcode += "G1" + set_format_F(f) + "\n"; + m_current_feedrate = f; + } return *this; } @@ -523,9 +525,14 @@ WipeTower::WipeTower(const PrintConfig& config, const std::vector WipeTower::prime( if (m_set_extruder_trimpot) writer.set_extruder_trimpot(550); writer.speed_override_restore() - .feedrate(6000) + .feedrate(m_travel_speed * 60.f) .flush_planner_queue() .reset_extruder() .append("; CP PRIMING END\n" @@ -762,7 +769,7 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) if (m_set_extruder_trimpot) writer.set_extruder_trimpot(550); // Reset the extruder current to a normal value. writer.speed_override_restore(); - writer.feedrate(6000) + writer.feedrate(m_travel_speed * 60.f) .flush_planner_queue() .reset_extruder() .append("; CP TOOLCHANGE END\n" @@ -933,7 +940,10 @@ void WipeTower::toolchange_Change( // gcode could have left the extruder somewhere, we cannot just start extruding. We should also inform the // postprocessor that we absolutely want to have this in the gcode, even if it thought it is the same as before. Vec2f current_pos = writer.pos_rotated(); - writer.append(std::string("G1 X") + std::to_string(current_pos.x()) + " Y" + std::to_string(current_pos.y()) + never_skip_tag() + "\n"); + writer.feedrate(m_travel_speed * 60.f) // see https://github.com/prusa3d/PrusaSlicer/issues/5483 + .append(std::string("G1 X") + std::to_string(current_pos.x()) + + " Y" + std::to_string(current_pos.y()) + + never_skip_tag() + "\n"); // The toolchange Tn command will be inserted later, only in case that the user does // not provide a custom toolchange gcode. diff --git a/src/libslic3r/GCode/WipeTower.hpp b/src/libslic3r/GCode/WipeTower.hpp index cfd3a9e116..fd9fbe57b2 100644 --- a/src/libslic3r/GCode/WipeTower.hpp +++ b/src/libslic3r/GCode/WipeTower.hpp @@ -259,6 +259,8 @@ private: float m_layer_height = 0.f; // Current layer height. size_t m_max_color_changes = 0; // Maximum number of color changes per layer. int m_old_temperature = -1; // To keep track of what was the last temp that we set (so we don't issue the command when not neccessary) + float m_travel_speed = 0.f; + float m_first_layer_speed = 0.f; // G-code generator parameters. float m_cooling_tube_retraction = 0.f; @@ -383,6 +385,6 @@ private: -}; // namespace Slic3r +} // namespace Slic3r #endif // WipeTowerPrusaMM_hpp_ From 5d636ab853aab0fa587a667d24ad8bf81ff44807 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 22 Mar 2021 13:26:05 +0100 Subject: [PATCH 08/10] Wipe tower: respect first_layer_speed --- src/libslic3r/GCode/WipeTower.cpp | 35 ++++++++++++++++++------------- src/libslic3r/Print.cpp | 4 ++-- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 81b87f7150..8b321a3c8d 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -526,12 +526,16 @@ WipeTower::WipeTower(const PrintConfig& config, const std::vector cleaning_box.lu.y()-0.5f*m_perimeter_width) break; // in case next line would not fit @@ -1070,7 +1075,7 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() // Slow down on the 1st layer. bool first_layer = m_layer_info == m_plan.begin(); - float speed_factor = first_layer ? 0.5f : 1.f; + float feedrate = first_layer ? m_first_layer_speed * 60.f : 2900.f; float current_depth = m_layer_info->depth - m_layer_info->toolchanges_depth(); box_coordinates fill_box(Vec2f(m_perimeter_width, m_layer_info->depth-(current_depth-m_perimeter_width)), m_wipe_tower_width - 2 * m_perimeter_width, current_depth-m_perimeter_width); @@ -1085,7 +1090,7 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() // inner perimeter of the sparse section, if there is space for it: if (fill_box.ru.y() - fill_box.rd.y() > m_perimeter_width - WT_EPSILON) - writer.rectangle(fill_box.ld, fill_box.rd.x()-fill_box.ld.x(), fill_box.ru.y()-fill_box.rd.y(), 2900*speed_factor); + writer.rectangle(fill_box.ld, fill_box.rd.x()-fill_box.ld.x(), fill_box.ru.y()-fill_box.rd.y(), feedrate); // we are in one of the corners, travel to ld along the perimeter: if (writer.x() > fill_box.ld.x()+EPSILON) writer.travel(fill_box.ld.x(),writer.y()); @@ -1126,14 +1131,14 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() float spacing = (dy-m_perimeter_width)/(n-1); int i=0; for (i=0; i Date: Wed, 24 Mar 2021 09:37:39 +0100 Subject: [PATCH 09/10] Wipe tower: reorder extruders so first layer starts with soluble if possible That way it will not be wiped on first layer --- src/libslic3r/GCode/ToolOrdering.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libslic3r/GCode/ToolOrdering.cpp b/src/libslic3r/GCode/ToolOrdering.cpp index 8520cf35bd..c45e260158 100644 --- a/src/libslic3r/GCode/ToolOrdering.cpp +++ b/src/libslic3r/GCode/ToolOrdering.cpp @@ -329,6 +329,16 @@ void ToolOrdering::reorder_extruders(unsigned int last_extruder_id) lt.extruders.front() = last_extruder_id; break; } + + // On first layer with wipe tower, prefer a soluble extruder + // at the beginning, so it is not wiped on the first layer. + if (lt == m_layer_tools[0] && m_print_config_ptr && m_print_config_ptr->wipe_tower) { + for (size_t i = 0; ifilament_soluble.get_at(lt.extruders[i]-1)) { // 1-based... + std::swap(lt.extruders[i], lt.extruders.front()); + break; + } + } } last_extruder_id = lt.extruders.back(); } From 58a811a638a524e3678ffa6870636e7239ab7ea0 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 5 Apr 2021 23:37:25 +0200 Subject: [PATCH 10/10] Wipe tower: correctly detect first layer even with 'No sparse layers' option enabled --- src/libslic3r/GCode/WipeTower.cpp | 22 +++++++++++----------- src/libslic3r/GCode/WipeTower.hpp | 3 +++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 8b321a3c8d..8f104eab6d 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -708,7 +708,6 @@ std::vector WipeTower::prime( WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) { size_t old_tool = m_current_tool; - bool first_layer = m_layer_info == m_plan.begin(); float wipe_area = 0.f; float wipe_volume = 0.f; @@ -759,7 +758,7 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) // Ram the hot material out of the melt zone, retract the filament into the cooling tubes and let it cool. if (tool != (unsigned int)-1){ // This is not the last change. toolchange_Unload(writer, cleaning_box, m_filpar[m_current_tool].material, - first_layer ? m_filpar[tool].first_layer_temperature : m_filpar[tool].temperature); + is_first_layer() ? m_filpar[tool].first_layer_temperature : m_filpar[tool].temperature); toolchange_Change(writer, tool, m_filpar[tool].material); // Change the tool, set a speed override for soluble and flex materials. toolchange_Load(writer, cleaning_box); writer.travel(writer.x(), writer.y()-m_perimeter_width); // cooling and loading were done a bit down the road @@ -795,7 +794,6 @@ void WipeTower::toolchange_Unload( const std::string& current_material, const int new_temperature) { - bool first_layer = m_layer_info == m_plan.begin(); float xl = cleaning_box.ld.x() + 1.f * m_perimeter_width; float xr = cleaning_box.rd.x() - 1.f * m_perimeter_width; @@ -884,7 +882,7 @@ void WipeTower::toolchange_Unload( // be already set and there is no need to change anything. Also, the temperature could be changed // for wrong extruder. if (m_semm) { - if (new_temperature != 0 && (new_temperature != m_old_temperature || first_layer) ) { // Set the extruder temperature, but don't wait. + if (new_temperature != 0 && (new_temperature != m_old_temperature || is_first_layer()) ) { // Set the extruder temperature, but don't wait. // If the required temperature is the same as last time, don't emit the M104 again (if user adjusted the value, it would be reset) // However, always change temperatures on the first layer (this is to avoid issues with priming lines turned off). writer.set_extruder_temp(new_temperature, false); @@ -993,8 +991,7 @@ void WipeTower::toolchange_Wipe( float wipe_volume) { // Increase flow on first layer, slow down print. - bool first_layer = m_layer_info == m_plan.begin(); - writer.set_extrusion_flow(m_extrusion_flow * (first_layer ? 1.18f : 1.f)) + writer.set_extrusion_flow(m_extrusion_flow * (is_first_layer() ? 1.18f : 1.f)) .append("; CP TOOLCHANGE WIPE\n"); const float& xl = cleaning_box.ld.x(); const float& xr = cleaning_box.rd.x(); @@ -1006,7 +1003,7 @@ void WipeTower::toolchange_Wipe( float x_to_wipe = volume_to_length(wipe_volume, m_perimeter_width, m_layer_height); float dy = m_extra_spacing*m_perimeter_width; - const float target_speed = first_layer ? m_first_layer_speed * 60.f : 4800.f; + const float target_speed = is_first_layer() ? m_first_layer_speed * 60.f : 4800.f; float wipe_speed = 0.33f * target_speed; // if there is less than 2.5*m_perimeter_width to the edge, advance straightaway (there is likely a blob anyway) @@ -1074,7 +1071,7 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() // Slow down on the 1st layer. - bool first_layer = m_layer_info == m_plan.begin(); + bool first_layer = is_first_layer(); float feedrate = first_layer ? m_first_layer_speed * 60.f : 2900.f; float current_depth = m_layer_info->depth - m_layer_info->toolchanges_depth(); box_coordinates fill_box(Vec2f(m_perimeter_width, m_layer_info->depth-(current_depth-m_perimeter_width)), @@ -1201,11 +1198,14 @@ void WipeTower::plan_toolchange(float z_par, float layer_height_par, unsigned in if (m_plan.empty() || m_plan.back().z + WT_EPSILON < z_par) // if we moved to a new layer, we'll add it to m_plan first m_plan.push_back(WipeTowerInfo(z_par, layer_height_par)); - if (old_tool==new_tool) // new layer without toolchanges - we are done - return; + if (m_first_layer_idx == size_t(-1) && (! m_no_sparse_layers || old_tool != new_tool)) + m_first_layer_idx = m_plan.size() - 1; + + if (old_tool == new_tool) // new layer without toolchanges - we are done + return; // this is an actual toolchange - let's calculate depth to reserve on the wipe tower - float depth = 0.f; + float depth = 0.f; float width = m_wipe_tower_width - 3*m_perimeter_width; float length_to_extrude = volume_to_length(0.25f * std::accumulate(m_filpar[old_tool].ramming_speed.begin(), m_filpar[old_tool].ramming_speed.end(), 0.f), m_perimeter_width * m_filpar[old_tool].ramming_line_width_multiplicator, diff --git a/src/libslic3r/GCode/WipeTower.hpp b/src/libslic3r/GCode/WipeTower.hpp index fd9fbe57b2..c3b2770b70 100644 --- a/src/libslic3r/GCode/WipeTower.hpp +++ b/src/libslic3r/GCode/WipeTower.hpp @@ -261,6 +261,7 @@ private: int m_old_temperature = -1; // To keep track of what was the last temp that we set (so we don't issue the command when not neccessary) float m_travel_speed = 0.f; float m_first_layer_speed = 0.f; + size_t m_first_layer_idx = size_t(-1); // G-code generator parameters. float m_cooling_tube_retraction = 0.f; @@ -303,6 +304,8 @@ private: bool m_left_to_right = true; float m_extra_spacing = 1.f; + bool is_first_layer() const { return size_t(m_layer_info - m_plan.begin()) == m_first_layer_idx; } + // Calculates extrusion flow needed to produce required line width for given layer height float extrusion_flow(float layer_height = -1.f) const // negative layer_height - return current m_extrusion_flow {