From 65b3dd835aa5941574ede19c5449314f88b161ce Mon Sep 17 00:00:00 2001 From: supermerill Date: Mon, 29 Jun 2020 01:05:02 +0200 Subject: [PATCH] #318 set travel acceleration - now gocde-accel will try to change only the printing accel on the fly (for marlin and repetier only) --- src/libslic3r/GCode.cpp | 9 ++++---- src/libslic3r/GCodeTimeEstimator.cpp | 32 +++++++++++++++++++++++++--- src/libslic3r/GCodeTimeEstimator.hpp | 10 +++++++++ src/libslic3r/GCodeWriter.cpp | 10 ++++----- src/libslic3r/PrintConfig.cpp | 20 ++++++++++++----- src/libslic3r/PrintConfig.hpp | 5 ++++- src/slic3r/GUI/Preset.cpp | 1 + src/slic3r/GUI/Tab.cpp | 1 + 8 files changed, 70 insertions(+), 18 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 709597cba..2653aeac1 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -845,6 +845,7 @@ namespace DoExport { if (config.gcode_flavor.value == gcfMarlin || config.gcode_flavor.value == gcfLerdge) { normal_time_estimator.set_max_acceleration((float)config.machine_max_acceleration_extruding.values[0]); normal_time_estimator.set_retract_acceleration((float)config.machine_max_acceleration_retracting.values[0]); + normal_time_estimator.set_max_travel_acceleration((float)config.machine_max_acceleration_travel.values[0]); normal_time_estimator.set_minimum_feedrate((float)config.machine_min_extruding_rate.values[0]); normal_time_estimator.set_minimum_travel_feedrate((float)config.machine_min_travel_rate.values[0]); normal_time_estimator.set_axis_max_acceleration(GCodeTimeEstimator::X, (float)config.machine_max_acceleration_x.values[0]); @@ -1755,11 +1756,11 @@ void GCode::print_machine_envelope(FILE *file, Print &print) fprintf(file, "M204 P%d R%d T%d ; sets acceleration (P, T) and retract acceleration (R), mm/sec^2\n", int(print.config().machine_max_acceleration_extruding.values.front() + 0.5), int(print.config().machine_max_acceleration_retracting.values.front() + 0.5), - int(print.config().machine_max_acceleration_extruding.values.front() + 0.5)); + int(print.config().machine_max_acceleration_travel.values.front() + 0.5)); if (std::set{gcfRepRap, gcfKlipper}.count(print.config().gcode_flavor.value) > 0) - fprintf(file, "M204 P%d T%d ; sets acceleration (P, T) and retract acceleration (R), mm/sec^2\n", + fprintf(file, "M204 P%d T%d ; sets acceleration (P, T), mm/sec^2\n", int(print.config().machine_max_acceleration_extruding.values.front() + 0.5), - int(print.config().machine_max_acceleration_retracting.values.front() + 0.5)); + int(print.config().machine_max_acceleration_travel.values.front() + 0.5)); if (std::set{gcfMarlin, gcfLerdge, gcfRepetier}.count(print.config().gcode_flavor.value) > 0) fprintf(file, "M566 X%.2lf Y%.2lf Z%.2lf E%.2lf ; sets the jerk limits, mm/sec\n", print.config().machine_max_jerk_x.values.front(), @@ -3827,7 +3828,7 @@ std::string GCode::_before_extrude(const ExtrusionPath &path, const std::string acceleration = m_config.infill_acceleration.value; } else { acceleration = m_config.default_acceleration.value; - } + }//TODO: add travel accel? gcode += m_writer.set_acceleration((unsigned int)floor(acceleration + 0.5)); } diff --git a/src/libslic3r/GCodeTimeEstimator.cpp b/src/libslic3r/GCodeTimeEstimator.cpp index 928146238..55cb078a7 100644 --- a/src/libslic3r/GCodeTimeEstimator.cpp +++ b/src/libslic3r/GCodeTimeEstimator.cpp @@ -496,6 +496,31 @@ namespace Slic3r { return m_state.max_acceleration; } + void GCodeTimeEstimator::set_max_travel_acceleration(float acceleration_mm_sec2) + { + m_state.max_travel_acceleration = acceleration_mm_sec2; + if (acceleration_mm_sec2 > 0) + m_state.travel_acceleration = acceleration_mm_sec2; + } + + float GCodeTimeEstimator::get_max_travel_acceleration() const + { + return m_state.max_travel_acceleration; + } + + void GCodeTimeEstimator::set_travel_acceleration(float acceleration_mm_sec2) + { + m_state.travel_acceleration = (m_state.max_travel_acceleration == 0) ? + acceleration_mm_sec2 : + // Clamp the acceleration with the maximum. + std::min(m_state.max_travel_acceleration, acceleration_mm_sec2); + } + + float GCodeTimeEstimator::get_travel_acceleration() const + { + return m_state.travel_acceleration; + } + void GCodeTimeEstimator::set_retract_acceleration(float acceleration_mm_sec2) { m_state.retract_acceleration = acceleration_mm_sec2; @@ -670,7 +695,9 @@ namespace Slic3r { // Setting the maximum acceleration to zero means that the there is no limit and the G-code // is allowed to set excessive values. set_max_acceleration(0); + set_max_travel_acceleration(0); set_acceleration(DEFAULT_ACCELERATION); + set_travel_acceleration(DEFAULT_ACCELERATION); set_retract_acceleration(DEFAULT_RETRACT_ACCELERATION); set_minimum_feedrate(DEFAULT_MINIMUM_FEEDRATE); set_minimum_travel_feedrate(DEFAULT_MINIMUM_TRAVEL_FEEDRATE); @@ -1087,7 +1114,7 @@ namespace Slic3r { } // calculates block acceleration - float acceleration = block.is_extruder_only_move() ? get_retract_acceleration() : get_acceleration(); + float acceleration = block.is_extruder_only_move() ? get_retract_acceleration() : block.is_travel_move() ? get_travel_acceleration() : get_acceleration(); for (unsigned char a = X; a < Num_Axis; ++a) { @@ -1406,8 +1433,7 @@ namespace Slic3r { set_retract_acceleration(value); if (line.has_value('T', value)) { // Interpret the T value as the travel acceleration in the new Marlin format. - //FIXME Prusa3D firmware currently does not support travel acceleration value independent from the extruding acceleration value. - // set_travel_acceleration(value); + set_travel_acceleration(value); } } } diff --git a/src/libslic3r/GCodeTimeEstimator.hpp b/src/libslic3r/GCodeTimeEstimator.hpp index d9facd7cb..a2ad52aa3 100644 --- a/src/libslic3r/GCodeTimeEstimator.hpp +++ b/src/libslic3r/GCodeTimeEstimator.hpp @@ -84,6 +84,9 @@ namespace Slic3r { float acceleration; // mm/s^2 // hard limit for the acceleration, to which the firmware will clamp. float max_acceleration; // mm/s^2 + float travel_acceleration; // mm/s^2 + // hard limit for the travel_acceleration, to which the firmware will clamp. + float max_travel_acceleration; // mm/s^2 float retract_acceleration; // mm/s^2 float additional_time; // s float minimum_feedrate; // mm/s @@ -327,6 +330,13 @@ namespace Slic3r { void set_max_acceleration(float acceleration_mm_sec2); float get_max_acceleration() const; + void set_travel_acceleration(float acceleration_mm_sec2); + float get_travel_acceleration() const; + + // Maximum acceleration for the machine. The firmware simulator will clamp the M204 Txxx to this maximum. + void set_max_travel_acceleration(float acceleration_mm_sec2); + float get_max_travel_acceleration() const; + void set_retract_acceleration(float acceleration_mm_sec2); float get_retract_acceleration() const; diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 5b428885b..d568604ba 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -61,7 +61,7 @@ std::string GCodeWriter::preamble() gcode << "G21 ; set units to millimeters\n"; gcode << "G90 ; use absolute coordinates\n"; } - if (FLAVOR_IS(gcfRepRap) || FLAVOR_IS(gcfMarlin) || FLAVOR_IS(gcfTeacup) || FLAVOR_IS(gcfRepetier) || FLAVOR_IS(gcfSmoothie) + if (FLAVOR_IS(gcfRepRap) || FLAVOR_IS(gcfMarlin) || FLAVOR_IS(gcfLerdge) || FLAVOR_IS(gcfTeacup) || FLAVOR_IS(gcfRepetier) || FLAVOR_IS(gcfSmoothie) || FLAVOR_IS(gcfKlipper) || FLAVOR_IS(gcfLerdge)) { if (this->config.use_relative_e_distances) { gcode << "M83 ; use relative distances for extrusion\n"; @@ -200,13 +200,13 @@ std::string GCodeWriter::set_acceleration(unsigned int acceleration) m_last_acceleration = 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; - if (this->config.gcode_comments) gcode << " ; adjust acceleration"; - gcode << "\n"; - // M202: Set max travel acceleration - gcode << "M202 X" << acceleration << " Y" << acceleration; + } else if(FLAVOR_IS(gcfMarlin) || FLAVOR_IS(gcfLerdge)){ + // M204: Set printing acceleration + gcode << "M204 P" << acceleration; } else { // M204: Set default acceleration gcode << "M204 S" << acceleration; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index ada5ab060..88381342d 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -335,7 +335,7 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionFloat(0)); def = this->add("brim_ears", coBool); - def->label = L(""); + def->label = (""); def->full_label = L("Brim ears"); def->category = OptionCategory::skirtBrim; def->tooltip = L("Only draw brim over the sharp edges of the model."); @@ -1932,17 +1932,27 @@ void PrintConfigDef::init_fff_params() def = this->add("machine_max_acceleration_extruding", coFloats); def->full_label = L("Maximum acceleration when extruding"); def->category = OptionCategory::limits; - def->tooltip = L("Maximum acceleration when extruding (M204 S)"); + def->tooltip = L("Maximum acceleration when extruding (M204 P)"); + def->sidetext = L("mm/s²"); + def->min = 0; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloats{ 1500., 1250. }); + + // M204 R... [mm/sec^2] + def = this->add("machine_max_acceleration_retracting", coFloats); + def->full_label = L("Maximum acceleration when retracting"); + def->category = OptionCategory::limits; + def->tooltip = L("Maximum acceleration when retracting (M204 R)"); def->sidetext = L("mm/s²"); def->min = 0; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloats{ 1500., 1250. }); // M204 T... [mm/sec^2] - def = this->add("machine_max_acceleration_retracting", coFloats); - def->full_label = L("Maximum acceleration when retracting"); + def = this->add("machine_max_acceleration_travel", coFloats); + def->full_label = L("Maximum acceleration when travelling"); def->category = OptionCategory::limits; - def->tooltip = L("Maximum acceleration when retracting (M204 T)"); + def->tooltip = L("Maximum acceleration when travelling (M204 T)"); def->sidetext = L("mm/s²"); def->min = 0; def->mode = comAdvanced; diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 14bc04266..ac8e01b4c 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -798,8 +798,10 @@ public: ConfigOptionFloats machine_max_feedrate_e; // M204 S... [mm/sec^2] ConfigOptionFloats machine_max_acceleration_extruding; - // M204 T... [mm/sec^2] + // M204 R... [mm/sec^2] ConfigOptionFloats machine_max_acceleration_retracting; + // M204 T... [mm/sec^2] + ConfigOptionFloats machine_max_acceleration_travel; // M205 X... Y... Z... E... [mm/sec] ConfigOptionFloats machine_max_jerk_x; ConfigOptionFloats machine_max_jerk_y; @@ -823,6 +825,7 @@ protected: OPT_PTR(machine_max_feedrate_e); OPT_PTR(machine_max_acceleration_extruding); OPT_PTR(machine_max_acceleration_retracting); + OPT_PTR(machine_max_acceleration_travel); OPT_PTR(machine_max_jerk_x); OPT_PTR(machine_max_jerk_y); OPT_PTR(machine_max_jerk_z); diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp index 847dbdd26..7ce78f25e 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/slic3r/GUI/Preset.cpp @@ -607,6 +607,7 @@ const std::vector& Preset::printer_options() "wipe_advanced_multiplier", "wipe_advanced_algo", "remaining_times", "silent_mode", "machine_max_acceleration_extruding", "machine_max_acceleration_retracting", + "machine_max_acceleration_travel", "machine_max_acceleration_x", "machine_max_acceleration_y", "machine_max_acceleration_z", "machine_max_acceleration_e", "machine_max_feedrate_x", "machine_max_feedrate_y", "machine_max_feedrate_z", "machine_max_feedrate_e", "machine_min_extruding_rate", "machine_min_travel_rate", diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 8800b98d4..34896e0c5 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2234,6 +2234,7 @@ PageShp TabPrinter::build_kinematics_page() } append_option_line_kinematics(optgroup, "machine_max_acceleration_extruding"); append_option_line_kinematics(optgroup, "machine_max_acceleration_retracting"); + append_option_line_kinematics(optgroup, "machine_max_acceleration_travel"); optgroup = page->new_optgroup(_(L("Jerk limits"))); for (const std::string &axis : axes) {