ENH: add back use_relative_e for third party printer

Useless for BambuPrinter. But used by third party printer

Signed-off-by: salt.wei <salt.wei@bambulab.com>
Change-Id: Ib6a63e78816b25696c25952508f76c3d9221e363
This commit is contained in:
salt.wei 2023-06-21 15:51:01 +08:00 committed by Lane.Wei
parent 9bd0e3e85b
commit 766abf92fa
13 changed files with 31 additions and 23 deletions

View file

@ -22,7 +22,7 @@ double Extruder::extrude(double dE)
{
// BBS
if (m_share_extruder) {
if (RELATIVE_E_AXIS)
if (m_config->use_relative_e_distances)
m_share_E = 0.;
m_share_E += dE;
m_absolute_E += dE;
@ -30,7 +30,7 @@ double Extruder::extrude(double dE)
m_share_retracted -= dE;
} else {
// in case of relative E distances we always reset to 0 before any output
if (RELATIVE_E_AXIS)
if (m_config->use_relative_e_distances)
m_E = 0.;
m_E += dE;
m_absolute_E += dE;
@ -51,7 +51,7 @@ double Extruder::retract(double length, double restart_extra)
{
// BBS
if (m_share_extruder) {
if (RELATIVE_E_AXIS)
if (m_config->use_relative_e_distances)
m_share_E = 0.;
double to_retract = std::max(0., length - m_share_retracted);
if (to_retract > 0.) {
@ -62,7 +62,7 @@ double Extruder::retract(double length, double restart_extra)
return to_retract;
} else {
// in case of relative E distances we always reset to 0 before any output
if (RELATIVE_E_AXIS)
if (m_config->use_relative_e_distances)
m_E = 0.;
double to_retract = std::max(0., length - m_retracted);
if (to_retract > 0.) {

View file

@ -34,7 +34,7 @@ public:
double retract(double length, double restart_extra);
double unretract();
double E() const { return m_share_extruder ? m_share_E : m_E; }
void reset_E() { m_E = 0.; }
void reset_E() { m_E = 0.; m_share_E = 0.; }
double e_per_mm(double mm3_per_mm) const { return mm3_per_mm * m_e_per_mm3; }
double e_per_mm3() const { return m_e_per_mm3; }
// Used filament volume in mm^3.
@ -64,7 +64,7 @@ private:
GCodeConfig *m_config;
// Print-wide global ID of this extruder.
unsigned int m_id;
// Current state of the extruder axis, may be resetted if relative_e_axis.
// Current state of the extruder axis, may be resetted if use_relative_e_distance.
double m_E;
// Current state of the extruder tachometer, used to output the extruded_volume() and used_filament() statistics.
double m_absolute_E;

View file

@ -478,7 +478,7 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
new_filament_e_feedrate = new_filament_e_feedrate == 0 ? 100 : new_filament_e_feedrate;
config.set_key_value("max_layer_z", new ConfigOptionFloat(gcodegen.m_max_layer_z));
config.set_key_value("relative_e_axis", new ConfigOptionBool(RELATIVE_E_AXIS));
config.set_key_value("relative_e_axis", new ConfigOptionBool(full_config.use_relative_e_distances));
config.set_key_value("toolchange_count", new ConfigOptionInt((int)gcodegen.m_toolchange_count));
//BBS: fan speed is useless placeholer now, but we don't remove it to avoid
//slicing error in old change_filament_gcode in old 3MF
@ -3198,7 +3198,7 @@ GCode::LayerResult GCode::process_layer(
get_instance_name(&instance_to_print.print_object, inst.id) + "\n";
reset_e = true;
}
if (reset_e && !RELATIVE_E_AXIS)
if (reset_e && !m_config.use_relative_e_distances)
gcode += m_writer.reset_e(true);
// When starting a new object, use the external motion planner for the first travel move.
@ -3301,7 +3301,7 @@ GCode::LayerResult GCode::process_layer(
get_instance_name(&instance_to_print.print_object, inst.id) + "\n";
reset_e = true;
}
if (reset_e && !RELATIVE_E_AXIS)
if (reset_e && !m_config.use_relative_e_distances)
gcode += m_writer.reset_e(true);
}
}
@ -4483,7 +4483,7 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z)
dyn_config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index));
dyn_config.set_key_value("layer_z", new ConfigOptionFloat(print_z));
dyn_config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z));
dyn_config.set_key_value("relative_e_axis", new ConfigOptionBool(RELATIVE_E_AXIS));
dyn_config.set_key_value("relative_e_axis", new ConfigOptionBool(m_config.use_relative_e_distances));
dyn_config.set_key_value("toolchange_count", new ConfigOptionInt((int)m_toolchange_count));
//BBS: fan speed is useless placeholer now, but we don't remove it to avoid
//slicing error in old change_filament_gcode in old 3MF

View file

