diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 68fbe62d5..0e2b1a57f 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1571,10 +1571,20 @@ void GCode::print_machine_envelope(FILE *file, Print &print) int(print.config().machine_max_feedrate_y.values.front() + 0.5), int(print.config().machine_max_feedrate_z.values.front() + 0.5), int(print.config().machine_max_feedrate_e.values.front() + 0.5)); + + // Now M204 - acceleration. This one is quite hairy thanks to how Marlin guys care about + // backwards compatibility: https://github.com/prusa3d/PrusaSlicer/issues/1089 + // Legacy Marlin should export travel acceleration the same as printing acceleration. + // MarlinFirmware has the two separated. + int travel_acc = print.config().gcode_flavor == gcfMarlinLegacy + ? int(print.config().machine_max_acceleration_extruding.values.front() + 0.5) + : int(print.config().machine_max_acceleration_travel.values.front() + 0.5); 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)); + travel_acc); + + fprintf(file, "M205 X%.2lf Y%.2lf Z%.2lf E%.2lf ; sets the jerk limits, mm/sec\n", print.config().machine_max_jerk_x.values.front(), print.config().machine_max_jerk_y.values.front(), diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 5bf0a30da..bc8533113 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -207,8 +207,12 @@ std::string GCodeWriter::set_acceleration(unsigned int acceleration) // M202: Set max travel acceleration gcode << "M202 X" << acceleration << " Y" << acceleration; } else if (FLAVOR_IS(gcfRepRapFirmware)) { - // M204: Set default acceleration - gcode << "M204 P" << acceleration; + // M204: Set default acceleration + gcode << "M204 P" << acceleration; + } else if (FLAVOR_IS(gcfMarlinFirmware)) { + // This is new MarlinFirmware with separated print/retraction/travel acceleration. + // Use M204 P, we don't want to override travel acc by M204 S (which is deprecated anyway). + gcode << "M204 P" << acceleration; } else { // M204: Set default acceleration gcode << "M204 S" << acceleration; diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index ecb20a18e..d57bcb451 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -468,7 +468,7 @@ const std::vector& Preset::machine_limits_options() static std::vector s_opts; if (s_opts.empty()) { s_opts = { - "machine_max_acceleration_extruding", "machine_max_acceleration_retracting", + "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/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 9c6ac2662..fd33f5807 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1469,21 +1469,34 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloats{ 0., 0. }); - // M204 S... [mm/sec^2] + // M204 P... [mm/sec^2] def = this->add("machine_max_acceleration_extruding", coFloats); def->full_label = L("Maximum acceleration when extruding"); def->category = L("Machine limits"); - def->tooltip = L("Maximum acceleration when extruding (M204 S)"); + def->tooltip = L("Maximum acceleration when extruding (M204 P)\n\n" + "Marlin (legacy) firmware flavor will use this also " + "as travel acceleration (M204 T)."); + 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 = L("Machine 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 for travel moves"); def->category = L("Machine limits"); - def->tooltip = L("Maximum acceleration when retracting (M204 T)"); + def->tooltip = L("Maximum acceleration for travel moves (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 4f94f8859..2ee6bc061 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -726,10 +726,12 @@ public: ConfigOptionFloats machine_max_feedrate_y; ConfigOptionFloats machine_max_feedrate_z; ConfigOptionFloats machine_max_feedrate_e; - // M204 S... [mm/sec^2] + + // M204 P... R... T...[mm/sec^2] ConfigOptionFloats machine_max_acceleration_extruding; - // M204 T... [mm/sec^2] ConfigOptionFloats machine_max_acceleration_retracting; + ConfigOptionFloats machine_max_acceleration_travel; + // M205 X... Y... Z... E... [mm/sec] ConfigOptionFloats machine_max_jerk_x; ConfigOptionFloats machine_max_jerk_y; @@ -754,6 +756,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/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 915fa5267..933ae1a4d 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2264,6 +2264,13 @@ void TabPrinter::build_fff() m_use_silent_mode = val; } } + if (opt_key == "gcode_flavor") { + bool supports_travel_acceleration = (boost::any_cast(value) == int(gcfMarlinFirmware)); + if (supports_travel_acceleration != m_supports_travel_acceleration) { + m_rebuild_kinematics_page = true; + m_supports_travel_acceleration = supports_travel_acceleration; + } + } build_unregular_pages(); update_dirty(); on_value_change(opt_key, value); @@ -2560,6 +2567,8 @@ PageShp TabPrinter::build_kinematics_page() } append_option_line(optgroup, "machine_max_acceleration_extruding"); append_option_line(optgroup, "machine_max_acceleration_retracting"); + if (m_supports_travel_acceleration) + append_option_line(optgroup, "machine_max_acceleration_travel"); optgroup = page->new_optgroup(L("Jerk limits")); for (const std::string &axis : axes) { @@ -2954,6 +2963,12 @@ void TabPrinter::update_fff() m_use_silent_mode = m_config->opt_bool("silent_mode"); } + bool supports_travel_acceleration = (m_config->option>("gcode_flavor")->value == gcfMarlinFirmware); + if (m_supports_travel_acceleration != supports_travel_acceleration) { + m_rebuild_kinematics_page = true; + m_supports_travel_acceleration = supports_travel_acceleration; + } + toggle_options(); } diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 8cbc6585a..9ccbcda28 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -425,6 +425,7 @@ class TabPrinter : public Tab private: bool m_has_single_extruder_MM_page = false; bool m_use_silent_mode = false; + bool m_supports_travel_acceleration = false; void append_option_line(ConfigOptionsGroupShp optgroup, const std::string opt_key); bool m_rebuild_kinematics_page = false; ogStaticText* m_machine_limits_description_line {nullptr};