remove duplicate M204

This commit is contained in:
supermerill 2020-07-05 22:28:19 +02:00
parent e37c6d5940
commit 6325a9e3a2
3 changed files with 37 additions and 22 deletions

View File

@ -3036,7 +3036,7 @@ std::string GCode::extrude_loop_vase(const ExtrusionLoop &original_loop, const s
} }
// reset acceleration // 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 //don't wipe here
//if (m_wipe.enable) //if (m_wipe.enable)
@ -3380,7 +3380,7 @@ std::string GCode::extrude_loop(const ExtrusionLoop &original_loop, const std::s
} }
// reset acceleration // 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) if (m_wipe.enable)
m_wipe.path = paths.front().polyline; // TODO: don't limit wipe to last path 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(); m_wipe.path.reverse();
} }
// reset acceleration // 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; return gcode;
} }
@ -3517,7 +3517,7 @@ std::string GCode::extrude_multi_path3D(const ExtrusionMultiPath3D &multipath3D,
m_wipe.path.reverse(); m_wipe.path.reverse();
} }
// reset acceleration // 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; return gcode;
} }
@ -3551,7 +3551,7 @@ std::string GCode::extrude_path(const ExtrusionPath &path, const std::string &de
m_wipe.path.reverse(); m_wipe.path.reverse();
} }
// reset acceleration // 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; return gcode;
} }
@ -3586,7 +3586,7 @@ std::string GCode::extrude_path_3D(const ExtrusionPath3D &path, const std::strin
m_wipe.path.reverse(); m_wipe.path.reverse();
} }
// reset acceleration // 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; return gcode;
} }
@ -3834,7 +3834,7 @@ std::string GCode::_before_extrude(const ExtrusionPath &path, const std::string
} else { } else {
acceleration = m_config.default_acceleration.value; acceleration = m_config.default_acceleration.value;
}//TODO: add travel accel? }//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));
} }

View File

@ -188,28 +188,35 @@ std::string GCodeWriter::set_fan(unsigned int speed, bool dont_save)
return gcode.str(); 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. // Clamp the acceleration to the allowed maximum.
if (m_max_acceleration > 0 && acceleration > m_max_acceleration) if (m_max_acceleration > 0 && acceleration > m_max_acceleration)
acceleration = m_max_acceleration; acceleration = m_max_acceleration;
if (acceleration == 0 || acceleration == m_last_acceleration) if (acceleration == 0 || acceleration == m_current_acceleration)
return std::string(); return;
m_last_acceleration = acceleration; 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; std::ostringstream gcode;
//try to set only printing acceleration, travel should be untouched if possible //try to set only printing acceleration, travel should be untouched if possible
if (FLAVOR_IS(gcfRepetier)) { if (FLAVOR_IS(gcfRepetier)) {
// M201: Set max printing acceleration // 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)){ } else if(FLAVOR_IS(gcfMarlin) || FLAVOR_IS(gcfLerdge)){
// M204: Set printing acceleration // M204: Set printing acceleration
gcode << "M204 P" << acceleration; gcode << "M204 P" << m_current_acceleration;
} else { } else {
// M204: Set default acceleration // M204: Set default acceleration
gcode << "M204 S" << acceleration; gcode << "M204 S" << m_current_acceleration;
} }
if (this->config.gcode_comments) gcode << " ; adjust acceleration"; if (this->config.gcode_comments) gcode << " ; adjust acceleration";
gcode << "\n"; 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::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.x() = point.x();
m_pos.y() = point.y(); m_pos.y() = point.y();
std::ostringstream gcode;
gcode << "G1 X" << XYZF_NUM(point.x()) gcode << "G1 X" << XYZF_NUM(point.x())
<< " Y" << XYZF_NUM(point.y()) << " Y" << XYZF_NUM(point.y())
<< " F" << XYZF_NUM(this->config.travel_speed.value * 60.0); << " 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. */ the lift. */
m_lifted = 0; m_lifted = 0;
m_pos = point; m_pos = point;
std::ostringstream gcode; std::ostringstream gcode;
gcode << write_acceleration();
gcode << "G1 X" << XYZF_NUM(point.x()) gcode << "G1 X" << XYZF_NUM(point.x())
<< " Y" << XYZF_NUM(point.y()) << " Y" << XYZF_NUM(point.y())
<< " Z" << XYZF_NUM(point.z()) << " 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) std::string GCodeWriter::_travel_to_z(double z, const std::string &comment)
{ {
m_pos.z() = z; m_pos.z() = z;
std::ostringstream gcode; std::ostringstream gcode;
gcode << write_acceleration();
gcode << "G1 Z" << XYZF_NUM(z) gcode << "G1 Z" << XYZF_NUM(z)
<< " F" << XYZF_NUM(this->config.travel_speed.value * 60.0); << " F" << XYZF_NUM(this->config.travel_speed.value * 60.0);
COMMENT(comment); 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.x() = point.x();
m_pos.y() = point.y(); m_pos.y() = point.y();
bool is_extrude = m_tool->extrude(dE) != 0; bool is_extrude = m_tool->extrude(dE) != 0;
std::ostringstream gcode; std::ostringstream gcode;
gcode << write_acceleration();
gcode << "G1 X" << XYZF_NUM(point.x()) gcode << "G1 X" << XYZF_NUM(point.x())
<< " Y" << XYZF_NUM(point.y()); << " Y" << XYZF_NUM(point.y());
if(is_extrude) 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_pos.y() = point.y();
m_lifted = 0; m_lifted = 0;
bool is_extrude = m_tool->extrude(dE) != 0; bool is_extrude = m_tool->extrude(dE) != 0;
std::ostringstream gcode; std::ostringstream gcode;
gcode << write_acceleration();
gcode << "G1 X" << XYZF_NUM(point.x()) gcode << "G1 X" << XYZF_NUM(point.x())
<< " Y" << XYZF_NUM(point.y()) << " Y" << XYZF_NUM(point.y())
<< " Z" << XYZF_NUM(point.z() + m_pos.z()); << " Z" << XYZF_NUM(point.z() + m_pos.z());

View File

@ -65,7 +65,8 @@ public:
std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1) const; 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_bed_temperature(unsigned int temperature, bool wait = false);
std::string set_fan(unsigned int speed, bool dont_save = 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 reset_e(bool force = false);
std::string update_progress(unsigned int num, unsigned int tot, bool allow_100 = false) const; std::string update_progress(unsigned int num, unsigned int tot, bool allow_100 = false) const;
// return false if this extruder was already selected // return false if this extruder was already selected
@ -100,6 +101,7 @@ private:
bool m_single_extruder_multi_material; bool m_single_extruder_multi_material;
Tool* m_tool; Tool* m_tool;
unsigned int m_last_acceleration; 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. // 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. // If set to zero, the limit is not in action.
unsigned int m_max_acceleration; unsigned int m_max_acceleration;