Browse Source

Add lift before the first travel move in GCode.cpp

Martin Šach 1 year ago
parent
commit
8cbea4982a
2 changed files with 26 additions and 3 deletions
  1. 15 1
      src/libslic3r/GCode.cpp
  2. 11 2
      tests/fff_print/test_retraction.cpp

+ 15 - 1
src/libslic3r/GCode.cpp

@@ -2957,11 +2957,25 @@ std::string GCodeGenerator::_extrude(
     const std::string_view description_bridge = path_attr.role.is_bridge() ? " (bridge)"sv : ""sv;
     const std::string_view description_bridge = path_attr.role.is_bridge() ? " (bridge)"sv : ""sv;
 
 
     if (!m_current_layer_first_position) {
     if (!m_current_layer_first_position) {
-        // Make the first travel just one G1.
         const Vec3crd point = to_3d(path.front().point, scaled(this->m_last_layer_z + this->m_config.z_offset.value));
         const Vec3crd point = to_3d(path.front().point, scaled(this->m_last_layer_z + this->m_config.z_offset.value));
         const Vec3d gcode_point = to_3d(this->point_to_gcode(point.head<2>()), unscaled(point.z()));
         const Vec3d gcode_point = to_3d(this->point_to_gcode(point.head<2>()), unscaled(point.z()));
+
+        if (!this->last_position) {
+            double lift{
+                EXTRUDER_CONFIG(travel_ramping_lift) ? EXTRUDER_CONFIG(travel_max_lift) :
+                                                       EXTRUDER_CONFIG(retract_lift)};
+            const double upper_limit = EXTRUDER_CONFIG(retract_lift_below);
+            const double lower_limit = EXTRUDER_CONFIG(retract_lift_above);
+            if ((lower_limit > 0 && gcode_point.z() < lower_limit) ||
+                (upper_limit > 0 && gcode_point.z() > upper_limit)) {
+                lift = 0.0;
+            }
+            gcode += this->writer().get_travel_to_z_gcode(gcode_point.z() + lift, "lift");
+        }
+
         this->last_position = path.front().point;
         this->last_position = path.front().point;
         this->writer().update_position(gcode_point);
         this->writer().update_position(gcode_point);
+
         gcode += this->writer().get_travel_to_xy_gcode(gcode_point.head<2>(), "move to first layer point");
         gcode += this->writer().get_travel_to_xy_gcode(gcode_point.head<2>(), "move to first layer point");
         gcode += this->writer().get_travel_to_z_gcode(gcode_point.z(), "move to first layer point");
         gcode += this->writer().get_travel_to_z_gcode(gcode_point.z(), "move to first layer point");
         m_current_layer_first_position = gcode_point;
         m_current_layer_first_position = gcode_point;

+ 11 - 2
tests/fff_print/test_retraction.cpp

@@ -9,10 +9,13 @@
 
 
 #include "test_data.hpp"
 #include "test_data.hpp"
 #include <regex>
 #include <regex>
+#include <fstream>
 
 
 using namespace Slic3r;
 using namespace Slic3r;
 using namespace Test;
 using namespace Test;
 
 
+constexpr bool debug_files {false};
+
 void check_gcode(std::initializer_list<TestMesh> meshes, const DynamicPrintConfig& config, const unsigned duplicate) {
 void check_gcode(std::initializer_list<TestMesh> meshes, const DynamicPrintConfig& config, const unsigned duplicate) {
     constexpr std::size_t tools_count = 4;
     constexpr std::size_t tools_count = 4;
     std::size_t tool = 0;
     std::size_t tool = 0;
@@ -183,6 +186,12 @@ TEST_CASE("Z moves", "[retraction]") {
     unsigned z_restores = 0;
     unsigned z_restores = 0;
 
 
     std::string gcode = Slic3r::Test::slice({TestMesh::cube_20x20x20}, config);
     std::string gcode = Slic3r::Test::slice({TestMesh::cube_20x20x20}, config);
+
+    if constexpr(debug_files) {
+        std::ofstream file{"zmoves.gcode"};
+        file << gcode;
+    }
+
 	GCodeReader parser;
 	GCodeReader parser;
     parser.parse_buffer(gcode, [&] (Slic3r::GCodeReader &self, const Slic3r::GCodeReader::GCodeLine &line) {
     parser.parse_buffer(gcode, [&] (Slic3r::GCodeReader &self, const Slic3r::GCodeReader::GCodeLine &line) {
         if (line.retracting(self)) {
         if (line.retracting(self)) {
@@ -205,8 +214,8 @@ TEST_CASE("Z moves", "[retraction]") {
     CHECK(layer_changes_with_retraction == 0);
     CHECK(layer_changes_with_retraction == 0);
     INFO("no retractions");
     INFO("no retractions");
     CHECK(retractions == 0);
     CHECK(retractions == 0);
-    INFO("no lift");
-    CHECK(z_restores == 0);
+    INFO("no lift other than for the first move");
+    CHECK(z_restores == 1);
 }
 }
 
 
 TEST_CASE("Firmware retraction handling", "[retraction]") {
 TEST_CASE("Firmware retraction handling", "[retraction]") {