ENH: add firmware retract for 3rd printers

1. Add firmware retract for 3rd printers. Use G10,G11

Github: #2319,#969

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: If3a3d591c249a4323a08045f3cc86ffb3e477d0e
This commit is contained in:
xun.zhang 2023-10-08 15:42:52 +08:00 committed by Lane.Wei
parent 7e0c831358
commit ae40f0fc4d
7 changed files with 87 additions and 21 deletions

View File

@ -4671,7 +4671,7 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li
gcode += m_writer.reset_e();
//BBS
if (m_writer.extruder()->retraction_length() > 0) {
if (m_writer.extruder()->retraction_length() > 0||m_config.use_firmware_retraction) {
// BBS: force to use normal lift for spiral vase mode
gcode += m_writer.lift(lift_type, m_spiral_vase != nullptr);
}

View File

@ -625,14 +625,22 @@ std::string GCodeWriter::retract_for_toolchange(bool before_wipe)
std::string GCodeWriter::_retract(double length, double restart_extra, const std::string &comment)
{
std::string gcode;
if (config.use_firmware_retraction)
length = 1;
if (double dE = m_extruder->retract(length, restart_extra); dE != 0) {
//BBS
GCodeG1Formatter w;
w.emit_e(m_extruder->E());
w.emit_f(m_extruder->retract_speed() * 60.);
//BBS
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
gcode = w.string();
//add firmware retraction
if (config.use_firmware_retraction) {
gcode = FLAVOR_IS(gcfMachinekit) ? "G22 ;retract" : "G10 ;retract \n";
}
else {
//BBS
GCodeG1Formatter w;
w.emit_e(m_extruder->E());
w.emit_f(m_extruder->retract_speed() * 60.);
//BBS
w.emit_comment(GCodeWriter::full_gcode_comment, comment);
gcode = w.string();
}
}
if (FLAVOR_IS(gcfMakerWare))
@ -649,14 +657,20 @@ std::string GCodeWriter::unretract()
gcode = "M101 ; extruder on\n";
if (double dE = m_extruder->unretract(); dE != 0) {
//BBS
// use G1 instead of G0 because G0 will blend the restart with the previous travel move
GCodeG1Formatter w;
w.emit_e(m_extruder->E());
w.emit_f(m_extruder->deretract_speed() * 60.);
//BBS
w.emit_comment(GCodeWriter::full_gcode_comment, " ; unretract");
gcode += w.string();
if (config.use_firmware_retraction) {
gcode += FLAVOR_IS(gcfMachinekit) ? "G23 ;unretract \n" : "G11 ;unretract \n";
gcode += reset_e();
}
else {
//BBS
// use G1 instead of G0 because G0 will blend the restart with the previous travel move
GCodeG1Formatter w;
w.emit_e(m_extruder->E());
w.emit_f(m_extruder->deretract_speed() * 60.);
//BBS
w.emit_comment(GCodeWriter::full_gcode_comment, " ; unretract");
gcode += w.string();
}
}
return gcode;

View File

@ -882,7 +882,7 @@ static std::vector<std::string> s_Preset_printer_options {
"print_host_webui",
"printhost_cafile","printhost_port","printhost_authorization_type",
"printhost_user", "printhost_password", "printhost_ssl_ignore_revoke",
"use_relative_e_distances", "extruder_type"
"use_relative_e_distances", "extruder_type","use_firmware_retraction"
};
static std::vector<std::string> s_Preset_sla_print_options {

View File

@ -171,7 +171,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"use_relative_e_distances",
"activate_air_filtration",
"during_print_exhaust_fan_speed",
"complete_print_exhaust_fan_speed"
"complete_print_exhaust_fan_speed",
"use_firmware_retraction"
};
static std::unordered_set<std::string> steps_ignore;

View File

@ -3378,6 +3378,12 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionBool(true));
def = this->add("use_firmware_retraction",coBool);
def->label = L("Use firmware retraction");
def->tooltip = L("Convert the retraction moves to G10 and G11 gcode");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionBool(false));
def = this->add("wipe", coBools);
def->label = L("Wipe while retracting");
def->tooltip = L("Move nozzle along the last extrusion path when retracting to clean leaked material on nozzle. "
@ -4881,6 +4887,24 @@ std::map<std::string, std::string> validate(const FullPrintConfig &cfg, bool und
error_message.emplace("bottom_shell_layers", L("invalid value ") + std::to_string(cfg.bottom_shell_layers));
}
std::set<GCodeFlavor>with_firmware_retraction_flavor = {
gcfSmoothie,
gcfRepRapSprinter,
gcfRepRapFirmware,
gcfMarlinLegacy,
gcfMarlinFirmware,
gcfMachinekit,
gcfRepetier,
gcfKlipper
};
if (cfg.use_firmware_retraction.value && with_firmware_retraction_flavor.count(cfg.gcode_flavor.value)==0)
error_message.emplace("gcode_flavor",L("--use-firmware-retraction is only supported by Marlin, Klipper, Smoothie, RepRapFirmware, Repetier and Machinekit firmware"));
if (cfg.use_firmware_retraction.value)
for (unsigned char wipe : cfg.wipe.values)
if (wipe)
error_message.emplace("wipe",L("--use-firmware-retraction is not compatible with --wipe"));
// --gcode-flavor
if (! print_config_def.get("gcode_flavor")->has_enum_value(cfg.gcode_flavor.serialize())) {
error_message.emplace("gcode_flavor", L("invalid value ") + cfg.gcode_flavor.serialize());

View File

@ -908,6 +908,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionFloat, travel_speed))
((ConfigOptionFloat, travel_speed_z))
((ConfigOptionBool, use_relative_e_distances))
((ConfigOptionBool, use_firmware_retraction))
((ConfigOptionBool, silent_mode))
((ConfigOptionString, machine_pause_gcode))
((ConfigOptionString, template_custom_gcode))

