ENH: add new way to set bed temperature

jira:NONE

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I99a9f67e9b13b2137ad371b22cf0999ccf9c096d
This commit is contained in:
xun.zhang 2025-02-20 21:12:00 +08:00 committed by lane.wei
parent 4231da88fa
commit 69c2947daf
11 changed files with 125 additions and 20 deletions

View File

@ -11,6 +11,7 @@
"printer_variant": "0.4",
"best_object_pos": "0.3x0.5",
"bed_exclude_area": [],
"bed_temperature_formula": "by_highest_temp",
"default_filament_profile": [
"Bambu PLA Basic @BBL H2D"
],

View File

@ -23,6 +23,7 @@
],
"enable_long_retraction_when_cut" : "0",
"enable_pre_heating": "0",
"bed_temperature_formula" : "by_first_filament",
"hotend_cooling_rate": "2",
"hotend_heating_rate": "2",
"extruder_offset": [

View File

@ -3176,8 +3176,15 @@ void GCode::_print_first_layer_bed_temperature(GCodeOutputStream &file, Print &p
// Initial bed temperature based on the first extruder.
// BBS
std::vector<int> temps_per_bed;
int bed_temp = get_bed_temperature(first_printing_extruder_id, true, print.config().curr_bed_type);
int bed_temp = 0;
if (m_config.bed_temperature_formula.value == BedTempFormula::btfHighestTemp) {
for (auto fidx : print.get_slice_used_filaments(true)) {
bed_temp = std::max(bed_temp, get_bed_temperature(fidx, true, print.config().curr_bed_type));
}
}
else {
bed_temp = get_bed_temperature(first_printing_extruder_id, true, print.config().curr_bed_type);
}
// Is the bed temperature set by the provided custom G-code?
int temp_by_gcode = -1;
bool temp_set_by_gcode = custom_gcode_sets_temperature(gcode, 140, 190, false, temp_by_gcode);
@ -3690,7 +3697,7 @@ GCode::LayerResult GCode::process_layer(
gcode += m_writer.set_jerk_xy(m_config.initial_layer_jerk.value);
}
if (! first_layer && ! m_second_layer_things_done) {
if (!first_layer && !m_second_layer_things_done) {
//BBS: open powerlost recovery
{
if (print.is_BBL_Printer()) {
@ -3718,7 +3725,7 @@ GCode::LayerResult GCode::process_layer(
// Transition from 1st to 2nd layer. Adjust nozzle temperatures as prescribed by the nozzle dependent
// nozzle_temperature_initial_layer vs. temperature settings.
for (const Extruder &extruder : m_writer.extruders()) {
for (const Extruder& extruder : m_writer.extruders()) {
if (print.config().single_extruder_multi_material.value && extruder.id() != m_writer.filament()->id())
// In single extruder multi material mode, set the temperature for the current extruder only.
continue;
@ -3728,7 +3735,14 @@ GCode::LayerResult GCode::process_layer(
}
// BBS
int bed_temp = get_bed_temperature(first_extruder_id, false, print.config().curr_bed_type);
int bed_temp = 0;
if (m_config.bed_temperature_formula == BedTempFormula::btfHighestTemp) {
for (auto fidx : print.get_slice_used_filaments(false)) {
bed_temp = std::max(bed_temp, get_bed_temperature(fidx, false, m_config.curr_bed_type));
}
}
else
bed_temp = get_bed_temperature(first_extruder_id, false, m_config.curr_bed_type);
gcode += m_writer.set_bed_temperature(bed_temp);
// Mark the temperature transition from 1st to 2nd layer to be finished.
m_second_layer_things_done = true;

View File

@ -966,7 +966,8 @@ static std::vector<std::string> s_Preset_printer_options {
"printhost_cafile","printhost_port","printhost_authorization_type",
"printhost_user", "printhost_password", "printhost_ssl_ignore_revoke",
"use_relative_e_distances", "extruder_type","use_firmware_retraction",
"grab_length","machine_switch_extruder_time","hotend_cooling_rate","hotend_heating_rate","enable_pre_heating", "physical_extruder_map"
"grab_length","machine_switch_extruder_time","hotend_cooling_rate","hotend_heating_rate","enable_pre_heating", "physical_extruder_map",
"bed_temperature_formula"
};
static std::vector<std::string> s_Preset_sla_print_options {

View File

@ -200,7 +200,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"retraction_distances_when_cut",
"filament_long_retractions_when_cut",
"filament_retraction_distances_when_cut",
"grab_length"
"grab_length",
"bed_temperature_formula"
};
static std::unordered_set<std::string> steps_ignore;
@ -1910,15 +1911,21 @@ void Print::process(std::unordered_map<std::string, long long>* slice_time, bool
if (this->config().print_sequence == PrintSequence::ByObject) {
// Order object instances for sequential print.
print_object_instances_ordering = sort_object_instances_by_model_order(*this);
std::vector<unsigned int> first_layer_used_filaments;
std::vector<std::vector<unsigned int>> all_filaments;
for (print_object_instance_sequential_active = print_object_instances_ordering.begin(); print_object_instance_sequential_active != print_object_instances_ordering.end(); ++print_object_instance_sequential_active) {
tool_ordering = ToolOrdering(*(*print_object_instance_sequential_active)->print_object, initial_extruder_id);
for (const auto& layer_tool : tool_ordering.layer_tools()) {
all_filaments.emplace_back(layer_tool.extruders);
for (size_t idx = 0; idx < tool_ordering.layer_tools().size(); ++idx) {
auto& layer_filament = tool_ordering.layer_tools()[idx].extruders;
all_filaments.emplace_back(layer_filament);
if (idx == 0)
first_layer_used_filaments.insert(first_layer_used_filaments.end(), layer_filament.begin(), layer_filament.end());
}
}
sort_remove_duplicates(first_layer_used_filaments);
auto used_filaments = collect_sorted_used_filaments(all_filaments);
this->set_slice_used_filaments(first_layer_used_filaments,used_filaments);
auto physical_unprintables = this->get_physical_unprintable_filaments(used_filaments);
auto geometric_unprintables = this->get_geometric_unprintable_filaments();
std::vector<int>filament_maps = this->get_filament_maps();
@ -1951,6 +1958,12 @@ void Print::process(std::unordered_map<std::string, long long>* slice_time, bool
else {
tool_ordering = this->tool_ordering();
tool_ordering.assign_custom_gcodes(*this);
std::vector<unsigned int> first_layer_used_filaments;
if (!tool_ordering.layer_tools().empty())
first_layer_used_filaments = tool_ordering.layer_tools().front().extruders;
this->set_slice_used_filaments(first_layer_used_filaments, tool_ordering.all_extruders());
has_wipe_tower = this->has_wipe_tower() && tool_ordering.has_wipe_tower();
//BBS: have no single_extruder_multi_material_priming
#if 0

View File

@ -893,6 +893,12 @@ public:
void set_geometric_unprintable_filaments(const std::vector<std::set<int>> &unprintables_filament_ids) { m_geometric_unprintable_filaments = unprintables_filament_ids; }
std::vector<std::set<int>> get_geometric_unprintable_filaments() const { return m_geometric_unprintable_filaments;}
void set_slice_used_filaments(const std::vector<unsigned int> &first_layer_used_filaments, const std::vector<unsigned int> &used_filaments){
m_slice_used_filaments_first_layer = first_layer_used_filaments;
m_slice_used_filaments = used_filaments;
}
std::vector<unsigned int> get_slice_used_filaments(bool first_layer) const { return first_layer ? m_slice_used_filaments_first_layer : m_slice_used_filaments;}
/**
* @brief Determines the unprintable filaments for each extruder based on its physical attributes
*
@ -1027,6 +1033,9 @@ private:
bool m_support_used {false};
StatisticsByExtruderCount m_statistics_by_extruder_count;
std::vector<unsigned int> m_slice_used_filaments;
std::vector<unsigned int> m_slice_used_filaments_first_layer;
//BBS: plate's origin
Vec3d m_origin;
//BBS: modified_count

View File

@ -120,6 +120,12 @@ static t_config_enum_values s_keys_map_GCodeFlavor {
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(GCodeFlavor)
static t_config_enum_values s_keys_map_BedTempFormula {
{ "by_first_filament",int(BedTempFormula::btfFirstFilament) },
{ "by_highest_temp", int(BedTempFormula::btfHighestTemp)}
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(BedTempFormula)
static t_config_enum_values s_keys_map_FuzzySkinType {
{ "none", int(FuzzySkinType::None) },
{ "external", int(FuzzySkinType::External) },
@ -1757,6 +1763,17 @@ void PrintConfigDef::init_fff_params()
def = this->add("enable_pre_heating", coBool);
def->set_default_value(new ConfigOptionBool(false));
def = this->add("bed_temperature_formula", coEnum);
def->label = L("Bed temperature type");
def->tooltip = L("With this option enabled, you can print filaments with significant bed temperature differentials.");
def->mode = comDevelop;
def->enum_keys_map = &ConfigOptionEnum<BedTempFormula>::get_enum_values();
def->enum_values.push_back("first_filament");
def->enum_values.push_back("highest_filament");
def->enum_labels.push_back("First filament");
def->enum_labels.push_back("Highest temp filament");
def->set_default_value(new ConfigOptionEnum<BedTempFormula>(BedTempFormula::btfFirstFilament));
def = this->add("filament_diameter", coFloats);
def->label = L("Diameter");
def->tooltip = L("Filament diameter is used to calculate extrusion in gcode, so it's important and should be accurate");

View File

@ -82,6 +82,12 @@ enum class WallInfillOrder {
Count,
};
enum class BedTempFormula {
btfFirstFilament,
btfHighestTemp,
count,
};
// BBS
enum class WallSequence {
InnerOuter,
@ -1037,6 +1043,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionFloat, machine_unload_filament_time))
((ConfigOptionFloat, machine_switch_extruder_time))
((ConfigOptionBool, enable_pre_heating))
((ConfigOptionEnum<BedTempFormula>, bed_temperature_formula))
((ConfigOptionInts, physical_extruder_map))
((ConfigOptionFloat, hotend_cooling_rate))
((ConfigOptionFloat, hotend_heating_rate))

View File

@ -143,6 +143,29 @@ T get_max_element(const std::vector<T> &vec)
}
template <typename From, typename To>
std::vector<To> convert_vector(const std::vector<From>& src) {
std::vector<To> dst;
dst.reserve(src.size());
for (const auto& elem : src) {
if constexpr (std::is_signed_v<To>) {
if (elem > static_cast<From>(std::numeric_limits<To>::max())) {
throw std::overflow_error("Source value exceeds destination maximum");
}
if (elem < static_cast<From>(std::numeric_limits<To>::min())) {
throw std::underflow_error("Source value below destination minimum");
}
}
else {
if (elem < 0) {
throw std::invalid_argument("Negative value in source for unsigned destination");
}
}
dst.push_back(static_cast<To>(elem));
}
return dst;
}
// Set a path with GUI localization files.
void set_local_dir(const std::string &path);
// Return a full path to the localization directory.

View File

@ -856,16 +856,34 @@ wxBoxSizer *PreferencesDialog::create_item_checkbox(wxString title, wxWindow *pa
if (param == "enable_high_low_temp_mixed_printing") {
if (checkbox->GetValue()) {
MessageDialog msg_wingow(nullptr, _L("Printing with multiple filaments that have a large temperature difference can cause the extruder and nozzle to be blocked or dameged during printing.\nPlease enable with caution."),
_L("Warning"), wxICON_WARNING | wxYES | wxYES_DEFAULT | wxCANCEL | wxCENTRE, wxEmptyString,
_L("Click Wiki for help."), [](const wxString){
std::string language = wxGetApp().app_config->get("language");
wxString region = L"en";
if (language.find("zh") == 0) region = L"zh";
const wxString wiki_link = wxString::Format(L"https://wiki.bambulab.com/%s/filament-acc/filament/h2d-filament-config-limit", region);
wxGetApp().open_browser_with_warning_dialog(wiki_link);
});
if (msg_wingow.ShowModal() != wxID_YES) {
const wxString warning_title = _L("Bed Temperature Difference Warning");
const wxString warning_message =
_L("Using filaments with significantly different temperatures may cause:\n"
"• Extruder clogging\n"
"• Nozzle damage\n"
"• Layer adhesion issues\n\n"
"Continue with enabling this feature?");
std::function<void(const wxString&)> link_callback = [](const wxString&) {
const std::string lang_code = wxGetApp().app_config->get("language");
const wxString region = (lang_code.find("zh") != std::string::npos) ? L"zh" : L"en";
const wxString wiki_url = wxString::Format(
L"https://wiki.bambulab.com/%s/filament-acc/filament/h2d-filament-config-limit",
region
);
wxGetApp().open_browser_with_warning_dialog(wiki_url);
};
MessageDialog msg_dialog(
nullptr,
warning_message,
warning_title,
wxICON_WARNING | wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTRE,
wxEmptyString,
_L("Click Wiki for help."),
link_callback
);
if (msg_dialog.ShowModal() != wxID_YES) {
checkbox->SetValue(false);
app_config->set_bool(param, false);
app_config->save();

View File

@ -3706,6 +3706,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("bed_temperature_formula");
// 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");