Update dependency

This commit is contained in:
QIDI TECH
2024-11-28 14:53:09 +08:00
parent 506ff7ad8c
commit db50a0814e
17 changed files with 250 additions and 26 deletions

View File

@@ -17,9 +17,12 @@ const std::string Extrusion_Role_Tag = " FEATURE: ";
const std::string Width_Tag = " LINE_WIDTH: ";
const std::string Wipe_Start_Tag = " WIPE_START";
const std::string Wipe_End_Tag = " WIPE_END";
const std::string Wipe_Tower_Start_Tag = " WIPE_TOWER_START";
const std::string Wipe_Tower_End_Tag = " WIPE_TOWER_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 has_scarf_joint_seam_tag = " has_scarf_joint_seam";
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: ";
@@ -130,6 +133,12 @@ GCodeCheckResult GCodeChecker::parse_comment(GCodeLine& line)
m_wiping = true;
} else if (starts_with(comment, Wipe_End_Tag)) {
m_wiping = false;
}
else if (starts_with(comment, Wipe_Tower_Start_Tag)) {
is_wipe_tower = true;
}
else if (starts_with(comment, Wipe_Tower_End_Tag)) {
is_wipe_tower = false;
} else if (starts_with(comment, Height_Tag)) {
std::string str = comment.substr(Height_Tag.size());
if (!parse_double_from_str(str, m_height)) {
@@ -162,6 +171,11 @@ GCodeCheckResult GCodeChecker::parse_comment(GCodeLine& line)
return GCodeCheckResult::ParseFailed;
}
}
else if (starts_with(comment, has_scarf_joint_seam_tag))
{
std::string str = comment.substr(has_scarf_joint_seam_tag.size() + 3);
has_scarf_joint_seam = (str == "1");
}
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)) {
@@ -232,6 +246,10 @@ GCodeCheckResult GCodeChecker::parse_command(GCodeLine& gcode_line)
ret = parse_M104_M109(gcode_line);
break;
} // Set to nozzle temperature
case 1020: {
ret = parse_M1020(gcode_line);
break;
}
default: { break; }
}
break;
@@ -407,20 +425,31 @@ GCodeCheckResult GCodeChecker::parse_G92(GCodeLine& gcode_line)
return GCodeCheckResult::ParseFailed;
}
if (gcode_line.has(X))
bool any_found = false;
if (gcode_line.has(X)){
m_origin[X] = m_end_position[X] - gcode_line.get(X);
any_found = true;
}
if (gcode_line.has(Y))
if (gcode_line.has(Y)){
m_origin[Y] = m_end_position[Y] - gcode_line.get(Y);
any_found = true;
}
if (gcode_line.has(Z))
if (gcode_line.has(Z)){
m_origin[Z] = m_end_position[Z] - gcode_line.get(Z);
any_found = true;
}
if (gcode_line.has(E))
if (gcode_line.has(E)){
m_end_position[E] = gcode_line.get(E);
any_found = true;
}
for (unsigned char a = X; a <= E; ++a) {
m_origin[a] = m_end_position[a];
if (!any_found) {
for (unsigned char a = X; a <= E; ++a) {
m_origin[a] = m_end_position[a];
}
}
return GCodeCheckResult::Success;
@@ -469,6 +498,46 @@ GCodeCheckResult GCodeChecker::parse_M104_M109(const GCodeLine &gcode_line)
return GCodeCheckResult::Success;
}
GCodeCheckResult GCodeChecker::parse_M1020(const GCodeLine& gcode_line)
{
const char* c = gcode_line.m_raw.c_str();
const char* rs = strchr(c, 'S');
if (rs != nullptr) {
std::string str = rs;
str = str.substr(1);
for (int i = 0; i < str.size(); i++) {
if (str[i] == ' ')
str = str.substr(0, i);
}
try {
int value = std::stoi(str);
if (value >= 0 && value <= filament_flow_ratio.size() - 1) {
filament_id = value;
flow_ratio = filament_flow_ratio[value];
return GCodeCheckResult::Success;
}
else {
return GCodeCheckResult::ParseFailed;
}
}
catch (std::invalid_argument&) {
std::cout << "Invalid argument: not a valid integer" << std::endl;
return GCodeCheckResult::ParseFailed;
}
catch (std::out_of_range&) {
std::cout << "Out of range: number is too large" << std::endl;
return GCodeCheckResult::ParseFailed;
}
}
else
{
std::cout << "Missing 'S' character in the G-code line!" << std::endl;
return GCodeCheckResult::ParseFailed;
}
}
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
@@ -593,8 +662,21 @@ GCodeCheckResult GCodeChecker::check_G0_G1_width(const GCodeLine& line)
std::array<double, 3> target = { m_end_position[X], m_end_position[Y], m_end_position[Z] };
bool is_bridge = m_role == erOverhangPerimeter || m_role == erBridgeInfill;
if (!is_bridge) {
double width_real = calculate_G1_width(source, target, delta_pos[E], m_height, is_bridge);
if (!is_bridge && !is_wipe_tower) {
double real_height = m_height;
if (line.has(Z) && has_scarf_joint_seam && line.get(Z) != 0)
{
if (line.get(Z) == z_height)
{
return GCodeCheckResult::Success;
}
if (line.get(Z) && line.get(E))
{
return GCodeCheckResult::Success;
}
real_height = line.get(Z) - (z_height - m_height);
}
double width_real = calculate_G1_width(source, target, delta_pos[E], real_height, is_bridge);
if (fabs(width_real - m_width) > WIDTH_THRESHOLD) {
std::cout << "Invalid G0_G1 because has abnormal line width." << std::endl;
std::cout << "Width: " << m_width << " Width_real: " << width_real << std::endl;