ENH: gcodechecker updare
check nozzle temp e/flow_ratio before calculate the width Signed-off-by: qing.zhang <qing.zhang@bambulab.com> Change-Id: I5c95522f061671d4bf503258ef3cd6be714db631 (cherry picked from commit c15d6efdd36db1773ad762e6a09cf21e1a3d9c8b)
This commit is contained in:
parent
12206e59b4
commit
d2f915a558
2 changed files with 137 additions and 4 deletions
|
@ -2,12 +2,12 @@
|
|||
#include <fstream>
|
||||
#include <math.h>
|
||||
#include <map>
|
||||
|
||||
#include <string.h>
|
||||
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,6 +141,40 @@ 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"<<std::endl;
|
||||
ret = GCodeCheckResult::ParseFailed;
|
||||
break;
|
||||
}
|
||||
filament_id = pt;
|
||||
flow_ratio = filament_flow_ratio[pt];
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -358,11 +431,30 @@ GCodeCheckResult GCodeChecker::parse_M83(const GCodeLine& gcode_line)
|
|||
return GCodeCheckResult::Success;
|
||||
}
|
||||
|
||||
GCodeCheckResult GCodeChecker::parse_M104_M109(const GCodeLine &gcode_line)
|
||||
{
|
||||
const char *c = gcode_line.m_raw.c_str();
|
||||
const char *rs = strchr(c,'S');
|
||||
|
||||
std::string str=rs;
|
||||
str = str.substr(1);
|
||||
for (int i = 0; i < str.size(); i++) {
|
||||
if (str[i] == ' ')
|
||||
str=str.substr(0,i);
|
||||
}
|
||||
if (!parse_double_from_str(str, nozzle_temp)) {
|
||||
std::cout << "invalid nozzle temperature comment with invalid value!" << std::endl;
|
||||
return GCodeCheckResult::ParseFailed;
|
||||
}
|
||||
|
||||
return GCodeCheckResult::Success;
|
||||
}
|
||||
|
||||
double GCodeChecker::calculate_G1_width(const std::array<double, 3>& source,
|
||||
const std::array<double, 3>& 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<double, 3> 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<double, 2>& 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) :
|
||||
|
|
|
@ -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<double> &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<double> filament_flow_ratio;
|
||||
std::vector<double> nozzle_temperature;
|
||||
std::vector<double> nozzle_temperature_initial_layer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue