From d2f915a558456c24e40d617192a238711ecf046e Mon Sep 17 00:00:00 2001 From: "qing.zhang" Date: Fri, 11 Nov 2022 10:18:19 +0800 Subject: [PATCH] ENH: gcodechecker updare check nozzle temp e/flow_ratio before calculate the width Signed-off-by: qing.zhang Change-Id: I5c95522f061671d4bf503258ef3cd6be714db631 (cherry picked from commit c15d6efdd36db1773ad762e6a09cf21e1a3d9c8b) --- .../bbs_gcode_checker/GCodeChecker.cpp | 100 +++++++++++++++++- .../bbs_gcode_checker/GCodeChecker.h | 41 +++++++ 2 files changed, 137 insertions(+), 4 deletions(-) diff --git a/bbs_test_tools/bbs_gcode_checker/GCodeChecker.cpp b/bbs_test_tools/bbs_gcode_checker/GCodeChecker.cpp index 798be1f5c..aad8a1a57 100644 --- a/bbs_test_tools/bbs_gcode_checker/GCodeChecker.cpp +++ b/bbs_test_tools/bbs_gcode_checker/GCodeChecker.cpp @@ -2,12 +2,12 @@ #include #include #include - +#include namespace BambuStudio { //BBS: only check wodth when dE is longer than this value const double CHECK_WIDTH_E_THRESHOLD = 0.0025; -const double WIDTH_THRESHOLD = 0.03; +const double WIDTH_THRESHOLD = 0.02; const double RADIUS_THRESHOLD = 0.005; const double filament_diameter = 1.75; @@ -19,6 +19,11 @@ const std::string Wipe_Start_Tag = " WIPE_START"; const std::string Wipe_End_Tag = " WIPE_END"; const std::string Layer_Change_Tag = " CHANGE_LAYER"; const std::string Height_Tag = " LAYER_HEIGHT: "; +const std::string filament_flow_ratio_tag = " filament_flow_ratio"; +const std::string nozzle_temperature_Tag = " nozzle_temperature ="; +const std::string nozzle_temperature_initial_layer_Tag = " nozzle_temperature_initial_layer"; +const std::string Z_HEIGHT_TAG = " Z_HEIGHT: "; +const std::string Initial_Layer_Ptint_Height_Tag = " initial_layer_print_height ="; GCodeCheckResult GCodeChecker::parse_file(const std::string& path) { @@ -105,6 +110,19 @@ GCodeCheckResult GCodeChecker::parse_comment(GCodeLine& line) // extrusion role tag if (starts_with(comment, Extrusion_Role_Tag)) { m_role = string_to_role(comment.substr(Extrusion_Role_Tag.length())); + if (m_role == erExternalPerimeter) { + + if (z_height == initial_layer_height && nozzle_temp != nozzle_temperature_initial_layer[filament_id]) { + std::cout << "invalid filament nozzle initial layer temperature comment with invalid value!" << std::endl; + return GCodeCheckResult::ParseFailed; + } + + if (z_height != initial_layer_height && nozzle_temp != nozzle_temperature[filament_id]) { + std::cout << "invalid filament nozzle temperature comment with invalid value!" << std::endl; + return GCodeCheckResult::ParseFailed; + } + } + } else if (starts_with(comment, Wipe_Start_Tag)) { m_wiping = true; } else if (starts_with(comment, Wipe_End_Tag)) { @@ -123,7 +141,41 @@ GCodeCheckResult GCodeChecker::parse_comment(GCodeLine& line) } } else if (starts_with(comment, Layer_Change_Tag)) { m_layer_num++; + } else if (starts_with(comment, filament_flow_ratio_tag)) + { + std::string str = comment.substr(filament_flow_ratio_tag.size()+3); + if (!parse_double_from_str(str, filament_flow_ratio)) + { + std::cout << "invalid filament flow ratio comment with invalid value!" << std::endl; + return GCodeCheckResult::ParseFailed; + } } + else if (starts_with(comment, nozzle_temperature_Tag)) { + std::string str = comment.substr(nozzle_temperature_Tag.size() + 1); + if (!parse_double_from_str(str, nozzle_temperature)) { + std::cout << "invalid nozzle temperature comment with invalid value!" << std::endl; + return GCodeCheckResult::ParseFailed; + } + } + else if (starts_with(comment, nozzle_temperature_initial_layer_Tag)) { + std::string str = comment.substr(nozzle_temperature_initial_layer_Tag.size() + 3); + if (!parse_double_from_str(str, nozzle_temperature_initial_layer)) { + std::cout << "invalid nozzle temperature initial layer comment with invalid value!" << std::endl; + return GCodeCheckResult::ParseFailed; + } + } else if (starts_with(comment, Z_HEIGHT_TAG)) { + std::string str = comment.substr(Z_HEIGHT_TAG.size()); + if (!parse_double_from_str(str, z_height)) { + std::cout << "invalid z height comment with invalid value!" << std::endl; + return GCodeCheckResult::ParseFailed; + } + } else if (starts_with(comment, Initial_Layer_Ptint_Height_Tag)) { + std::string str = comment.substr(Initial_Layer_Ptint_Height_Tag.size()); + if (!parse_double_from_str(str, initial_layer_height)) { + std::cout << "invalid initial layer height comment with invalid value!" << std::endl; + return GCodeCheckResult::ParseFailed; + } + } return GCodeCheckResult::Success; } @@ -153,11 +205,32 @@ GCodeCheckResult GCodeChecker::parse_command(GCodeLine& gcode_line) { case 82: { ret = parse_M82(gcode_line); break; } // Set to Absolute extrusion case 83: { ret = parse_M83(gcode_line); break; } // Set to Relative extrusion + case 104: { + ret = parse_M104_M109(gcode_line); + break; + } // Set to nozzle temperature + case 109: { + ret = parse_M104_M109(gcode_line); + break; + } // Set to nozzle temperature default: { break; } } break; } case 'T':{ + + int pt = ::atoi(&cmd[1]); + if (pt == 1000 || pt == 1100 || pt == 255) { + break; + } + + if (pt < 0 || pt > 254 || pt >= filament_flow_ratio.size()) { + std::cout << "Invalid T command"<& source, const std::array& target, double e, double height, bool is_bridge) const { - double volume = e * Pi * (filament_diameter/2.0f) * (filament_diameter/2.0f); + double volume = (e / flow_ratio) * Pi * (filament_diameter / 2.0f) * (filament_diameter / 2.0f); std::array delta = { target[0] - source[0], target[1] - source[1], target[2] - source[2] }; @@ -389,7 +481,7 @@ double GCodeChecker::calculate_G2_G3_width(const std::array& source, (radian < 0 ? -radian : 2 * Pi - radian); double radius = sqrt(v1[0] * v1[0] + v1[1] * v1[1]); double length = radius * radian; - double volume = e * Pi * (filament_diameter/2) * (filament_diameter/2); + double volume = (e / flow_ratio) * Pi * (filament_diameter / 2) * (filament_diameter / 2); double mm3_per_mm = volume / length; return is_bridge? 2 * sqrt(mm3_per_mm/Pi) : diff --git a/bbs_test_tools/bbs_gcode_checker/GCodeChecker.h b/bbs_test_tools/bbs_gcode_checker/GCodeChecker.h index 74fb859b9..f908ebfb8 100644 --- a/bbs_test_tools/bbs_gcode_checker/GCodeChecker.h +++ b/bbs_test_tools/bbs_gcode_checker/GCodeChecker.h @@ -108,6 +108,7 @@ private: GCodeCheckResult parse_G92(GCodeLine& gcode_line); GCodeCheckResult parse_M82(const GCodeLine& gcode_line); GCodeCheckResult parse_M83(const GCodeLine& gcode_line); + GCodeCheckResult parse_M104_M109(const GCodeLine &gcode_line); GCodeCheckResult parse_comment(GCodeLine& gcode_line); @@ -160,6 +161,38 @@ public: } } + static bool parse_double_from_str(const std::string &input, std::vector &out) + { + + std::string cmd=input; + size_t read = 0; + + while (cmd.size() >= 5) + { + int pt = 0; + for (pt = 0; pt < cmd.size(); pt++) { + char temp = cmd[pt]; + if (temp == ',') + { + try { + double num = std::stod(cmd.substr(0, pt), &read); + + out.push_back(num); + cmd = cmd.substr(pt+1); + break; + } catch (...) { + return false; + } + } + } + } + + double num = std::stod(cmd, &read); + out.push_back(num); + + return true; + } + private: EPositioningType m_global_positioning_type = EPositioningType::Absolute; EPositioningType m_e_local_positioning_type = EPositioningType::Absolute; @@ -174,6 +207,14 @@ private: int m_layer_num = 0; double m_height = 0.0; double m_width = 0.0; + double z_height=0.0f; + double initial_layer_height=0.0f; + int filament_id; + double flow_ratio = 0; + double nozzle_temp = 0.0f; + std::vector filament_flow_ratio; + std::vector nozzle_temperature; + std::vector nozzle_temperature_initial_layer; }; }