2
2
#include < fstream>
3
3
#include < math.h>
4
4
#include < map>
5
-
5
+ # include < string.h >
6
6
namespace BambuStudio {
7
7
8
8
// BBS: only check wodth when dE is longer than this value
9
9
const double CHECK_WIDTH_E_THRESHOLD = 0.0025 ;
10
- const double WIDTH_THRESHOLD = 0.03 ;
10
+ const double WIDTH_THRESHOLD = 0.02 ;
11
11
const double RADIUS_THRESHOLD = 0.005 ;
12
12
13
13
const double filament_diameter = 1.75 ;
@@ -19,6 +19,11 @@ const std::string Wipe_Start_Tag = " WIPE_START";
19
19
const std::string Wipe_End_Tag = " WIPE_END" ;
20
20
const std::string Layer_Change_Tag = " CHANGE_LAYER" ;
21
21
const std::string Height_Tag = " LAYER_HEIGHT: " ;
22
+ const std::string filament_flow_ratio_tag = " filament_flow_ratio" ;
23
+ const std::string nozzle_temperature_Tag = " nozzle_temperature =" ;
24
+ const std::string nozzle_temperature_initial_layer_Tag = " nozzle_temperature_initial_layer" ;
25
+ const std::string Z_HEIGHT_TAG = " Z_HEIGHT: " ;
26
+ const std::string Initial_Layer_Ptint_Height_Tag = " initial_layer_print_height =" ;
22
27
23
28
GCodeCheckResult GCodeChecker::parse_file (const std::string& path)
24
29
{
@@ -105,6 +110,19 @@ GCodeCheckResult GCodeChecker::parse_comment(GCodeLine& line)
105
110
// extrusion role tag
106
111
if (starts_with (comment, Extrusion_Role_Tag)) {
107
112
m_role = string_to_role (comment.substr (Extrusion_Role_Tag.length ()));
113
+ if (m_role == erExternalPerimeter) {
114
+
115
+ if (z_height == initial_layer_height && nozzle_temp != nozzle_temperature_initial_layer[filament_id]) {
116
+ std::cout << " invalid filament nozzle initial layer temperature comment with invalid value!" << std::endl;
117
+ return GCodeCheckResult::ParseFailed;
118
+ }
119
+
120
+ if (z_height != initial_layer_height && nozzle_temp != nozzle_temperature[filament_id]) {
121
+ std::cout << " invalid filament nozzle temperature comment with invalid value!" << std::endl;
122
+ return GCodeCheckResult::ParseFailed;
123
+ }
124
+ }
125
+
108
126
} else if (starts_with (comment, Wipe_Start_Tag)) {
109
127
m_wiping = true ;
110
128
} else if (starts_with (comment, Wipe_End_Tag)) {
@@ -123,7 +141,41 @@ GCodeCheckResult GCodeChecker::parse_comment(GCodeLine& line)
123
141
}
124
142
} else if (starts_with (comment, Layer_Change_Tag)) {
125
143
m_layer_num++;
144
+ } else if (starts_with (comment, filament_flow_ratio_tag))
145
+ {
146
+ std::string str = comment.substr (filament_flow_ratio_tag.size ()+3 );
147
+ if (!parse_double_from_str (str, filament_flow_ratio))
148
+ {
149
+ std::cout << " invalid filament flow ratio comment with invalid value!" << std::endl;
150
+ return GCodeCheckResult::ParseFailed;
151
+ }
152
+ }
153
+ else if (starts_with (comment, nozzle_temperature_Tag)) {
154
+ std::string str = comment.substr (nozzle_temperature_Tag.size () + 1 );
155
+ if (!parse_double_from_str (str, nozzle_temperature)) {
156
+ std::cout << " invalid nozzle temperature comment with invalid value!" << std::endl;
157
+ return GCodeCheckResult::ParseFailed;
158
+ }
126
159
}
160
+ else if (starts_with (comment, nozzle_temperature_initial_layer_Tag)) {
161
+ std::string str = comment.substr (nozzle_temperature_initial_layer_Tag.size () + 3 );
162
+ if (!parse_double_from_str (str, nozzle_temperature_initial_layer)) {
163
+ std::cout << " invalid nozzle temperature initial layer comment with invalid value!" << std::endl;
164
+ return GCodeCheckResult::ParseFailed;
165
+ }
166
+ } else if (starts_with (comment, Z_HEIGHT_TAG)) {
167
+ std::string str = comment.substr (Z_HEIGHT_TAG.size ());
168
+ if (!parse_double_from_str (str, z_height)) {
169
+ std::cout << " invalid z height comment with invalid value!" << std::endl;
170
+ return GCodeCheckResult::ParseFailed;
171
+ }
172
+ } else if (starts_with (comment, Initial_Layer_Ptint_Height_Tag)) {
173
+ std::string str = comment.substr (Initial_Layer_Ptint_Height_Tag.size ());
174
+ if (!parse_double_from_str (str, initial_layer_height)) {
175
+ std::cout << " invalid initial layer height comment with invalid value!" << std::endl;
176
+ return GCodeCheckResult::ParseFailed;
177
+ }
178
+ }
127
179
128
180
return GCodeCheckResult::Success;
129
181
}
@@ -153,11 +205,32 @@ GCodeCheckResult GCodeChecker::parse_command(GCodeLine& gcode_line)
153
205
{
154
206
case 82 : { ret = parse_M82 (gcode_line); break ; } // Set to Absolute extrusion
155
207
case 83 : { ret = parse_M83 (gcode_line); break ; } // Set to Relative extrusion
208
+ case 104 : {
209
+ ret = parse_M104_M109 (gcode_line);
210
+ break ;
211
+ } // Set to nozzle temperature
212
+ case 109 : {
213
+ ret = parse_M104_M109 (gcode_line);
214
+ break ;
215
+ } // Set to nozzle temperature
156
216
default : { break ; }
157
217
}
158
218
break ;
159
219
}
160
220
case ' T' :{
221
+
222
+ int pt = ::atoi (&cmd[1 ]);
223
+ if (pt == 1000 || pt == 1100 || pt == 255 ) {
224
+ break ;
225
+ }
226
+
227
+ if (pt < 0 || pt > 254 || pt >= filament_flow_ratio.size ()) {
228
+ std::cout << " Invalid T command" <<std::endl;
229
+ ret = GCodeCheckResult::ParseFailed;
230
+ break ;
231
+ }
232
+ filament_id = pt;
233
+ flow_ratio = filament_flow_ratio[pt];
161
234
break ;
162
235
}
163
236
default : {
@@ -358,11 +431,30 @@ GCodeCheckResult GCodeChecker::parse_M83(const GCodeLine& gcode_line)
358
431
return GCodeCheckResult::Success;
359
432
}
360
433
434
+ GCodeCheckResult GCodeChecker::parse_M104_M109 (const GCodeLine &gcode_line)
435
+ {
436
+ const char *c = gcode_line.m_raw .c_str ();
437
+ const char *rs = strchr (c,' S' );
438
+
439
+ std::string str=rs;
440
+ str = str.substr (1 );
441
+ for (int i = 0 ; i < str.size (); i++) {
442
+ if (str[i] == ' ' )
443
+ str=str.substr (0 ,i);
444
+ }
445
+ if (!parse_double_from_str (str, nozzle_temp)) {
446
+ std::cout << " invalid nozzle temperature comment with invalid value!" << std::endl;
447
+ return GCodeCheckResult::ParseFailed;
448
+ }
449
+
450
+ return GCodeCheckResult::Success;
451
+ }
452
+
361
453
double GCodeChecker::calculate_G1_width (const std::array<double , 3 >& source,
362
454
const std::array<double , 3 >& target,
363
455
double e, double height, bool is_bridge) const
364
456
{
365
- double volume = e * Pi * (filament_diameter/ 2 .0f ) * (filament_diameter/ 2 .0f );
457
+ double volume = (e / flow_ratio) * Pi * (filament_diameter / 2 .0f ) * (filament_diameter / 2 .0f );
366
458
std::array<double , 3 > delta = { target[0 ] - source[0 ],
367
459
target[1 ] - source[1 ],
368
460
target[2 ] - source[2 ] };
@@ -389,7 +481,7 @@ double GCodeChecker::calculate_G2_G3_width(const std::array<double, 2>& source,
389
481
(radian < 0 ? -radian : 2 * Pi - radian);
390
482
double radius = sqrt (v1[0 ] * v1[0 ] + v1[1 ] * v1[1 ]);
391
483
double length = radius * radian;
392
- double volume = e * Pi * (filament_diameter/ 2 ) * (filament_diameter/ 2 );
484
+ double volume = (e / flow_ratio) * Pi * (filament_diameter / 2 ) * (filament_diameter / 2 );
393
485
double mm3_per_mm = volume / length;
394
486
395
487
return is_bridge? 2 * sqrt (mm3_per_mm/Pi) :
0 commit comments