FIX: display the minimum flush data

1. Use the minimum flush between nozzle volume and flush in datalist
2. Add a new param to decide the datalist to use

github:7445

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: Id87c98ca5069e7b328974d641d7a81dfbf9c50a0
(cherry picked from commit 2be29b784727330732170b5c2ff0ba9d5e79d82f)
This commit is contained in:
xun.zhang
2025-07-03 17:14:34 +08:00
committed by Noisyfox
parent cf9a38bbc6
commit bc02e48dc0
13 changed files with 69 additions and 65 deletions

View File

@@ -39,24 +39,15 @@ static float DeltaHS_BBS(float h1, float s1, float v1, float h2, float s2, float
return std::min(1.2f, dxy);
}
FlushVolCalculator::FlushVolCalculator(int min, int max, bool is_multi_extruder, NozzleVolumeType volume_type, float multiplier)
:m_min_flush_vol(min), m_max_flush_vol(max), m_multiplier(multiplier)
FlushVolCalculator::FlushVolCalculator(int min, int max, int flush_dataset, float multiplier)
:m_min_flush_vol(min), m_max_flush_vol(max), m_multiplier(multiplier), m_flush_dataset(flush_dataset)
{
if (!is_multi_extruder) {
m_machine_type = FlushPredict::Standard;
return;
}
if (volume_type == NozzleVolumeType::nvtHighFlow)
m_machine_type = FlushPredict::DualHighFlow;
else
m_machine_type = FlushPredict::DualStandard;
}
bool FlushVolCalculator::get_flush_vol_from_data(unsigned char src_r, unsigned char src_g, unsigned char src_b,
unsigned char dst_r, unsigned char dst_g, unsigned char dst_b, float& flush)
{
GenericFlushPredictor pd(m_machine_type);
GenericFlushPredictor pd(m_flush_dataset);
FlushPredict::RGBColor src(src_r, src_g, src_b);
FlushPredict::RGBColor dst(dst_r, dst_g, dst_b);
@@ -67,7 +58,7 @@ int FlushVolCalculator::calc_flush_vol_rgb(unsigned char src_r, unsigned char sr
unsigned char dst_r, unsigned char dst_g, unsigned char dst_b)
{
float flush_volume;
if(m_machine_type == FlushPredict::Standard && get_flush_vol_from_data(src_r, src_g, src_b, dst_r, dst_g, dst_b, flush_volume))
if(m_flush_dataset == 0 && get_flush_vol_from_data(src_r, src_g, src_b, dst_r, dst_g, dst_b, flush_volume))
return flush_volume;
float src_r_f, src_g_f, src_b_f, dst_r_f, dst_g_f, dst_b_f;
float from_hsv_h, from_hsv_s, from_hsv_v;
@@ -119,7 +110,7 @@ int FlushVolCalculator::calc_flush_vol(unsigned char src_a, unsigned char src_r,
}
float flush_volume;
if(m_machine_type != FlushPredict::Standard && get_flush_vol_from_data(src_r, src_g, src_b, dst_r, dst_g, dst_b, flush_volume))
if(m_flush_dataset != 0 && get_flush_vol_from_data(src_r, src_g, src_b, dst_r, dst_g, dst_b, flush_volume))
return std::min((int)flush_volume, m_max_flush_vol);
@@ -129,7 +120,7 @@ int FlushVolCalculator::calc_flush_vol(unsigned char src_a, unsigned char src_r,
constexpr float light_color_thres = 75.f/255.f;
bool is_from_dark = get_luminance(src_r, src_g, src_b) > dark_color_thres;
bool is_to_light = get_luminance(dst_r, dst_g, dst_b) < light_color_thres;
if (m_machine_type != FlushPredict::Standard && is_from_dark && is_to_light)
if (m_flush_dataset != 0 && is_from_dark && is_to_light)
flush_volume *= 1.3;
flush_volume += m_min_flush_vol;

View File

@@ -15,7 +15,7 @@ extern const int g_max_flush_volume;
class FlushVolCalculator
{
public:
FlushVolCalculator(int min, int max, bool is_multi_extruder, NozzleVolumeType volume_type, float multiplier = 1.0f);
FlushVolCalculator(int min, int max, int flush_dataset, float multiplier = 1.0f);
~FlushVolCalculator()
{
}
@@ -33,7 +33,7 @@ private:
int m_min_flush_vol;
int m_max_flush_vol;
float m_multiplier;
FlushPredict::FlushMachineType m_machine_type;
int m_flush_dataset;
};

View File

@@ -173,6 +173,7 @@ class FlushVolPredictor
public:
bool predict(const RGB& from,const RGB& to , float& flush);
FlushVolPredictor(const std::string& data_file);
int get_min_flush_volume();
FlushVolPredictor() = default;
private:
uint64_t generate_hash_key(const RGB& from, const RGB& to);
@@ -181,6 +182,13 @@ private:
bool m_valid{ false };
};
int FlushVolPredictor::get_min_flush_volume()
{
if(!m_valid)
return std::numeric_limits<int>::max();
return static_cast<int>(std::min_element(m_flush_map.begin(), m_flush_map.end(), [](const auto& a, const auto& b) {return a.second < b.second; })->second);
}
uint64_t FlushVolPredictor::generate_hash_key(const RGB& from, const RGB& to)
{
uint64_t key = 0;
@@ -299,24 +307,24 @@ bool FlushVolPredictor::predict(const RGB& from, const RGB& to, float& flush)
}
static std::unordered_map<FlushPredict::FlushMachineType, FlushVolPredictor> predictor_instances;
static std::unordered_map<int, FlushVolPredictor> predictor_instances;
GenericFlushPredictor::GenericFlushPredictor(const MachineType& type)
GenericFlushPredictor::GenericFlushPredictor(const int dataset_value)
{
auto iter = predictor_instances.find(type);
auto iter = predictor_instances.find(dataset_value);
if (iter != predictor_instances.end())
predictor = &iter->second;
else {
std::string path = Slic3r::resources_dir();
if (type == MachineType::DualHighFlow)
path += "/flush/flush_data_dual_highflow.txt";
else if (type == MachineType::DualStandard)
path += "/flush/flush_data_dual_standard.txt";
else
if (dataset_value == 0)
path += "/flush/flush_data_standard.txt";
predictor_instances[type] = FlushVolPredictor(path);
else if (dataset_value == 1)
path += "/flush/flush_data_dual_standard.txt";
else if (dataset_value == 2)
path += "/flush/flush_data_dual_highflow.txt";
predictor_instances[dataset_value] = FlushVolPredictor(path);
predictor = &predictor_instances[type];
predictor = &predictor_instances[dataset_value];
}
}
@@ -327,3 +335,10 @@ bool GenericFlushPredictor::predict(const RGB& from, const RGB& to, float& flush
return false;
return predictor->predict(from, to, flush);
}
int GenericFlushPredictor::get_min_flush_volume()
{
if (!predictor)
return std::numeric_limits<int>::max();
return predictor->get_min_flush_volume();
}

View File

@@ -8,14 +8,6 @@
namespace FlushPredict
{
enum FlushMachineType
{
Standard,
DualStandard,
DualHighFlow
};
struct RGBColor
{
unsigned char r{ 0 };
@@ -48,10 +40,10 @@ class FlushVolPredictor;
class GenericFlushPredictor
{
using RGB = FlushPredict::RGBColor;
using MachineType = FlushPredict::FlushMachineType;
public:
explicit GenericFlushPredictor(const MachineType& type);
explicit GenericFlushPredictor(const int dataset_value);
bool predict(const RGB& from, const RGB& to, float& flush);
int get_min_flush_volume();
private:
FlushVolPredictor* predictor{ nullptr };
};

View File

@@ -1016,7 +1016,7 @@ static std::vector<std::string> s_Preset_printer_options {
"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",
"bed_temperature_formula"
"bed_temperature_formula", "nozzle_flush_dataset"
};
static std::vector<std::string> s_Preset_sla_print_options {

View File

@@ -2277,6 +2277,10 @@ void PrintConfigDef::init_fff_params()
def->enum_labels.push_back(L("By Highest Temp"));
def->set_default_value(new ConfigOptionEnum<BedTempFormula>(BedTempFormula::btfFirstFilament));
def = this->add("nozzle_flush_dataset", coInts);
def->nullable = true;
def->set_default_value(new ConfigOptionIntsNullable{0});
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.");
@@ -7535,7 +7539,8 @@ std::set<std::string> printer_options_with_variant_1 = {
"nozzle_volume",
"nozzle_type",
"printer_extruder_id",
"printer_extruder_variant"
"printer_extruder_variant",
"nozzle_flush_dataset"
};
//options with silient mode

View File

@@ -1251,6 +1251,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionStrings, filament_extruder_variant))
((ConfigOptionEnum<BedTempFormula>, bed_temperature_formula))
((ConfigOptionInts, physical_extruder_map))
((ConfigOptionIntsNullable, nozzle_flush_dataset))
((ConfigOptionFloatsNullable, filament_flush_volumetric_speed))
((ConfigOptionIntsNullable, filament_flush_temp))
// BBS