View File

@ -3314,6 +3314,7 @@ void TabPrinter::build_fff()
optgroup->append_single_option_line("scan_first_layer");
optgroup->append_single_option_line("use_relative_e_distances");
optgroup->append_single_option_line("use_firmware_retraction");
// optgroup->append_single_option_line("spaghetti_detector");
optgroup->append_single_option_line("machine_load_filament_time");
optgroup->append_single_option_line("machine_unload_filament_time");
@ -3907,6 +3908,7 @@ void TabPrinter::toggle_options()
toggle_option("printer_structure", !is_BBL_printer);
toggle_option("use_relative_e_distances", !is_BBL_printer);
toggle_option("support_chamber_temp_control",!is_BBL_printer);
toggle_option("use_firmware_retraction", !is_BBL_printer);
toggle_option("support_air_filtration",is_BBL_printer);
auto flavor = m_config->option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor")->value;
bool is_marlin_flavor = flavor == gcfMarlinLegacy || flavor == gcfMarlinFirmware;
@ -3933,13 +3935,16 @@ void TabPrinter::toggle_options()
for (auto el : {"extruder_type" , "nozzle_diameter", "extruder_offset"})
toggle_option(el, !is_BBL_printer, i);
bool use_firmware_retraction = m_config->opt_bool("use_firmware_retraction");
toggle_option("retract_length",!use_firmware_retraction, i);
// user can customize travel length if we have retraction length or we"re using
// firmware retraction
toggle_option("retraction_minimum_travel", have_retract_length, i);
toggle_option("retraction_minimum_travel", have_retract_length||use_firmware_retraction, i);
// user can customize other retraction options if retraction is enabled
//BBS
bool retraction = have_retract_length;
bool retraction = have_retract_length || use_firmware_retraction;
std::vector<std::string> vec = { "z_hop", "retract_when_changing_layer" };
for (auto el : vec)
toggle_option(el, retraction, i);
@ -3949,10 +3954,31 @@ void TabPrinter::toggle_options()
vec = { "retraction_speed", "deretraction_speed", "retract_before_wipe", "retract_restart_extra", "wipe", "wipe_distance" };
for (auto el : vec)
//BBS
toggle_option(el, retraction, i);
toggle_option(el, retraction && !use_firmware_retraction, i);
bool wipe = retraction && m_config->opt_bool("wipe", i);
toggle_option("retract_before_wipe", wipe, i);
if (use_firmware_retraction && wipe) {
//wxMessageDialog dialog(parent(),
MessageDialog dialog(parent(),
_(L("The Wipe option is not available when using the Firmware Retraction mode.\n"
"\nShall I disable it in order to enable Firmware Retraction?")),
_(L("Firmware Retraction")), wxICON_WARNING | wxYES | wxNO);
DynamicPrintConfig new_conf = *m_config;
if (dialog.ShowModal() == wxID_YES) {
auto wipe = static_cast<ConfigOptionBools*>(m_config->option("wipe")->clone());
for (size_t w = 0; w < wipe->values.size(); w++)
wipe->values[w] = false;
new_conf.set_key_value("wipe", wipe);
}
else {
new_conf.set_key_value("use_firmware_retraction", new ConfigOptionBool(false));
}
load_config(new_conf);
}
// BBS
toggle_option("wipe_distance", wipe, i);