From 6325a9e3a2c00f9fa77c25e5af6034315368efeb Mon Sep 17 00:00:00 2001 From: supermerill Date: Sun, 5 Jul 2020 22:28:19 +0200 Subject: [PATCH] remove duplicate M204 --- src/libslic3r/GCode.cpp | 14 ++++++------ src/libslic3r/GCodeWriter.cpp | 41 +++++++++++++++++++++++------------ src/libslic3r/GCodeWriter.hpp | 4 +++- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 817567847..95d4a2c12 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -3036,7 +3036,7 @@ std::string GCode::extrude_loop_vase(const ExtrusionLoop &original_loop, const s } // reset acceleration - gcode += m_writer.set_acceleration((unsigned int)(m_config.default_acceleration.value + 0.5)); + m_writer.set_acceleration((unsigned int)(m_config.default_acceleration.value + 0.5)); //don't wipe here //if (m_wipe.enable) @@ -3380,7 +3380,7 @@ std::string GCode::extrude_loop(const ExtrusionLoop &original_loop, const std::s } // reset acceleration - gcode += m_writer.set_acceleration((unsigned int)(m_config.default_acceleration.value + 0.5)); + m_writer.set_acceleration((unsigned int)(m_config.default_acceleration.value + 0.5)); if (m_wipe.enable) m_wipe.path = paths.front().polyline; // TODO: don't limit wipe to last path @@ -3480,7 +3480,7 @@ std::string GCode::extrude_multi_path(const ExtrusionMultiPath &multipath, const m_wipe.path.reverse(); } // reset acceleration - gcode += m_writer.set_acceleration((unsigned int)floor(m_config.default_acceleration.value + 0.5)); + m_writer.set_acceleration((unsigned int)floor(m_config.default_acceleration.value + 0.5)); return gcode; } @@ -3517,7 +3517,7 @@ std::string GCode::extrude_multi_path3D(const ExtrusionMultiPath3D &multipath3D, m_wipe.path.reverse(); } // reset acceleration - gcode += m_writer.set_acceleration((unsigned int)floor(m_config.default_acceleration.value + 0.5)); + m_writer.set_acceleration((unsigned int)floor(m_config.default_acceleration.value + 0.5)); return gcode; } @@ -3551,7 +3551,7 @@ std::string GCode::extrude_path(const ExtrusionPath &path, const std::string &de m_wipe.path.reverse(); } // reset acceleration - gcode += m_writer.set_acceleration((unsigned int)floor(m_config.default_acceleration.value + 0.5)); + m_writer.set_acceleration((unsigned int)floor(m_config.default_acceleration.value + 0.5)); return gcode; } @@ -3586,7 +3586,7 @@ std::string GCode::extrude_path_3D(const ExtrusionPath3D &path, const std::strin m_wipe.path.reverse(); } // reset acceleration - gcode += m_writer.set_acceleration((unsigned int)floor(m_config.default_acceleration.value + 0.5)); + m_writer.set_acceleration((unsigned int)floor(m_config.default_acceleration.value + 0.5)); return gcode; } @@ -3834,7 +3834,7 @@ std::string GCode::_before_extrude(const ExtrusionPath &path, const std::string } else { acceleration = m_config.default_acceleration.value; }//TODO: add travel accel? - gcode += m_writer.set_acceleration((unsigned int)floor(acceleration + 0.5)); + m_writer.set_acceleration((unsigned int)floor(acceleration + 0.5)); } diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index d568604ba..192c95e17 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -188,28 +188,35 @@ std::string GCodeWriter::set_fan(unsigned int speed, bool dont_save) return gcode.str(); } -std::string GCodeWriter::set_acceleration(unsigned int acceleration) +void GCodeWriter::set_acceleration(unsigned int acceleration) { // Clamp the acceleration to the allowed maximum. if (m_max_acceleration > 0 && acceleration > m_max_acceleration) acceleration = m_max_acceleration; - if (acceleration == 0 || acceleration == m_last_acceleration) - return std::string(); - - m_last_acceleration = acceleration; - + if (acceleration == 0 || acceleration == m_current_acceleration) + return; + + m_current_acceleration = acceleration; +} + +std::string GCodeWriter::write_acceleration(){ + if (m_current_acceleration == m_last_acceleration || m_current_acceleration == 0) + return ""; + + m_last_acceleration = m_current_acceleration; + std::ostringstream gcode; //try to set only printing acceleration, travel should be untouched if possible if (FLAVOR_IS(gcfRepetier)) { // M201: Set max printing acceleration - gcode << "M201 X" << acceleration << " Y" << acceleration; + gcode << "M201 X" << m_current_acceleration << " Y" << m_current_acceleration; } else if(FLAVOR_IS(gcfMarlin) || FLAVOR_IS(gcfLerdge)){ // M204: Set printing acceleration - gcode << "M204 P" << acceleration; + gcode << "M204 P" << m_current_acceleration; } else { // M204: Set default acceleration - gcode << "M204 S" << acceleration; + gcode << "M204 S" << m_current_acceleration; } if (this->config.gcode_comments) gcode << " ; adjust acceleration"; gcode << "\n"; @@ -321,10 +328,12 @@ std::string GCodeWriter::set_speed(double F, const std::string &comment, const s std::string GCodeWriter::travel_to_xy(const Vec2d &point, const std::string &comment) { + std::ostringstream gcode; + gcode << write_acceleration(); + m_pos.x() = point.x(); m_pos.y() = point.y(); - std::ostringstream gcode; gcode << "G1 X" << XYZF_NUM(point.x()) << " Y" << XYZF_NUM(point.y()) << " F" << XYZF_NUM(this->config.travel_speed.value * 60.0); @@ -353,8 +362,9 @@ std::string GCodeWriter::travel_to_xyz(const Vec3d &point, const std::string &co the lift. */ m_lifted = 0; m_pos = point; - + std::ostringstream gcode; + gcode << write_acceleration(); gcode << "G1 X" << XYZF_NUM(point.x()) << " Y" << XYZF_NUM(point.y()) << " Z" << XYZF_NUM(point.z()) @@ -386,8 +396,9 @@ std::string GCodeWriter::travel_to_z(double z, const std::string &comment) std::string GCodeWriter::_travel_to_z(double z, const std::string &comment) { m_pos.z() = z; - + std::ostringstream gcode; + gcode << write_acceleration(); gcode << "G1 Z" << XYZF_NUM(z) << " F" << XYZF_NUM(this->config.travel_speed.value * 60.0); COMMENT(comment); @@ -412,8 +423,9 @@ std::string GCodeWriter::extrude_to_xy(const Vec2d &point, double dE, const std: m_pos.x() = point.x(); m_pos.y() = point.y(); bool is_extrude = m_tool->extrude(dE) != 0; - + std::ostringstream gcode; + gcode << write_acceleration(); gcode << "G1 X" << XYZF_NUM(point.x()) << " Y" << XYZF_NUM(point.y()); if(is_extrude) @@ -429,8 +441,9 @@ std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std m_pos.y() = point.y(); m_lifted = 0; bool is_extrude = m_tool->extrude(dE) != 0; - + std::ostringstream gcode; + gcode << write_acceleration(); gcode << "G1 X" << XYZF_NUM(point.x()) << " Y" << XYZF_NUM(point.y()) << " Z" << XYZF_NUM(point.z() + m_pos.z()); diff --git a/src/libslic3r/GCodeWriter.hpp b/src/libslic3r/GCodeWriter.hpp index a76aae8b6..954fe4570 100644 --- a/src/libslic3r/GCodeWriter.hpp +++ b/src/libslic3r/GCodeWriter.hpp @@ -65,7 +65,8 @@ public: std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1) const; std::string set_bed_temperature(unsigned int temperature, bool wait = false); std::string set_fan(unsigned int speed, bool dont_save = false); - std::string set_acceleration(unsigned int acceleration); + void set_acceleration(unsigned int acceleration); + std::string write_acceleration(); std::string reset_e(bool force = false); std::string update_progress(unsigned int num, unsigned int tot, bool allow_100 = false) const; // return false if this extruder was already selected @@ -100,6 +101,7 @@ private: bool m_single_extruder_multi_material; Tool* m_tool; unsigned int m_last_acceleration; + unsigned int m_current_acceleration; // Limit for setting the acceleration, to respect the machine limits set for the Marlin firmware. // If set to zero, the limit is not in action. unsigned int m_max_acceleration;