ENH: add new way to set bed temperature

jira:NONE

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I99a9f67e9b13b2137ad371b22cf0999ccf9c096d
(cherry picked from commit 69c2947daf66eb0a6732b1b980c9b87f597c8da7)
This commit is contained in:
xun.zhang 2025-02-20 21:12:00 +08:00 committed by Noisyfox
parent 34d0855ba2
commit 6f5ea725dc
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

@ -22,6 +22,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

@ -3507,8 +3507,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);
@ -4186,7 +4193,7 @@ LayerResult GCode::process_layer(
}
}
if (! first_layer && ! m_second_layer_things_done) {
if (!first_layer && !m_second_layer_things_done) {
if (print.is_BBL_printer()) {
// BBS: open powerlost recovery
{
@ -4214,7 +4221,7 @@ 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 || m_ooze_prevention.enable) &&
extruder.id() != m_writer.filament()->id())
// In single extruder multi material mode, set the temperature for the current extruder only.
@ -4225,7 +4232,14 @@ 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

@ -915,7 +915,8 @@ static std::vector<std::string> s_Preset_printer_options {
"cooling_tube_retraction",
"cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "purge_in_prime_tower", "enable_filament_ramming",
"z_offset",
"disable_m73", "preferred_orientation", "emit_machine_limits_to_gcode", "pellet_modded_printer", "support_multi_bed_types", "default_bed_type", "bed_mesh_min","bed_mesh_max","bed_mesh_probe_distance", "adaptive_bed_mesh_margin", "enable_long_retraction_when_cut","long_retractions_when_cut","retraction_distances_when_cut"
"disable_m73", "preferred_orientation", "emit_machine_limits_to_gcode", "pellet_modded_printer", "support_multi_bed_types", "default_bed_type", "bed_mesh_min","bed_mesh_max","bed_mesh_probe_distance", "adaptive_bed_mesh_margin", "enable_long_retraction_when_cut","long_retractions_when_cut","retraction_distances_when_cut",
"bed_temperature_formula"
};
static std::vector<std::string> s_Preset_sla_print_options {

View file

@ -219,7 +219,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;
@ -2156,15 +2157,21 @@ void Print::process(long long *time_cost_with_cache, bool use_cache)
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();
@ -2197,6 +2204,12 @@ void Print::process(long long *time_cost_with_cache, bool use_cache)
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();
initial_extruder_id = tool_ordering.first_extruder();
print_object_instances_ordering = chain_print_object_instances(*this);

View file

@ -981,6 +981,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
*
@ -1131,6 +1137,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

@ -126,6 +126,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) },
@ -2218,6 +2224,17 @@ void PrintConfigDef::init_fff_params()
def->set_default_value(new ConfigOptionFloat { 0. });
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 G-code, so it is important and should be accurate.");

View file

@ -95,6 +95,12 @@ enum class WallInfillOrder {
Count,
};
enum class BedTempFormula {
btfFirstFilament,
btfHighestTemp,
count,
};
// BBS
enum class WallSequence {
InnerOuter,
@ -1235,6 +1241,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionIntsGroups, unprintable_filament_map))
//((ConfigOptionInts, filament_extruder_id))
((ConfigOptionStrings, filament_extruder_variant))
((ConfigOptionEnum<BedTempFormula>, bed_temperature_formula))
((ConfigOptionInts, physical_extruder_map))
// BBS
((ConfigOptionBool, scan_first_layer))

View file

@ -142,6 +142,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

@ -831,16 +831,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

@ -4117,6 +4117,7 @@ void TabPrinter::build_fff()
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("time_cost");