@ -401,7 +401,7 @@ std::vector<PerExtruderAdjustments> CoolingBuffer::parse_layer_gcode(const std::
}
if ((line.type & CoolingLine::TYPE_G92) == 0) {
//BBS: G0, G1, G2, G3. Calculate the duration.
if (RELATIVE_E_AXIS)
if (m_config.use_relative_e_distances.value)
// Reset extruder accumulator.
current_pos[3] = 0.f;
float dif[4];

View file

@ -54,7 +54,7 @@ std::string SpiralVase::process_layer(const std::string &gcode)
// For absolute extruder distances it will be switched off.
// Tapering the absolute extruder distances requires to process every extrusion value after the first transition
// layer.
bool transition = m_transition_layer && RELATIVE_E_AXIS;
bool transition = m_transition_layer && m_config.use_relative_e_distances.value;
float layer_height_factor = layer_height / total_layer_length;
float len = 0.f;
m_reader.parse_buffer(gcode, [&new_gcode, &z, total_layer_length, layer_height_factor, transition, &len]

View file

@ -82,7 +82,7 @@ const char* GCodeReader::parse_line_internal(const char *ptr, const char *end, G
}
}
if (gline.has(E) && RELATIVE_E_AXIS)
if (gline.has(E) && m_config.use_relative_e_distances)
m_position[E] = 0;
// Skip the rest of the line.

View file

@ -60,11 +60,9 @@ std::string GCodeWriter::preamble()
FLAVOR_IS(gcfSmoothie) ||
FLAVOR_IS(gcfKlipper))
{
if (RELATIVE_E_AXIS) {
gcode << "M83 ; only support relative e\n";
if (this->config.use_relative_e_distances) {
gcode << "M83 ; use relative distances for extrusion\n";
} else {
//BBS: don't support absolute e distance
assert(0);
gcode << "M82 ; use absolute distances for extrusion\n";
}
gcode << this->reset_e(true);
@ -243,7 +241,7 @@ std::string GCodeWriter::reset_e(bool force)
m_extruder->reset_E();
}
if (! RELATIVE_E_AXIS) {
if (!this->config.use_relative_e_distances) {
std::ostringstream gcode;
gcode << "G92 E0";
//BBS

View file

@ -836,7 +836,8 @@ static std::vector<std::string> s_Preset_printer_options {
"host_type", "print_host", "printhost_apikey",
"print_host_webui",
"printhost_cafile","printhost_port","printhost_authorization_type",
"printhost_user", "printhost_password", "printhost_ssl_ignore_revoke"
"printhost_user", "printhost_password", "printhost_ssl_ignore_revoke",
"use_relative_e_distances"
};
static std::vector<std::string> s_Preset_sla_print_options {

View file

@ -162,6 +162,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"inner_wall_acceleration",
"sparse_infill_acceleration",
"exclude_object",
"use_relative_e_distances"
};
static std::unordered_set<std::string> steps_ignore;
@ -973,6 +974,8 @@ StringObjectException Print::validate(StringObjectException *warning, Polygons*
return { ("Different nozzle diameters and different filament diameters is not allowed when prime tower is enabled.") };
}
if (! m_config.use_relative_e_distances)
return { ("The Wipe Tower is currently only supported with the relative extruder addressing (use_relative_e_distances=1).") };
if (m_config.ooze_prevention)
return { ("Ooze prevention is currently not supported with the prime tower enabled.") };

View file

@ -3158,6 +3158,13 @@ void PrintConfigDef::init_fff_params()
def->mode = comDevelop;
def->set_default_value(new ConfigOptionFloat(0.));
def = this->add("use_relative_e_distances", coBool);
def->label = L("Use relative E distances");
def->tooltip = L("If your firmware requires relative E values, check this, "
"otherwise leave it unchecked. Must use relative e distance for Bambu printer");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionBool(true));
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. "

View file

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

View file

@ -78,10 +78,6 @@ static constexpr double BRIDGE_INFILL_MARGIN = 1;
#define scale_(val) ((val) / SCALING_FACTOR)
#define unscale_(val) ((val) * SCALING_FACTOR)
//BBS: BBS only support relative E and can't been changed by user at the moment. because
//BBS need to support skip object when printing.
static constexpr bool RELATIVE_E_AXIS = 1;
#define SCALED_EPSILON scale_(EPSILON)
#ifndef UNUSED

View file

@ -3068,6 +3068,7 @@ void TabPrinter::build_fff()
optgroup = page->new_optgroup(L("Advanced"), L"param_advanced");
optgroup->append_single_option_line("gcode_flavor");
optgroup->append_single_option_line("scan_first_layer");
optgroup->append_single_option_line("use_relative_e_distances");
// 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");
@ -3632,6 +3633,7 @@ void TabPrinter::toggle_options()
toggle_option("single_extruder_multi_material", have_multiple_extruders);
//BBS: gcode_flavore of BBL printer can't be edited and changed
toggle_option("gcode_flavor", !is_BBL_printer);
toggle_option("use_relative_e_distances", !is_BBL_printer);
auto flavor = m_config->option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor")->value;
bool is_marlin_flavor = flavor == gcfMarlinLegacy || flavor == gcfMarlinFirmware;