From b94213bd35dd4564c2e54ebc2dbf8c9f03d660c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0ach?= Date: Tue, 6 Aug 2024 15:44:24 +0200 Subject: [PATCH 1/3] Fix simple layer change z update --- src/libslic3r/GCode.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 36fa60da34..3e5c583a22 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2861,7 +2861,11 @@ std::string GCodeGenerator::change_layer( gcode += this->retract_and_wipe(); } if (!first_layer) { + // travel_to_z is not used as it may not generate the travel if the writter z == print_z. gcode += this->writer().get_travel_to_z_gcode(print_z, "simple layer change"); + Vec3d position{this->writer().get_position()}; + position.z() = print_z; + this->writer().update_position(position); } } From 6cfad69a5ae076b4157569bf7318d01c39c48de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0ach?= Date: Wed, 7 Aug 2024 14:24:52 +0200 Subject: [PATCH 2/3] Fix first travel to wipe tower after layer change --- src/libslic3r/GCode.cpp | 6 +++--- src/libslic3r/GCode.hpp | 2 ++ src/libslic3r/GCode/WipeTowerIntegration.cpp | 17 +++++++++++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 3e5c583a22..c310d419fd 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2564,7 +2564,7 @@ LayerResult GCodeGenerator::process_layer( } this->set_origin({0, 0}); - bool moved_to_first_point{false}; + this->m_moved_to_first_layer_point = false; // Extrude the skirt, brim, support, perimeters, infill ordered by the extruders. for (const ExtruderExtrusions &extruder_extrusions : extrusions) @@ -2589,7 +2589,7 @@ LayerResult GCodeGenerator::process_layer( this->m_label_objects.update(nullptr); } - if (!moved_to_first_point) { + if (!this->m_moved_to_first_layer_point) { const Vec3crd point{to_3d(first_point, scaled(print_z))}; gcode += this->travel_to_first_position(point, print_z, ExtrusionRole::Mixed, [this]() { @@ -2598,7 +2598,6 @@ LayerResult GCodeGenerator::process_layer( } return m_label_objects.maybe_change_instance(m_writer); }); - moved_to_first_point = true; } if (!extruder_extrusions.skirt.empty()) { @@ -3116,6 +3115,7 @@ std::string GCodeGenerator::travel_to_first_position(const Vec3crd& point, const this->writer().update_position(gcode_point); } + this->m_moved_to_first_layer_point = true; return gcode; } diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 82e2dc151a..0727f9071f 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -429,6 +429,8 @@ private: std::optional m_previous_layer_last_position; std::optional m_previous_layer_last_position_before_wipe; + bool m_moved_to_first_layer_point{false}; + // This needs to be populated during the layer processing! std::unique_ptr m_cooling_buffer; std::unique_ptr m_spiral_vase; diff --git a/src/libslic3r/GCode/WipeTowerIntegration.cpp b/src/libslic3r/GCode/WipeTowerIntegration.cpp index b281060ff8..b36dc9de94 100644 --- a/src/libslic3r/GCode/WipeTowerIntegration.cpp +++ b/src/libslic3r/GCode/WipeTowerIntegration.cpp @@ -68,13 +68,18 @@ std::string WipeTowerIntegration::append_tcr(GCodeGenerator &gcodegen, const Wip gcode += gcodegen.retract_and_wipe(); gcodegen.m_avoid_crossing_perimeters.use_external_mp_once = true; const std::string comment{"Travel to a Wipe Tower"}; - if (gcodegen.last_position) { - gcode += gcodegen.travel_to( - *gcodegen.last_position, xy_point, ExtrusionRole::Mixed, comment, [](){return "";} - ); + if (!gcodegen.m_moved_to_first_layer_point) { + const Vec3crd point = to_3d(xy_point, scaled(z)); + gcode += gcodegen.travel_to_first_position(point, current_z, ExtrusionRole::Mixed, [](){return "";}); } else { - gcode += gcodegen.writer().travel_to_xy(gcodegen.point_to_gcode(xy_point), comment); - gcode += gcodegen.writer().get_travel_to_z_gcode(z, comment); + if (gcodegen.last_position) { + gcode += gcodegen.travel_to( + *gcodegen.last_position, xy_point, ExtrusionRole::Mixed, comment, [](){return "";} + ); + } else { + gcode += gcodegen.writer().travel_to_xy(gcodegen.point_to_gcode(xy_point), comment); + gcode += gcodegen.writer().get_travel_to_z_gcode(z, comment); + } } gcode += gcodegen.unretract(); } else { From dbc8300a599c8b0cfc3a04a599a5ad077ffc45fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0ach?= Date: Fri, 9 Aug 2024 11:00:54 +0200 Subject: [PATCH 3/3] Fix first positions on layers with wipe tower with not toolchange --- src/libslic3r/GCode/ExtrusionOrder.cpp | 13 ++++++++----- src/libslic3r/GCode/WipeTowerIntegration.hpp | 5 ++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/GCode/ExtrusionOrder.cpp b/src/libslic3r/GCode/ExtrusionOrder.cpp index b746ea352b..b6d95a7c63 100644 --- a/src/libslic3r/GCode/ExtrusionOrder.cpp +++ b/src/libslic3r/GCode/ExtrusionOrder.cpp @@ -525,11 +525,14 @@ std::vector get_extrusions( ExtruderExtrusions extruder_extrusions{extruder_id}; if (layer_tools.has_wipe_tower && wipe_tower != nullptr) { - if (is_toolchange_required(is_first_layer, layer_tools.extruders.back(), extruder_id, current_extruder_id)) { - const WipeTower::ToolChangeResult tool_change{wipe_tower->get_toolchange(toolchange_number++)}; - previous_position = Point::new_scale(wipe_tower->transform_wt_pt(tool_change.end_pos)); - current_extruder_id = tool_change.new_tool; - extruder_extrusions.wipe_tower_start = Point::new_scale(wipe_tower->transform_wt_pt(tool_change.start_pos)); + const bool finish_wipe_tower{extruder_id == layer_tools.extruders.back()}; + if (finish_wipe_tower || is_toolchange_required(is_first_layer, layer_tools.extruders.back(), extruder_id, current_extruder_id)) { + if (const auto tool_change{wipe_tower->get_toolchange(toolchange_number)}) { + toolchange_number++; + previous_position = Point::new_scale(wipe_tower->transform_wt_pt(tool_change->end_pos)); + current_extruder_id = tool_change->new_tool; + extruder_extrusions.wipe_tower_start = Point::new_scale(wipe_tower->transform_wt_pt(tool_change->start_pos)); + } } } diff --git a/src/libslic3r/GCode/WipeTowerIntegration.hpp b/src/libslic3r/GCode/WipeTowerIntegration.hpp index 05c60a2291..a0b8254757 100644 --- a/src/libslic3r/GCode/WipeTowerIntegration.hpp +++ b/src/libslic3r/GCode/WipeTowerIntegration.hpp @@ -39,7 +39,10 @@ public: std::string tool_change(GCodeGenerator &gcodegen, int extruder_id, bool finish_layer); std::string finalize(GCodeGenerator &gcodegen); std::vector used_filament_length() const; - WipeTower::ToolChangeResult get_toolchange(std::size_t index) const { + std::optional get_toolchange(std::size_t index) const { + if (m_layer_idx >= m_tool_changes.size()) { + return std::nullopt; + } return m_tool_changes.at(m_layer_idx).at(index); }