Stefan Schuermans commited on 2013-04-22 20:33:49
Showing 6 changed files, with 95 additions and 11 deletions.
... | ... |
@@ -288,7 +288,8 @@ bool CmdParser::procCmd_set_cut_z_step(std::istream &strm) |
288 | 288 |
return false; |
289 | 289 |
} |
290 | 290 |
if (z <= 0.0) { |
291 |
- std::cerr << "invalid z cut step value (" << z << ")" << std::endl; |
|
291 |
+ std::cerr << "invalid z cut step value (" << z |
|
292 |
+ << ", expected > 0.0)" << std::endl; |
|
292 | 293 |
return false; |
293 | 294 |
} |
294 | 295 |
|
... | ... |
@@ -312,7 +313,8 @@ bool CmdParser::procCmd_set_dwell_time(std::istream &strm) |
312 | 313 |
return false; |
313 | 314 |
} |
314 | 315 |
if (dwell_time < 0.0) { |
315 |
- std::cerr << "invalid dwell time (" << dwell_time << ")" << std::endl; |
|
316 |
+ std::cerr << "invalid dwell time (" << dwell_time |
|
317 |
+ << ", expected >= 0.0)" << std::endl; |
|
316 | 318 |
return false; |
317 | 319 |
} |
318 | 320 |
|
... | ... |
@@ -336,7 +338,8 @@ bool CmdParser::procCmd_set_feed_drill(std::istream &strm) |
336 | 338 |
return false; |
337 | 339 |
} |
338 | 340 |
if (feed <= 0.0) { |
339 |
- std::cerr << "invalid feed rate (" << feed << ")" << std::endl; |
|
341 |
+ std::cerr << "invalid feed rate (" << feed |
|
342 |
+ << ", expected > 0.0)" << std::endl; |
|
340 | 343 |
return false; |
341 | 344 |
} |
342 | 345 |
|
... | ... |
@@ -360,7 +363,8 @@ bool CmdParser::procCmd_set_feed_mill(std::istream &strm) |
360 | 363 |
return false; |
361 | 364 |
} |
362 | 365 |
if (feed <= 0.0) { |
363 |
- std::cerr << "invalid feed rate (" << feed << ")" << std::endl; |
|
366 |
+ std::cerr << "invalid feed rate (" << feed |
|
367 |
+ << ", expected > 0.0)" << std::endl; |
|
364 | 368 |
return false; |
365 | 369 |
} |
366 | 370 |
|
... | ... |
@@ -369,6 +373,37 @@ bool CmdParser::procCmd_set_feed_mill(std::istream &strm) |
369 | 373 |
return true; |
370 | 374 |
} |
371 | 375 |
|
376 |
+/** |
|
377 |
+ * @brief process set_layer_mode command |
|
378 |
+ * @param[in] strm stream to read command arguments from |
|
379 |
+ * @return if processing command was successful |
|
380 |
+ */ |
|
381 |
+bool CmdParser::procCmd_set_layer_mode(std::istream &strm) |
|
382 |
+{ |
|
383 |
+ // get arguments |
|
384 |
+ std::string layer_mode_str; |
|
385 |
+ strm >> layer_mode_str; |
|
386 |
+ if (strm.fail()) { |
|
387 |
+ std::cerr << "missing layer mode (\"level_by_level\", \"path_by_path\")" |
|
388 |
+ << std::endl; |
|
389 |
+ return false; |
|
390 |
+ } |
|
391 |
+ |
|
392 |
+ // check argument and update settings |
|
393 |
+ if (layer_mode_str == "level_by_level") { |
|
394 |
+ mSettings.layer_mode = Settings::LevelByLevel; |
|
395 |
+ return true; |
|
396 |
+ } else if (layer_mode_str == "path_by_path") { |
|
397 |
+ mSettings.layer_mode = Settings::PathByPath; |
|
398 |
+ return true; |
|
399 |
+ } else { |
|
400 |
+ std::cerr << "invalid layer mode (\"" << layer_mode_str |
|
401 |
+ << "\", expected: \"level_by_level\", \"path_by_path\")" |
|
402 |
+ << std::endl; |
|
403 |
+ return false; |
|
404 |
+ } |
|
405 |
+} |
|
406 |
+ |
|
372 | 407 |
/** |
373 | 408 |
* @brief process set_move_z command |
374 | 409 |
* @param[in] strm stream to read command arguments from |
... | ... |
@@ -444,7 +479,8 @@ bool CmdParser::procCmd_set_precision(std::istream &strm) |
444 | 479 |
return false; |
445 | 480 |
} |
446 | 481 |
if (precision < 1.0e-8 || precision > 1.0) { |
447 |
- std::cerr << "invalid precision (" << precision << ")" << std::endl; |
|
482 |
+ std::cerr << "invalid precision (" << precision |
|
483 |
+ << ", expected 1.0e-8 ... 1.0)" << std::endl; |
|
448 | 484 |
return false; |
449 | 485 |
} |
450 | 486 |
|
... | ... |
@@ -468,7 +504,8 @@ bool CmdParser::procCmd_set_tool_diameter(std::istream &strm) |
468 | 504 |
return false; |
469 | 505 |
} |
470 | 506 |
if (diameter < 0.0) { |
471 |
- std::cerr << "invalid tool diameter (" << diameter << ")" << std::endl; |
|
507 |
+ std::cerr << "invalid tool diameter (" << diameter |
|
508 |
+ << ", expected >= 0.0)" << std::endl; |
|
472 | 509 |
return false; |
473 | 510 |
} |
474 | 511 |
|
... | ... |
@@ -548,6 +585,8 @@ bool CmdParser::procLine(const std::string &strLine) |
548 | 585 |
return procCmd_set_feed_drill(strm); |
549 | 586 |
else if (cmd == "set_feed_mill") |
550 | 587 |
return procCmd_set_feed_mill(strm); |
588 |
+ else if (cmd == "set_layer_mode") |
|
589 |
+ return procCmd_set_layer_mode(strm); |
|
551 | 590 |
else if (cmd == "set_move_z") |
552 | 591 |
return procCmd_set_move_z(strm); |
553 | 592 |
else if (cmd == "set_offset_x") |
... | ... |
@@ -123,6 +123,13 @@ public: |
123 | 123 |
*/ |
124 | 124 |
bool procCmd_set_feed_mill(std::istream &strm); |
125 | 125 |
|
126 |
+ /** |
|
127 |
+ * @brief process set_layer_mode command |
|
128 |
+ * @param[in] strm stream to read command arguments from |
|
129 |
+ * @return if processing command was successful |
|
130 |
+ */ |
|
131 |
+ bool procCmd_set_layer_mode(std::istream &strm); |
|
132 |
+ |
|
126 | 133 |
/** |
127 | 134 |
* @brief process set_move_z command |
128 | 135 |
* @param[in] strm stream to read command arguments from |
... | ... |
@@ -124,18 +124,46 @@ void Layer::improvePaths(double eqDist) |
124 | 124 |
*/ |
125 | 125 |
void Layer::toGCode(const Settings &settings, GCode &gcode) const |
126 | 126 |
{ |
127 |
+ double z; |
|
128 |
+ Paths::const_iterator path; |
|
129 |
+ |
|
130 |
+ switch (settings.layer_mode) { |
|
131 |
+ |
|
132 |
+ case Settings::LevelByLevel: |
|
133 |
+ |
|
127 | 134 |
// cut step-wise |
128 |
- double z = settings.base_z; |
|
135 |
+ z = settings.base_z; |
|
129 | 136 |
do { |
130 | 137 |
z -= settings.cut_z_step; |
131 | 138 |
if (z < settings.cut_z) |
132 | 139 |
z = settings.cut_z; |
133 | 140 |
|
134 |
- // cut path at current z |
|
135 |
- Paths::const_iterator path; |
|
141 |
+ // cut all paths at current z |
|
136 | 142 |
for (path = mPaths.begin(); path != mPaths.end(); ++path) |
137 | 143 |
path->toGCode(settings, z, gcode); |
138 | 144 |
|
139 | 145 |
} while (z > settings.cut_z); |
146 |
+ |
|
147 |
+ break; |
|
148 |
+ |
|
149 |
+ case Settings::PathByPath: |
|
150 |
+ |
|
151 |
+ // cut each path |
|
152 |
+ for (path = mPaths.begin(); path != mPaths.end(); ++path) { |
|
153 |
+ |
|
154 |
+ // cut current path step-wise |
|
155 |
+ z = settings.base_z; |
|
156 |
+ do { |
|
157 |
+ z -= settings.cut_z_step; |
|
158 |
+ if (z < settings.cut_z) |
|
159 |
+ z = settings.cut_z; |
|
160 |
+ path->toGCode(settings, z, gcode); |
|
161 |
+ } while (z > settings.cut_z); |
|
162 |
+ |
|
163 |
+ } // for path |
|
164 |
+ |
|
165 |
+ break; |
|
166 |
+ |
|
167 |
+ } // switch (settings.layer_mode) |
|
140 | 168 |
} |
141 | 169 |
|
... | ... |
@@ -9,15 +9,22 @@ |
9 | 9 |
/// settings for creation of G-code |
10 | 10 |
class Settings { |
11 | 11 |
public: |
12 |
+ /// layer mode |
|
13 |
+ enum LayerMode { |
|
14 |
+ LevelByLevel, ///< cut all paths at the each level (z), then next level |
|
15 |
+ PathByPath, ///< cut each path all the way down, then next path |
|
16 |
+ }; |
|
17 |
+ |
|
12 | 18 |
/// set some reasonable/safe default settings |
13 | 19 |
Settings(); |
14 | 20 |
|
15 | 21 |
double base_z; ///< z coordinate of workpiece surface |
16 | 22 |
double cut_z; ///< z coordinate of maximum cutting |
17 |
- double cut_z_step; ///< z coordinate difference to cut in one step, > 0.0 |
|
18 |
- double dwell_time; ///< dwell time before cutting each path (in seconds) |
|
23 |
+ double cut_z_step; ///< z coordinate delta to cut in one step, > 0.0 |
|
24 |
+ double dwell_time; ///< dwell time before cutting each path (in sec) |
|
19 | 25 |
double feed_drill; ///< feed rate for drilling |
20 | 26 |
double feed_mill; ///< feed rate for milling |
27 |
+ LayerMode layer_mode; ///< layer cutting mode (see LayerMode) |
|
21 | 28 |
double move_z; ///< z coordinate for moving |
22 | 29 |
double offset_x; ///< offset to add to X coordinate |
23 | 30 |
double offset_y; ///< offset to add to Y coordinate |
24 | 31 |