From 7d7813243be89958d7903692c59ee6d3ba6e2851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0ach?= Date: Wed, 23 Oct 2024 15:32:02 +0200 Subject: [PATCH] Use writter m_pos to determine previous position for xyz travel --- src/libslic3r/GCode.cpp | 11 ++--------- src/libslic3r/GCode/GCodeWriter.cpp | 11 ++++++----- src/libslic3r/GCode/GCodeWriter.hpp | 4 ++-- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 0c372e8662..c7a74d2a31 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2258,12 +2258,10 @@ std::string GCodeGenerator::generate_ramping_layer_change_gcode( )}; std::string travel_gcode; - Vec3d previous_point{this->point_to_gcode(travel.front())}; for (const Vec3crd &point : travel) { const Vec3d gcode_point{this->point_to_gcode(point)}; travel_gcode += this->m_writer - .get_travel_to_xyz_gcode(previous_point, gcode_point, "layer change"); - previous_point = gcode_point; + .get_travel_to_xyz_gcode(gcode_point, "layer change"); } return travel_gcode; } @@ -3194,9 +3192,6 @@ std::string GCodeGenerator::travel_to_first_position(const Vec3crd& point, const const Vec3d gcode_point = to_3d(this->point_to_gcode(point.head<2>()), unscaled(point.z())); if (!EXTRUDER_CONFIG(travel_ramping_lift) && this->last_position) { - Vec3d writer_position{this->writer().get_position()}; - writer_position.z() = 0.0; // Endofrce z generation! - this->writer().update_position(writer_position); const Vec3crd from{to_3d(*this->last_position, scaled(from_z))}; gcode = this->travel_to( from, point, role, "travel to first layer point", insert_gcode @@ -3546,7 +3541,6 @@ std::string GCodeGenerator::generate_travel_gcode( // use G1 because we rely on paths being straight (G0 may make round paths) gcode += this->m_writer.set_travel_acceleration(acceleration); - Vec3d previous_point{this->point_to_gcode(travel.front())}; bool already_inserted{false}; for (std::size_t i{0}; i < travel.size(); ++i) { const Vec3crd& point{travel[i]}; @@ -3557,9 +3551,8 @@ std::string GCodeGenerator::generate_travel_gcode( already_inserted = true; } - gcode += this->m_writer.travel_to_xyz(previous_point, gcode_point, comment); + gcode += this->m_writer.travel_to_xyz(gcode_point, comment); this->last_position = point.head<2>(); - previous_point = gcode_point; } if (! GCodeWriter::supports_separate_travel_acceleration(config().gcode_flavor)) { diff --git a/src/libslic3r/GCode/GCodeWriter.cpp b/src/libslic3r/GCode/GCodeWriter.cpp index aa211c8634..4ec2550bae 100644 --- a/src/libslic3r/GCode/GCodeWriter.cpp +++ b/src/libslic3r/GCode/GCodeWriter.cpp @@ -327,19 +327,20 @@ std::string GCodeWriter::travel_to_xy_G2G3IJ(const Vec2d &point, const Vec2d &ij return w.string(); } -std::string GCodeWriter::travel_to_xyz(const Vec3d& from, const Vec3d &to, const std::string_view comment) +std::string GCodeWriter::travel_to_xyz(const Vec3d &to, const std::string_view comment) { if (std::abs(to.x() - m_pos.x()) < EPSILON && std::abs(to.y() - m_pos.y()) < EPSILON) { return this->travel_to_z(to.z(), comment); } else if (std::abs(to.z() - m_pos.z()) < EPSILON) { return this->travel_to_xy(to.head<2>(), comment); } else { + std::string result{this->get_travel_to_xyz_gcode(to, comment)}; m_pos = to; - return this->get_travel_to_xyz_gcode(from, to, comment); + return result; } } -std::string GCodeWriter::get_travel_to_xyz_gcode(const Vec3d &from, const Vec3d &to, const std::string_view comment) const { +std::string GCodeWriter::get_travel_to_xyz_gcode(const Vec3d &to, const std::string_view comment) const { GCodeG1Formatter w; w.emit_xyz(to); @@ -347,8 +348,8 @@ std::string GCodeWriter::get_travel_to_xyz_gcode(const Vec3d &from, const Vec3d if (speed_z == 0.) speed_z = this->config.travel_speed.value; - const double distance_xy{(to.head<2>() - from.head<2>()).norm()}; - const double distnace_z{std::abs(to.z() - from.z())}; + const double distance_xy{(to.head<2>() - m_pos.head<2>()).norm()}; + const double distnace_z{std::abs(to.z() - m_pos.z())}; const double time_z = distnace_z / speed_z; const double time_xy = distance_xy / this->config.travel_speed.value; const double factor = time_z > 0 ? time_xy / time_z : 1; diff --git a/src/libslic3r/GCode/GCodeWriter.hpp b/src/libslic3r/GCode/GCodeWriter.hpp index 26b1bc383e..47aedab680 100644 --- a/src/libslic3r/GCode/GCodeWriter.hpp +++ b/src/libslic3r/GCode/GCodeWriter.hpp @@ -87,8 +87,8 @@ public: * @param to Where to travel to. * @param comment Description of the travel purpose. */ - std::string get_travel_to_xyz_gcode(const Vec3d &from, const Vec3d &to, const std::string_view comment) const; - std::string travel_to_xyz(const Vec3d &from, const Vec3d &to, const std::string_view comment = {}); + std::string get_travel_to_xyz_gcode(const Vec3d &to, const std::string_view comment) const; + std::string travel_to_xyz(const Vec3d &to, const std::string_view comment = {}); std::string get_travel_to_z_gcode(double z, const std::string_view comment) const; std::string travel_to_z(double z, const std::string_view comment = {}); std::string extrude_to_xy(const Vec2d &point, double dE, const std::string_view comment = {});