FIX: enhance for timelapse gcode

1. support traditional timelapse for H2D when printing by object
2. insert timelapse gcode when close wipe tower
3. remove hard gcode before filament gcode
jira: none

Change-Id: Ib56c21b1f07832f2cbc8ba5ab7f2e8653b3105bf
(cherry picked from commit 7613474cefd210685d16a5585608c0c7cb7efa95)
This commit is contained in:
zhimin.zeng 2025-02-05 11:05:43 +08:00 committed by lane.wei
parent 6cea772d4f
commit fff7873456
4 changed files with 49 additions and 76 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "Bambulab", "name": "Bambulab",
"url": "http://www.bambulab.com/Parameters/vendor/BBL.json", "url": "http://www.bambulab.com/Parameters/vendor/BBL.json",
"version": "02.00.00.25", "version": "02.00.00.27",
"force_update": "0", "force_update": "0",
"description": "the initial version of BBL configurations", "description": "the initial version of BBL configurations",
"machine_model_list": [ "machine_model_list": [

File diff suppressed because one or more lines are too long

View File

@ -84,11 +84,6 @@ static const size_t g_max_label_object = 64;
static const double smooth_speed_step = 10; static const double smooth_speed_step = 10;
static const double not_split_length = scale_(1.0); static const double not_split_length = scale_(1.0);
static const std::string lift_gcode_after_printing_object = "{if toolchange_count > 1 && (z_hop_types[current_extruder] == 0 || z_hop_types[current_extruder] == 3)}\n"
"G17\n"
"G2 Z{z_after_toolchange + 0.4} I0.86 J0.86 P1 F10000 ; spiral lift a little from second lift\n"
"{endif}\n";
Vec2d travel_point_1; Vec2d travel_point_1;
Vec2d travel_point_2; Vec2d travel_point_2;
Vec2d travel_point_3; Vec2d travel_point_3;
@ -657,8 +652,13 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
std::string toolchange_gcode_str; std::string toolchange_gcode_str;
ZHopType z_hope_type = ZHopType(gcodegen.config().z_hop_types.get_at(gcodegen.writer().filament()->id()));
LiftType auto_lift_type = LiftType::NormalLift;
if (z_hope_type == ZHopType::zhtAuto || z_hope_type == ZHopType::zhtSpiral || z_hope_type == ZHopType::zhtSlope)
auto_lift_type = LiftType::SpiralLift;
// BBS: should be placed before toolchange parsing // BBS: should be placed before toolchange parsing
std::string toolchange_retract_str = gcodegen.retract(true, false); std::string toolchange_retract_str = gcodegen.retract(false, false, auto_lift_type, true);
check_add_eol(toolchange_retract_str); check_add_eol(toolchange_retract_str);
// Process the custom change_filament_gcode. If it is empty, provide a simple Tn command to change the filament. // Process the custom change_filament_gcode. If it is empty, provide a simple Tn command to change the filament.
@ -668,7 +668,6 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
bool is_used_travel_avoid_perimeter = gcodegen.m_config.prime_tower_skip_points.value; bool is_used_travel_avoid_perimeter = gcodegen.m_config.prime_tower_skip_points.value;
// add nozzle change gcode into change filament gcode // add nozzle change gcode into change filament gcode
std::string prefix_gcode = lift_gcode_after_printing_object;
std::string nozzle_change_gcode_trans; std::string nozzle_change_gcode_trans;
if (!tcr.nozzle_change_result.gcode.empty() && (gcodegen.config().nozzle_diameter.size() > 1)) { if (!tcr.nozzle_change_result.gcode.empty() && (gcodegen.config().nozzle_diameter.size() > 1)) {
// move to start_pos before nozzle change // move to start_pos before nozzle change
@ -683,10 +682,9 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
gcodegen.m_wipe.reset_path(); gcodegen.m_wipe.reset_path();
for (const Vec2f& wipe_pt : tcr.nozzle_change_result.wipe_path) for (const Vec2f& wipe_pt : tcr.nozzle_change_result.wipe_path)
gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen, transform_wt_pt(wipe_pt) + plate_origin_2d)); gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen, transform_wt_pt(wipe_pt) + plate_origin_2d));
nozzle_change_gcode_trans += gcodegen.retract(true, false); nozzle_change_gcode_trans += gcodegen.retract(false, false, auto_lift_type, true);
prefix_gcode = nozzle_change_gcode_trans; change_filament_gcode = nozzle_change_gcode_trans + change_filament_gcode;
} }
change_filament_gcode = prefix_gcode + change_filament_gcode;
if (! change_filament_gcode.empty()) { if (! change_filament_gcode.empty()) {
DynamicConfig config; DynamicConfig config;
@ -1495,8 +1493,7 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu
if (m_config.printer_structure.value == PrinterStructure::psI3 && m_spiral_vase) { if (m_config.printer_structure.value == PrinterStructure::psI3 && m_spiral_vase) {
m_timelapse_warning_code += 1; m_timelapse_warning_code += 1;
} }
if ((m_config.printer_structure.value == PrinterStructure::psI3 || m_config.nozzle_diameter.size() == 2) if (m_config.printer_structure.value == PrinterStructure::psI3 && print->config().print_sequence == PrintSequence::ByObject) {
&& print->config().print_sequence == PrintSequence::ByObject) {
m_timelapse_warning_code += (1 << 1); m_timelapse_warning_code += (1 << 1);
} }
if (m_config.timelapse_type.value == TimelapseType::tlSmooth && !m_config.enable_prime_tower.value) { if (m_config.timelapse_type.value == TimelapseType::tlSmooth && !m_config.enable_prime_tower.value) {
@ -3604,17 +3601,32 @@ GCode::LayerResult GCode::process_layer(
int physical_extruder_id = print.config().physical_extruder_map.get_at(most_used_extruder); int physical_extruder_id = print.config().physical_extruder_map.get_at(most_used_extruder);
ZHopType z_hope_type = ZHopType(FILAMENT_CONFIG(z_hop_types));
LiftType auto_lift_type = LiftType::NormalLift;
if (z_hope_type == ZHopType::zhtAuto || z_hope_type == ZHopType::zhtSpiral || z_hope_type == ZHopType::zhtSlope)
auto_lift_type = LiftType::SpiralLift;
auto insert_timelapse_gcode = [this, print_z, &print, &physical_extruder_id]() -> std::string { auto insert_timelapse_gcode = [this, print_z, &print, &physical_extruder_id]() -> std::string {
std::string gcode_res; std::string timepals_gcode;
if (!print.config().time_lapse_gcode.value.empty()) { if (!print.config().time_lapse_gcode.value.empty()) {
DynamicConfig config; DynamicConfig config;
config.set_key_value("most_used_physical_extruder_id", new ConfigOptionInt(physical_extruder_id)); config.set_key_value("most_used_physical_extruder_id", new ConfigOptionInt(physical_extruder_id));
config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index)); config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index));
config.set_key_value("layer_z", new ConfigOptionFloat(print_z)); config.set_key_value("layer_z", new ConfigOptionFloat(print_z));
config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z)); config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z));
gcode_res = this->placeholder_parser_process("timelapse_gcode", print.config().time_lapse_gcode.value, m_writer.filament()->id(), &config) + "\n"; timepals_gcode = this->placeholder_parser_process("timelapse_gcode", print.config().time_lapse_gcode.value, m_writer.filament()->id(), &config) + "\n";
} }
return gcode_res;
m_writer.set_current_position_clear(false);
// BBS: check whether custom gcode changes the z position. Update if changed
double temp_z_after_timepals_gcode;
if (GCodeProcessor::get_last_z_from_gcode(timepals_gcode, temp_z_after_timepals_gcode)) {
Vec3d pos = m_writer.get_position();
pos(2) = temp_z_after_timepals_gcode;
m_writer.set_position(pos);
}
return timepals_gcode;
}; };
// BBS: don't use lazy_raise when enable spiral vase // BBS: don't use lazy_raise when enable spiral vase
@ -3624,16 +3636,8 @@ GCode::LayerResult GCode::process_layer(
if ((printer_structure == PrinterStructure::psI3 || m_config.nozzle_diameter.values.size() == 2) if ((printer_structure == PrinterStructure::psI3 || m_config.nozzle_diameter.values.size() == 2)
&& !need_insert_timelapse_gcode_for_traditional && !m_spiral_vase && !need_insert_timelapse_gcode_for_traditional && !m_spiral_vase
&& print.config().print_sequence == PrintSequence::ByLayer) { && print.config().print_sequence == PrintSequence::ByLayer) {
std::string timepals_gcode = insert_timelapse_gcode(); gcode += this->retract(false, false, auto_lift_type, true);
gcode += timepals_gcode; gcode += insert_timelapse_gcode();
m_writer.set_current_position_clear(false);
//BBS: check whether custom gcode changes the z position. Update if changed
double temp_z_after_timepals_gcode;
if (GCodeProcessor::get_last_z_from_gcode(timepals_gcode, temp_z_after_timepals_gcode)) {
Vec3d pos = m_writer.get_position();
pos(2) = temp_z_after_timepals_gcode;
m_writer.set_position(pos);
}
} }
if (! print.config().layer_change_gcode.value.empty()) { if (! print.config().layer_change_gcode.value.empty()) {
DynamicConfig config; DynamicConfig config;
@ -3993,25 +3997,23 @@ GCode::LayerResult GCode::process_layer(
} }
if (should_insert) { if (should_insert) {
gcode += this->retract(false, false, LiftType::SpiralLift,true); gcode += this->retract(false, false, auto_lift_type, true);
m_writer.add_object_change_labels(gcode); m_writer.add_object_change_labels(gcode);
std::string timepals_gcode = insert_timelapse_gcode(); gcode += insert_timelapse_gcode();
gcode += timepals_gcode;
m_writer.set_current_position_clear(false);
// BBS: check whether custom gcode changes the z position. Update if changed
double temp_z_after_timepals_gcode;
if (GCodeProcessor::get_last_z_from_gcode(timepals_gcode, temp_z_after_timepals_gcode)) {
Vec3d pos = m_writer.get_position();
pos(2) = temp_z_after_timepals_gcode;
m_writer.set_position(pos);
}
has_insert_timelapse_gcode = true; has_insert_timelapse_gcode = true;
} }
} }
gcode += m_wipe_tower->tool_change(*this, extruder_id, extruder_id == layer_tools.extruders.back()); gcode += m_wipe_tower->tool_change(*this, extruder_id, extruder_id == layer_tools.extruders.back());
} }
} else { } else {
if (m_config.nozzle_diameter.values.size() == 2 && writer().filament() && (get_extruder_id(writer().filament()->id()) == most_used_extruder)) {
gcode += this->retract(false, false, auto_lift_type, true);
m_writer.add_object_change_labels(gcode);
gcode += insert_timelapse_gcode();
has_insert_timelapse_gcode = true;
}
gcode += this->set_extruder(extruder_id, print_z); gcode += this->set_extruder(extruder_id, print_z);
} }
@ -4222,7 +4224,7 @@ GCode::LayerResult GCode::process_layer(
if (is_infill_first && !first_layer) { if (is_infill_first && !first_layer) {
if (!has_wipe_tower && need_insert_timelapse_gcode_for_traditional && printer_structure == PrinterStructure::psI3 if (!has_wipe_tower && need_insert_timelapse_gcode_for_traditional && printer_structure == PrinterStructure::psI3
&& !has_insert_timelapse_gcode && has_infill(by_region_specific)) { && !has_insert_timelapse_gcode && has_infill(by_region_specific)) {
gcode += this->retract(false, false, LiftType::SpiralLift,true); gcode += this->retract(false, false, auto_lift_type, true);
if (!temp_start_str.empty() && m_writer.empty_object_start_str()) { if (!temp_start_str.empty() && m_writer.empty_object_start_str()) {
std::string end_str = std::string("; stop printing object, unique label id: ") + std::to_string(instance_to_print.label_object_id) + "\n"; std::string end_str = std::string("; stop printing object, unique label id: ") + std::to_string(instance_to_print.label_object_id) + "\n";
if (print.is_BBL_Printer()) if (print.is_BBL_Printer())
@ -4230,16 +4232,7 @@ GCode::LayerResult GCode::process_layer(
gcode += end_str; gcode += end_str;
} }
std::string timepals_gcode = insert_timelapse_gcode(); gcode += insert_timelapse_gcode();
gcode += timepals_gcode;
m_writer.set_current_position_clear(false);
//BBS: check whether custom gcode changes the z position. Update if changed
double temp_z_after_timepals_gcode;
if (GCodeProcessor::get_last_z_from_gcode(timepals_gcode, temp_z_after_timepals_gcode)) {
Vec3d pos = m_writer.get_position();
pos(2) = temp_z_after_timepals_gcode;
m_writer.set_position(pos);
}
if (!temp_start_str.empty() && m_writer.empty_object_start_str()) if (!temp_start_str.empty() && m_writer.empty_object_start_str())
gcode += temp_start_str; gcode += temp_start_str;
@ -4252,7 +4245,7 @@ GCode::LayerResult GCode::process_layer(
gcode += this->extrude_perimeters(print, by_region_specific); gcode += this->extrude_perimeters(print, by_region_specific);
if (!has_wipe_tower && need_insert_timelapse_gcode_for_traditional && printer_structure == PrinterStructure::psI3 if (!has_wipe_tower && need_insert_timelapse_gcode_for_traditional && printer_structure == PrinterStructure::psI3
&& !has_insert_timelapse_gcode && has_infill(by_region_specific)) { && !has_insert_timelapse_gcode && has_infill(by_region_specific)) {
gcode += this->retract(false, false, LiftType::SpiralLift,true); gcode += this->retract(false, false, auto_lift_type, true);
if (!temp_start_str.empty() && m_writer.empty_object_start_str()) { if (!temp_start_str.empty() && m_writer.empty_object_start_str()) {
std::string end_str = std::string("; stop printing object, unique label id: ") + std::to_string(instance_to_print.label_object_id) + "\n"; std::string end_str = std::string("; stop printing object, unique label id: ") + std::to_string(instance_to_print.label_object_id) + "\n";
if (print.is_BBL_Printer()) if (print.is_BBL_Printer())
@ -4260,16 +4253,7 @@ GCode::LayerResult GCode::process_layer(
gcode += end_str; gcode += end_str;
} }
std::string timepals_gcode = insert_timelapse_gcode(); gcode += insert_timelapse_gcode();
gcode += timepals_gcode;
m_writer.set_current_position_clear(false);
//BBS: check whether custom gcode changes the z position. Update if changed
double temp_z_after_timepals_gcode;
if (GCodeProcessor::get_last_z_from_gcode(timepals_gcode, temp_z_after_timepals_gcode)) {
Vec3d pos = m_writer.get_position();
pos(2) = temp_z_after_timepals_gcode;
m_writer.set_position(pos);
}
if (!temp_start_str.empty() && m_writer.empty_object_start_str()) if (!temp_start_str.empty() && m_writer.empty_object_start_str())
gcode += temp_start_str; gcode += temp_start_str;
@ -4351,20 +4335,10 @@ GCode::LayerResult GCode::process_layer(
&& (writer().filament() && get_extruder_id(writer().filament()->id()) != most_used_extruder)) { && (writer().filament() && get_extruder_id(writer().filament()->id()) != most_used_extruder)) {
m_support_traditional_timelapse = false; m_support_traditional_timelapse = false;
} }
int layer_id = m_layer->id(); gcode += this->retract(false, false, auto_lift_type, true);
gcode += this->retract(false, false, LiftType::SpiralLift,true);
m_writer.add_object_change_labels(gcode); m_writer.add_object_change_labels(gcode);
std::string timepals_gcode = insert_timelapse_gcode(); gcode += insert_timelapse_gcode();
gcode += timepals_gcode;
m_writer.set_current_position_clear(false);
//BBS: check whether custom gcode changes the z position. Update if changed
double temp_z_after_timepals_gcode;
if (GCodeProcessor::get_last_z_from_gcode(timepals_gcode, temp_z_after_timepals_gcode)) {
Vec3d pos = m_writer.get_position();
pos(2) = temp_z_after_timepals_gcode;
m_writer.set_position(pos);
}
} }
result.gcode = std::move(gcode); result.gcode = std::move(gcode);
@ -6090,7 +6064,7 @@ std::string GCode::set_extruder(unsigned int new_filament_id, double print_z, bo
std::string change_filament_gcode = m_config.change_filament_gcode.value; std::string change_filament_gcode = m_config.change_filament_gcode.value;
// Move the lift gcode here which is in the change_filament_gcode originally // Move the lift gcode here which is in the change_filament_gcode originally
change_filament_gcode = lift_gcode_after_printing_object + change_filament_gcode; change_filament_gcode = this->retract(false, false, LiftType::SpiralLift, true) + change_filament_gcode;
std::string toolchange_gcode_parsed; std::string toolchange_gcode_parsed;
if (!change_filament_gcode.empty()) { if (!change_filament_gcode.empty()) {

View File

@ -1484,8 +1484,7 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value)
if (opt_key == "print_sequence" && m_config->opt_enum<PrintSequence>("print_sequence") == PrintSequence::ByObject) { if (opt_key == "print_sequence" && m_config->opt_enum<PrintSequence>("print_sequence") == PrintSequence::ByObject) {
auto printer_structure_opt = m_preset_bundle->printers.get_edited_preset().config.option<ConfigOptionEnum<PrinterStructure>>("printer_structure"); auto printer_structure_opt = m_preset_bundle->printers.get_edited_preset().config.option<ConfigOptionEnum<PrinterStructure>>("printer_structure");
if ((printer_structure_opt && printer_structure_opt->value == PrinterStructure::psI3) if (printer_structure_opt && printer_structure_opt->value == PrinterStructure::psI3) {
|| m_preset_bundle->get_printer_extruder_count() == 2) {
wxString msg_text = _(L("The current printer does not support timelapse in Traditional Mode when printing By-Object.")); wxString msg_text = _(L("The current printer does not support timelapse in Traditional Mode when printing By-Object."));
msg_text += "\n\n" + _(L("Still print by object?")); msg_text += "\n\n" + _(L("Still print by object?"));