From 151a76ee922de587e1888436196637ccf92ad6aa Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 30 Mar 2021 12:46:09 +0200 Subject: [PATCH 1/6] Duplicated Marlin firmware flavor to 'Marlin (legacy)' and 'Marlin Firmware' The two flavors should be identical after this commit, except that GCodeProcessor.cpp was not updated. This shall be done in a later step. --- src/libslic3r/GCode.cpp | 8 +++++--- src/libslic3r/GCode/WipeTower.cpp | 4 ++-- src/libslic3r/GCodeWriter.cpp | 4 +++- src/libslic3r/Print.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 5 ++++- src/libslic3r/PrintConfig.hpp | 3 ++- src/slic3r/GUI/Tab.cpp | 9 ++++++--- 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 0e464ee6d..ab2410104 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -784,7 +784,8 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re namespace DoExport { static void init_gcode_processor(const PrintConfig& config, GCodeProcessor& processor, bool& silent_time_estimator_enabled) { - silent_time_estimator_enabled = (config.gcode_flavor == gcfMarlin) && config.silent_mode; + silent_time_estimator_enabled = (config.gcode_flavor == gcfMarlin || config.gcode_flavor == gcfMarlinFirmware) + && config.silent_mode; processor.reset(); processor.apply_config(config); processor.enable_stealth_time_estimator(silent_time_estimator_enabled); @@ -1355,7 +1356,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu bbox_prime.offset(0.5f); bool overlap = bbox_prime.overlap(bbox_print); - if (print.config().gcode_flavor == gcfMarlin) { + if (print.config().gcode_flavor == gcfMarlin || print.config().gcode_flavor == gcfMarlinFirmware) { _write(file, this->retract()); _write(file, "M300 S800 P500\n"); // Beep for 500ms, tone 800Hz. if (overlap) { @@ -1558,7 +1559,8 @@ static bool custom_gcode_sets_temperature(const std::string &gcode, const int mc // Do not process this piece of G-code by the time estimator, it already knows the values through another sources. void GCode::print_machine_envelope(FILE *file, Print &print) { - if (print.config().gcode_flavor.value == gcfMarlin && print.config().machine_limits_usage.value == MachineLimitsUsage::EmitToGCode) { + if ((print.config().gcode_flavor.value == gcfMarlin || print.config().gcode_flavor.value == gcfMarlinFirmware) + && print.config().machine_limits_usage.value == MachineLimitsUsage::EmitToGCode) { fprintf(file, "M201 X%d Y%d Z%d E%d ; sets maximum accelerations, mm/sec^2\n", int(print.config().machine_max_acceleration_x.values.front() + 0.5), int(print.config().machine_max_acceleration_y.values.front() + 0.5), diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 8f104eab6..f59ab341c 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -342,7 +342,7 @@ public: WipeTowerWriter& speed_override_backup() { // This is only supported by Prusa at this point (https://github.com/prusa3d/PrusaSlicer/issues/3114) - if (m_gcode_flavor == gcfMarlin) + if (m_gcode_flavor == gcfMarlin || m_gcode_flavor == gcfMarlinFirmware) m_gcode += "M220 B\n"; return *this; } @@ -350,7 +350,7 @@ public: // Let the firmware restore the active speed override value. WipeTowerWriter& speed_override_restore() { - if (m_gcode_flavor == gcfMarlin) + if (m_gcode_flavor == gcfMarlin || m_gcode_flavor == gcfMarlinFirmware) m_gcode += "M220 R\n"; return *this; } diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 847398e69..233f07b43 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -20,7 +20,8 @@ void GCodeWriter::apply_print_config(const PrintConfig &print_config) this->config.apply(print_config, true); m_extrusion_axis = this->config.get_extrusion_axis(); m_single_extruder_multi_material = print_config.single_extruder_multi_material.value; - m_max_acceleration = std::lrint((print_config.gcode_flavor.value == gcfMarlin && print_config.machine_limits_usage.value == MachineLimitsUsage::EmitToGCode) ? + bool is_marlin = print_config.gcode_flavor.value == gcfMarlin || print_config.gcode_flavor.value == gcfMarlinFirmware; + m_max_acceleration = std::lrint((is_marlin && print_config.machine_limits_usage.value == MachineLimitsUsage::EmitToGCode) ? print_config.machine_max_acceleration_extruding.values.front() : 0); } @@ -49,6 +50,7 @@ std::string GCodeWriter::preamble() if (FLAVOR_IS(gcfRepRapSprinter) || FLAVOR_IS(gcfRepRapFirmware) || FLAVOR_IS(gcfMarlin) || + FLAVOR_IS(gcfMarlinFirmware) || FLAVOR_IS(gcfTeacup) || FLAVOR_IS(gcfRepetier) || FLAVOR_IS(gcfSmoothie)) diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 1801b658e..2cb2940e6 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1293,7 +1293,7 @@ std::string Print::validate(std::string* warning) const } if (m_config.gcode_flavor != gcfRepRapSprinter && m_config.gcode_flavor != gcfRepRapFirmware && - m_config.gcode_flavor != gcfRepetier && m_config.gcode_flavor != gcfMarlin) + m_config.gcode_flavor != gcfRepetier && m_config.gcode_flavor != gcfMarlin && m_config.gcode_flavor != gcfMarlinFirmware) return L("The Wipe Tower is currently only supported for the Marlin, RepRap/Sprinter, RepRapFirmware and Repetier G-code flavors."); if (! m_config.use_relative_e_distances) return L("The Wipe Tower is currently only supported with the relative extruder addressing (use_relative_e_distances=1)."); diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 2c6918acf..b795eaf20 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1103,6 +1103,7 @@ void PrintConfigDef::init_fff_params() def->enum_values.push_back("teacup"); def->enum_values.push_back("makerware"); def->enum_values.push_back("marlin"); + def->enum_values.push_back("marlinfirmware"); def->enum_values.push_back("sailfish"); def->enum_values.push_back("mach3"); def->enum_values.push_back("machinekit"); @@ -1113,7 +1114,8 @@ void PrintConfigDef::init_fff_params() def->enum_labels.push_back("Repetier"); def->enum_labels.push_back("Teacup"); def->enum_labels.push_back("MakerWare (MakerBot)"); - def->enum_labels.push_back("Marlin"); + def->enum_labels.push_back("Marlin (legacy)"); + def->enum_labels.push_back("Marlin Firmware"); def->enum_labels.push_back("Sailfish (MakerBot)"); def->enum_labels.push_back("Mach3/LinuxCNC"); def->enum_labels.push_back("Machinekit"); @@ -3631,6 +3633,7 @@ std::string FullPrintConfig::validate() this->gcode_flavor.value != gcfRepRapSprinter && this->gcode_flavor.value != gcfRepRapFirmware && this->gcode_flavor.value != gcfMarlin && + this->gcode_flavor.value != gcfMarlinFirmware && this->gcode_flavor.value != gcfMachinekit && this->gcode_flavor.value != gcfRepetier) return "--use-firmware-retraction is only supported by Marlin, Smoothie, RepRapFirmware, Repetier and Machinekit firmware"; diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 10f3b11d5..7f6ccf3c0 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -24,7 +24,7 @@ namespace Slic3r { enum GCodeFlavor : unsigned char { - gcfRepRapSprinter, gcfRepRapFirmware, gcfRepetier, gcfTeacup, gcfMakerWare, gcfMarlin, gcfSailfish, gcfMach3, gcfMachinekit, + gcfRepRapSprinter, gcfRepRapFirmware, gcfRepetier, gcfTeacup, gcfMakerWare, gcfMarlin, gcfMarlinFirmware, gcfSailfish, gcfMach3, gcfMachinekit, gcfSmoothie, gcfNoExtrusion, }; @@ -121,6 +121,7 @@ template<> inline const t_config_enum_values& ConfigOptionEnum::get keys_map["teacup"] = gcfTeacup; keys_map["makerware"] = gcfMakerWare; keys_map["marlin"] = gcfMarlin; + keys_map["marlinfirmware"] = gcfMarlinFirmware; keys_map["sailfish"] = gcfSailfish; keys_map["smoothie"] = gcfSmoothie; keys_map["mach3"] = gcfMach3; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 11c4875eb..1d10f3a8e 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2582,7 +2582,8 @@ PageShp TabPrinter::build_kinematics_page() void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/) { size_t n_before_extruders = 2; // Count of pages before Extruder pages - bool is_marlin_flavor = m_config->option>("gcode_flavor")->value == gcfMarlin; + auto flavor = m_config->option>("gcode_flavor")->value; + bool is_marlin_flavor = (flavor == gcfMarlin || flavor == gcfMarlinFirmware); /* ! Freeze/Thaw in this function is needed to avoid call OnPaint() for erased pages * and be cause of application crash, when try to change Preset in moment, @@ -2852,7 +2853,8 @@ void TabPrinter::toggle_options() if (m_active_page->title() == "General") { toggle_option("single_extruder_multi_material", have_multiple_extruders); - bool is_marlin_flavor = m_config->option>("gcode_flavor")->value == gcfMarlin; + auto flavor = m_config->option>("gcode_flavor")->value; + bool is_marlin_flavor = flavor == gcfMarlin || flavor == gcfMarlinFirmware; // Disable silent mode for non-marlin firmwares. toggle_option("silent_mode", is_marlin_flavor); } @@ -2920,7 +2922,8 @@ void TabPrinter::toggle_options() } if (m_active_page->title() == "Machine limits" && m_machine_limits_description_line) { - assert(m_config->option>("gcode_flavor")->value == gcfMarlin); + assert(m_config->option>("gcode_flavor")->value == gcfMarlin + || m_config->option>("gcode_flavor")->value == gcfMarlinFirmware); const auto *machine_limits_usage = m_config->option>("machine_limits_usage"); bool enabled = machine_limits_usage->value != MachineLimitsUsage::Ignore; bool silent_mode = m_config->opt_bool("silent_mode"); From f0e9ad46ece231ab76619331d6313b8df6425abf Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 30 Mar 2021 13:30:18 +0200 Subject: [PATCH 2/6] Renamed the gcfMarlin enum value to gcfMarlinLegacy so we never mistake it for the new one There should be no functional change. --- src/libslic3r/GCode.cpp | 6 +++--- src/libslic3r/GCode/GCodeProcessor.cpp | 18 +++++++++--------- src/libslic3r/GCode/WipeTower.cpp | 4 ++-- src/libslic3r/GCodeWriter.cpp | 4 ++-- src/libslic3r/Print.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 2 +- src/libslic3r/PrintConfig.hpp | 4 ++-- src/slic3r/GUI/Tab.cpp | 6 +++--- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index ab2410104..68fbe62d5 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -784,7 +784,7 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re namespace DoExport { static void init_gcode_processor(const PrintConfig& config, GCodeProcessor& processor, bool& silent_time_estimator_enabled) { - silent_time_estimator_enabled = (config.gcode_flavor == gcfMarlin || config.gcode_flavor == gcfMarlinFirmware) + silent_time_estimator_enabled = (config.gcode_flavor == gcfMarlinLegacy || config.gcode_flavor == gcfMarlinFirmware) && config.silent_mode; processor.reset(); processor.apply_config(config); @@ -1356,7 +1356,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu bbox_prime.offset(0.5f); bool overlap = bbox_prime.overlap(bbox_print); - if (print.config().gcode_flavor == gcfMarlin || print.config().gcode_flavor == gcfMarlinFirmware) { + if (print.config().gcode_flavor == gcfMarlinLegacy || print.config().gcode_flavor == gcfMarlinFirmware) { _write(file, this->retract()); _write(file, "M300 S800 P500\n"); // Beep for 500ms, tone 800Hz. if (overlap) { @@ -1559,7 +1559,7 @@ static bool custom_gcode_sets_temperature(const std::string &gcode, const int mc // Do not process this piece of G-code by the time estimator, it already knows the values through another sources. void GCode::print_machine_envelope(FILE *file, Print &print) { - if ((print.config().gcode_flavor.value == gcfMarlin || print.config().gcode_flavor.value == gcfMarlinFirmware) + if ((print.config().gcode_flavor.value == gcfMarlinLegacy || print.config().gcode_flavor.value == gcfMarlinFirmware) && print.config().machine_limits_usage.value == MachineLimitsUsage::EmitToGCode) { fprintf(file, "M201 X%d Y%d Z%d E%d ; sets maximum accelerations, mm/sec^2\n", int(print.config().machine_max_acceleration_x.values.front() + 0.5), diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 7c89cf467..be408c08f 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -823,7 +823,7 @@ void GCodeProcessor::apply_config(const PrintConfig& config) m_filament_diameters[i] = static_cast(config.filament_diameter.values[i]); } - if (m_flavor == gcfMarlin && config.machine_limits_usage.value != MachineLimitsUsage::Ignore) + if (m_flavor == gcfMarlinLegacy && config.machine_limits_usage.value != MachineLimitsUsage::Ignore) m_time_processor.machine_limits = reinterpret_cast(config); // Filament load / unload times are not specific to a firmware flavor. Let anybody use it if they find it useful. @@ -934,7 +934,7 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) } } - if (m_flavor == gcfMarlin) { + if (m_flavor == gcfMarlinLegacy) { const ConfigOptionFloats* machine_max_acceleration_x = config.option("machine_max_acceleration_x"); if (machine_max_acceleration_x != nullptr) m_time_processor.machine_limits.machine_max_acceleration_x.values = machine_max_acceleration_x->values; @@ -1646,23 +1646,23 @@ bool GCodeProcessor::process_cura_tags(const std::string_view comment) if (pos != comment.npos) { const std::string_view flavor = comment.substr(pos + tag.length()); if (flavor == "BFB") - m_flavor = gcfMarlin; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // << ??????????????????????? else if (flavor == "Mach3") m_flavor = gcfMach3; else if (flavor == "Makerbot") m_flavor = gcfMakerWare; else if (flavor == "UltiGCode") - m_flavor = gcfMarlin; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // << ??????????????????????? else if (flavor == "Marlin(Volumetric)") - m_flavor = gcfMarlin; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // << ??????????????????????? else if (flavor == "Griffin") - m_flavor = gcfMarlin; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // << ??????????????????????? else if (flavor == "Repetier") m_flavor = gcfRepetier; else if (flavor == "RepRap") m_flavor = gcfRepRapFirmware; else if (flavor == "Marlin") - m_flavor = gcfMarlin; + m_flavor = gcfMarlinLegacy; else BOOST_LOG_TRIVIAL(warning) << "GCodeProcessor found unknown flavor: " << flavor; @@ -2575,7 +2575,7 @@ void GCodeProcessor::process_M203(const GCodeReader::GCodeLine& line) // see http://reprap.org/wiki/G-code#M203:_Set_maximum_feedrate // http://smoothieware.org/supported-g-codes - float factor = (m_flavor == gcfMarlin || m_flavor == gcfSmoothie) ? 1.0f : MMMIN_TO_MMSEC; + float factor = (m_flavor == gcfMarlinLegacy || m_flavor == gcfSmoothie) ? 1.0f : MMMIN_TO_MMSEC; for (size_t i = 0; i < static_cast(PrintEstimatedTimeStatistics::ETimeMode::Count); ++i) { if (static_cast(i) == PrintEstimatedTimeStatistics::ETimeMode::Normal || @@ -2749,7 +2749,7 @@ void GCodeProcessor::process_T(const std::string_view command) int eid = 0; if (! parse_number(command.substr(1), eid) || eid < 0 || eid > 255) { // Specific to the MMU2 V2 (see https://www.help.prusa3d.com/en/article/prusa-specific-g-codes_112173): - if (m_flavor == gcfMarlin && (command == "Tx" || command == "Tc" || command == "T?")) + if (m_flavor == gcfMarlinLegacy && (command == "Tx" || command == "Tc" || command == "T?")) return; // T-1 is a valid gcode line for RepRap Firmwares (used to deselects all tools) see https://github.com/prusa3d/PrusaSlicer/issues/5677 diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index f59ab341c..10c68d076 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -342,7 +342,7 @@ public: WipeTowerWriter& speed_override_backup() { // This is only supported by Prusa at this point (https://github.com/prusa3d/PrusaSlicer/issues/3114) - if (m_gcode_flavor == gcfMarlin || m_gcode_flavor == gcfMarlinFirmware) + if (m_gcode_flavor == gcfMarlinLegacy || m_gcode_flavor == gcfMarlinFirmware) m_gcode += "M220 B\n"; return *this; } @@ -350,7 +350,7 @@ public: // Let the firmware restore the active speed override value. WipeTowerWriter& speed_override_restore() { - if (m_gcode_flavor == gcfMarlin || m_gcode_flavor == gcfMarlinFirmware) + if (m_gcode_flavor == gcfMarlinLegacy || m_gcode_flavor == gcfMarlinFirmware) m_gcode += "M220 R\n"; return *this; } diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 233f07b43..5bf0a30da 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -20,7 +20,7 @@ void GCodeWriter::apply_print_config(const PrintConfig &print_config) this->config.apply(print_config, true); m_extrusion_axis = this->config.get_extrusion_axis(); m_single_extruder_multi_material = print_config.single_extruder_multi_material.value; - bool is_marlin = print_config.gcode_flavor.value == gcfMarlin || print_config.gcode_flavor.value == gcfMarlinFirmware; + bool is_marlin = print_config.gcode_flavor.value == gcfMarlinLegacy || print_config.gcode_flavor.value == gcfMarlinFirmware; m_max_acceleration = std::lrint((is_marlin && print_config.machine_limits_usage.value == MachineLimitsUsage::EmitToGCode) ? print_config.machine_max_acceleration_extruding.values.front() : 0); } @@ -49,7 +49,7 @@ std::string GCodeWriter::preamble() } if (FLAVOR_IS(gcfRepRapSprinter) || FLAVOR_IS(gcfRepRapFirmware) || - FLAVOR_IS(gcfMarlin) || + FLAVOR_IS(gcfMarlinLegacy) || FLAVOR_IS(gcfMarlinFirmware) || FLAVOR_IS(gcfTeacup) || FLAVOR_IS(gcfRepetier) || diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 2cb2940e6..ff433a48f 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1293,7 +1293,7 @@ std::string Print::validate(std::string* warning) const } if (m_config.gcode_flavor != gcfRepRapSprinter && m_config.gcode_flavor != gcfRepRapFirmware && - m_config.gcode_flavor != gcfRepetier && m_config.gcode_flavor != gcfMarlin && m_config.gcode_flavor != gcfMarlinFirmware) + m_config.gcode_flavor != gcfRepetier && m_config.gcode_flavor != gcfMarlinLegacy && m_config.gcode_flavor != gcfMarlinFirmware) return L("The Wipe Tower is currently only supported for the Marlin, RepRap/Sprinter, RepRapFirmware and Repetier G-code flavors."); if (! m_config.use_relative_e_distances) return L("The Wipe Tower is currently only supported with the relative extruder addressing (use_relative_e_distances=1)."); diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index b795eaf20..9c6ac2662 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3632,7 +3632,7 @@ std::string FullPrintConfig::validate() this->gcode_flavor.value != gcfSmoothie && this->gcode_flavor.value != gcfRepRapSprinter && this->gcode_flavor.value != gcfRepRapFirmware && - this->gcode_flavor.value != gcfMarlin && + this->gcode_flavor.value != gcfMarlinLegacy && this->gcode_flavor.value != gcfMarlinFirmware && this->gcode_flavor.value != gcfMachinekit && this->gcode_flavor.value != gcfRepetier) diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 7f6ccf3c0..4f94f8859 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -24,7 +24,7 @@ namespace Slic3r { enum GCodeFlavor : unsigned char { - gcfRepRapSprinter, gcfRepRapFirmware, gcfRepetier, gcfTeacup, gcfMakerWare, gcfMarlin, gcfMarlinFirmware, gcfSailfish, gcfMach3, gcfMachinekit, + gcfRepRapSprinter, gcfRepRapFirmware, gcfRepetier, gcfTeacup, gcfMakerWare, gcfMarlinLegacy, gcfMarlinFirmware, gcfSailfish, gcfMach3, gcfMachinekit, gcfSmoothie, gcfNoExtrusion, }; @@ -120,7 +120,7 @@ template<> inline const t_config_enum_values& ConfigOptionEnum::get keys_map["repetier"] = gcfRepetier; keys_map["teacup"] = gcfTeacup; keys_map["makerware"] = gcfMakerWare; - keys_map["marlin"] = gcfMarlin; + keys_map["marlin"] = gcfMarlinLegacy; keys_map["marlinfirmware"] = gcfMarlinFirmware; keys_map["sailfish"] = gcfSailfish; keys_map["smoothie"] = gcfSmoothie; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 1d10f3a8e..915fa5267 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2583,7 +2583,7 @@ void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/) { size_t n_before_extruders = 2; // Count of pages before Extruder pages auto flavor = m_config->option>("gcode_flavor")->value; - bool is_marlin_flavor = (flavor == gcfMarlin || flavor == gcfMarlinFirmware); + bool is_marlin_flavor = (flavor == gcfMarlinLegacy || flavor == gcfMarlinFirmware); /* ! Freeze/Thaw in this function is needed to avoid call OnPaint() for erased pages * and be cause of application crash, when try to change Preset in moment, @@ -2854,7 +2854,7 @@ void TabPrinter::toggle_options() toggle_option("single_extruder_multi_material", have_multiple_extruders); auto flavor = m_config->option>("gcode_flavor")->value; - bool is_marlin_flavor = flavor == gcfMarlin || flavor == gcfMarlinFirmware; + bool is_marlin_flavor = flavor == gcfMarlinLegacy || flavor == gcfMarlinFirmware; // Disable silent mode for non-marlin firmwares. toggle_option("silent_mode", is_marlin_flavor); } @@ -2922,7 +2922,7 @@ void TabPrinter::toggle_options() } if (m_active_page->title() == "Machine limits" && m_machine_limits_description_line) { - assert(m_config->option>("gcode_flavor")->value == gcfMarlin + assert(m_config->option>("gcode_flavor")->value == gcfMarlinLegacy || m_config->option>("gcode_flavor")->value == gcfMarlinFirmware); const auto *machine_limits_usage = m_config->option>("machine_limits_usage"); bool enabled = machine_limits_usage->value != MachineLimitsUsage::Ignore; From 8c89bf748bb3f8b5a783819f00b5a8f0adf59d9d Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 30 Mar 2021 13:37:49 +0200 Subject: [PATCH 3/6] Implemented new acceleration control behaviour for the new Marlin firmware flavor: - show extra travel acceleration settings in 'Machine limits' page in Printer Settings when the new firmware flavor is selected - updated tooltips on the config values (they were basically wrong even in the current version) - 'Marlin (legacy)' firmware flavor behaviour should not change: it exports M204 Pa Rb Ta (where a, b are the values from machine limits) at the beginning of gcode and it uses M204 S... for feature type dependent acceleration settings (legacy variant of M204 P.. T..) - new Marlin Firmware exports M204 Pa Rb Tc (where a,b,c are the values from machine limits). Feature type dependent acceleration is set using M204 P..., not overriding the travel acceleration. --- src/libslic3r/GCode.cpp | 12 +++++++++++- src/libslic3r/GCodeWriter.cpp | 8 ++++++-- src/libslic3r/Preset.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 23 ++++++++++++++++++----- src/libslic3r/PrintConfig.hpp | 7 +++++-- src/slic3r/GUI/Tab.cpp | 15 +++++++++++++++ src/slic3r/GUI/Tab.hpp | 1 + 7 files changed, 57 insertions(+), 11 deletions(-) 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}; From 52af90ed8f9f8ab2c8a306da42c3909e133dba88 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 31 Mar 2021 12:34:28 +0200 Subject: [PATCH 4/6] GCodeProcessor use new flavor gcfMarlinFirmware --- src/libslic3r/GCode/GCodeProcessor.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index be408c08f..0a10ec4cc 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -823,7 +823,7 @@ void GCodeProcessor::apply_config(const PrintConfig& config) m_filament_diameters[i] = static_cast(config.filament_diameter.values[i]); } - if (m_flavor == gcfMarlinLegacy && config.machine_limits_usage.value != MachineLimitsUsage::Ignore) + if ((m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) && config.machine_limits_usage.value != MachineLimitsUsage::Ignore) m_time_processor.machine_limits = reinterpret_cast(config); // Filament load / unload times are not specific to a firmware flavor. Let anybody use it if they find it useful. @@ -934,7 +934,7 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) } } - if (m_flavor == gcfMarlinLegacy) { + if (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) { const ConfigOptionFloats* machine_max_acceleration_x = config.option("machine_max_acceleration_x"); if (machine_max_acceleration_x != nullptr) m_time_processor.machine_limits.machine_max_acceleration_x.values = machine_max_acceleration_x->values; @@ -991,6 +991,10 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) if (machine_max_acceleration_retracting != nullptr) m_time_processor.machine_limits.machine_max_acceleration_retracting.values = machine_max_acceleration_retracting->values; + const ConfigOptionFloats* machine_max_acceleration_travel = config.option("machine_max_acceleration_travel"); + if (machine_max_acceleration_travel != nullptr) + m_time_processor.machine_limits.machine_max_acceleration_travel.values = machine_max_acceleration_travel->values; + const ConfigOptionFloats* machine_min_extruding_rate = config.option("machine_min_extruding_rate"); if (machine_min_extruding_rate != nullptr) m_time_processor.machine_limits.machine_min_extruding_rate.values = machine_min_extruding_rate->values; @@ -1646,17 +1650,17 @@ bool GCodeProcessor::process_cura_tags(const std::string_view comment) if (pos != comment.npos) { const std::string_view flavor = comment.substr(pos + tag.length()); if (flavor == "BFB") - m_flavor = gcfMarlinLegacy; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // is this correct ? else if (flavor == "Mach3") m_flavor = gcfMach3; else if (flavor == "Makerbot") m_flavor = gcfMakerWare; else if (flavor == "UltiGCode") - m_flavor = gcfMarlinLegacy; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // is this correct ? else if (flavor == "Marlin(Volumetric)") - m_flavor = gcfMarlinLegacy; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // is this correct ? else if (flavor == "Griffin") - m_flavor = gcfMarlinLegacy; // << ??????????????????????? + m_flavor = gcfMarlinLegacy; // is this correct ? else if (flavor == "Repetier") m_flavor = gcfRepetier; else if (flavor == "RepRap") @@ -2575,7 +2579,7 @@ void GCodeProcessor::process_M203(const GCodeReader::GCodeLine& line) // see http://reprap.org/wiki/G-code#M203:_Set_maximum_feedrate // http://smoothieware.org/supported-g-codes - float factor = (m_flavor == gcfMarlinLegacy || m_flavor == gcfSmoothie) ? 1.0f : MMMIN_TO_MMSEC; + float factor = (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware || m_flavor == gcfSmoothie) ? 1.0f : MMMIN_TO_MMSEC; for (size_t i = 0; i < static_cast(PrintEstimatedTimeStatistics::ETimeMode::Count); ++i) { if (static_cast(i) == PrintEstimatedTimeStatistics::ETimeMode::Normal || @@ -2749,7 +2753,7 @@ void GCodeProcessor::process_T(const std::string_view command) int eid = 0; if (! parse_number(command.substr(1), eid) || eid < 0 || eid > 255) { // Specific to the MMU2 V2 (see https://www.help.prusa3d.com/en/article/prusa-specific-g-codes_112173): - if (m_flavor == gcfMarlinLegacy && (command == "Tx" || command == "Tc" || command == "T?")) + if ((m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) && (command == "Tx" || command == "Tc" || command == "T?")) return; // T-1 is a valid gcode line for RepRap Firmwares (used to deselects all tools) see https://github.com/prusa3d/PrusaSlicer/issues/5677 From 9b2d9fb01a9f5189041c07fba8a419ad424e3c0b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 31 Mar 2021 15:20:11 +0200 Subject: [PATCH 5/6] GCodeProcessor added travel acceleration --- src/libslic3r/GCode/GCodeProcessor.cpp | 39 +++++++++++++++++++++----- src/libslic3r/GCode/GCodeProcessor.hpp | 7 ++++- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 0a10ec4cc..74831e36e 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -26,6 +26,7 @@ static const float INCHES_TO_MM = 25.4f; static const float MMMIN_TO_MMSEC = 1.0f / 60.0f; static const float DEFAULT_ACCELERATION = 1500.0f; // Prusa Firmware 1_75mm_MK2 +static const float DEFAULT_TRAVEL_ACCELERATION = 1250.0f; namespace Slic3r { @@ -190,6 +191,8 @@ void GCodeProcessor::TimeMachine::reset() enabled = false; acceleration = 0.0f; max_acceleration = 0.0f; + travel_acceleration = 0.0f; + max_travel_acceleration = 0.0f; extrude_factor_override_percentage = 1.0f; time = 0.0f; #if ENABLE_EXTENDED_M73_LINES @@ -842,6 +845,9 @@ void GCodeProcessor::apply_config(const PrintConfig& config) float max_acceleration = get_option_value(m_time_processor.machine_limits.machine_max_acceleration_extruding, i); m_time_processor.machines[i].max_acceleration = max_acceleration; m_time_processor.machines[i].acceleration = (max_acceleration > 0.0f) ? max_acceleration : DEFAULT_ACCELERATION; + float max_travel_acceleration = get_option_value(m_time_processor.machine_limits.machine_max_acceleration_travel, i); + m_time_processor.machines[i].max_travel_acceleration = max_travel_acceleration; + m_time_processor.machines[i].travel_acceleration = (max_travel_acceleration > 0.0f) ? max_travel_acceleration : DEFAULT_TRAVEL_ACCELERATION; } m_time_processor.export_remaining_time_enabled = config.remaining_times.value; @@ -1008,6 +1014,9 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) float max_acceleration = get_option_value(m_time_processor.machine_limits.machine_max_acceleration_extruding, i); m_time_processor.machines[i].max_acceleration = max_acceleration; m_time_processor.machines[i].acceleration = (max_acceleration > 0.0f) ? max_acceleration : DEFAULT_ACCELERATION; + float max_travel_acceleration = get_option_value(m_time_processor.machine_limits.machine_max_acceleration_travel, i); + m_time_processor.machines[i].max_travel_acceleration = max_travel_acceleration; + m_time_processor.machines[i].travel_acceleration = (max_travel_acceleration > 0.0f) ? max_travel_acceleration : DEFAULT_TRAVEL_ACCELERATION; } if (m_time_processor.machine_limits.machine_max_acceleration_x.values.size() > 1) @@ -2230,9 +2239,11 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) } // calculates block acceleration - float acceleration = is_extrusion_only_move(delta_pos) ? - get_retract_acceleration(static_cast(i)) : - get_acceleration(static_cast(i)); + float acceleration = + (type == EMoveType::Travel) ? get_travel_acceleration(static_cast(i)) : + (is_extrusion_only_move(delta_pos) ? + get_retract_acceleration(static_cast(i)) : + get_acceleration(static_cast(i))); for (unsigned char a = X; a <= E; ++a) { float axis_max_acceleration = get_axis_max_acceleration(static_cast(i), static_cast(a)); @@ -2619,11 +2630,9 @@ void GCodeProcessor::process_M204(const GCodeReader::GCodeLine& line) set_acceleration(static_cast(i), value); if (line.has_value('R', value)) set_option_value(m_time_processor.machine_limits.machine_max_acceleration_retracting, i, value); - if (line.has_value('T', 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(static_cast(i), value); } } } @@ -2894,6 +2903,22 @@ void GCodeProcessor::set_acceleration(PrintEstimatedTimeStatistics::ETimeMode mo } } +float GCodeProcessor::get_travel_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode) const +{ + size_t id = static_cast(mode); + return (id < m_time_processor.machines.size()) ? m_time_processor.machines[id].travel_acceleration : DEFAULT_TRAVEL_ACCELERATION; +} + +void GCodeProcessor::set_travel_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode, float value) +{ + size_t id = static_cast(mode); + if (id < m_time_processor.machines.size()) { + m_time_processor.machines[id].travel_acceleration = (m_time_processor.machines[id].max_travel_acceleration == 0.0f) ? value : + // Clamp the acceleration with the maximum. + std::min(value, m_time_processor.machines[id].max_travel_acceleration); + } +} + float GCodeProcessor::get_filament_load_time(size_t extruder_id) { return (m_time_processor.filament_load_times.empty() || m_time_processor.extruder_unloaded) ? diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 96e216020..cf55bf86e 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -251,6 +251,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 extrude_factor_override_percentage; float time; // s #if ENABLE_EXTENDED_M73_LINES @@ -668,7 +671,9 @@ namespace Slic3r { float get_axis_max_jerk(PrintEstimatedTimeStatistics::ETimeMode mode, Axis axis) const; float get_retract_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode) const; float get_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode) const; - void set_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode, float value); + void set_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode, float value); + float get_travel_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode) const; + void set_travel_acceleration(PrintEstimatedTimeStatistics::ETimeMode mode, float value); float get_filament_load_time(size_t extruder_id); float get_filament_unload_time(size_t extruder_id); From 9660d35f8c5baba0500f7bb54387f1efee84018e Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 1 Apr 2021 11:30:41 +0200 Subject: [PATCH 6/6] An attempt to fix time estimates for 'Marlin (legacy)' flavor Old M204 S sets both printing and travel accelerations, which must be accounted for now when the latter was separated. --- src/libslic3r/GCode/GCodeProcessor.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 74831e36e..7a1790971 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -826,8 +826,13 @@ void GCodeProcessor::apply_config(const PrintConfig& config) m_filament_diameters[i] = static_cast(config.filament_diameter.values[i]); } - if ((m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) && config.machine_limits_usage.value != MachineLimitsUsage::Ignore) + if ((m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) && config.machine_limits_usage.value != MachineLimitsUsage::Ignore) { m_time_processor.machine_limits = reinterpret_cast(config); + if (m_flavor == gcfMarlinLegacy) { + // Legacy Marlin does not have separate travel acceleration, it uses the 'extruding' value instead. + m_time_processor.machine_limits.machine_max_acceleration_travel = m_time_processor.machine_limits.machine_max_acceleration_extruding; + } + } // Filament load / unload times are not specific to a firmware flavor. Let anybody use it if they find it useful. // As of now the fields are shown at the UI dialog in the same combo box as the ramming values, so they @@ -997,10 +1002,15 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) if (machine_max_acceleration_retracting != nullptr) m_time_processor.machine_limits.machine_max_acceleration_retracting.values = machine_max_acceleration_retracting->values; - const ConfigOptionFloats* machine_max_acceleration_travel = config.option("machine_max_acceleration_travel"); + + // Legacy Marlin does not have separate travel acceleration, it uses the 'extruding' value instead. + const ConfigOptionFloats* machine_max_acceleration_travel = config.option(m_flavor == gcfMarlinLegacy + ? "machine_max_acceleration_extruding" + : "machine_max_acceleration_travel"); if (machine_max_acceleration_travel != nullptr) m_time_processor.machine_limits.machine_max_acceleration_travel.values = machine_max_acceleration_travel->values; + const ConfigOptionFloats* machine_min_extruding_rate = config.option("machine_min_extruding_rate"); if (machine_min_extruding_rate != nullptr) m_time_processor.machine_limits.machine_min_extruding_rate.values = machine_min_extruding_rate->values; @@ -2617,10 +2627,11 @@ void GCodeProcessor::process_M204(const GCodeReader::GCodeLine& line) if (static_cast(i) == PrintEstimatedTimeStatistics::ETimeMode::Normal || m_time_processor.machine_envelope_processing_enabled) { if (line.has_value('S', value)) { - // Legacy acceleration format. This format is used by the legacy Marlin, MK2 or MK3 firmware, - // and it is also generated by Slic3r to control acceleration per extrusion type - // (there is a separate acceleration settings in Slicer for perimeter, first layer etc). + // Legacy acceleration format. This format is used by the legacy Marlin, MK2 or MK3 firmware + // It is also generated by PrusaSlicer to control acceleration per extrusion type + // (perimeters, first layer etc) when 'Marlin (legacy)' flavor is used. set_acceleration(static_cast(i), value); + set_travel_acceleration(static_cast(i), value); if (line.has_value('T', value)) set_option_value(m_time_processor.machine_limits.machine_max_acceleration_retracting, i, value); }