1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2025-01-03 22:20:17 +02:00

cameo: added optimization of movements between tool paths

- ops.h, ops.c (optimize_paths): reorder toolpaths to reduce the distance
  between them
- lang.l, lang.y: added command "optimize"
- README: documented "optimize"
This commit is contained in:
Werner Almesberger 2010-12-16 14:19:46 -03:00
parent ffaded7f48
commit 57b4e276e5
5 changed files with 62 additions and 1 deletions

View File

@ -179,3 +179,12 @@ and write the toolpaths to the file "drill.gp". Next, we retrieve the
remaining paths, generate toolpaths for a 0.8 mm endmill, and write
them to the file "mill.gp". Finally, we check that all paths have been
processed.
Tool path optimization:
optimize
Try to reduce the movements made between paths by reordering the paths.
Note that this disturbs the order generated by "offset" and should thus
not be used on paths that to be executed in a specific sequence.

View File

@ -46,6 +46,7 @@ NUM -?[0-9]+\.?[0-9]*
<INITIAL>empty return TOK_EMPTY;
<INITIAL>mill return TOK_MILL;
<INITIAL>offset return TOK_OFFSET;
<INITIAL>optimize return TOK_OPTIMIZE;
<INITIAL>remainder return TOK_REMAINDER;
<INITIAL>reset return TOK_RESET;
<INITIAL>translate return TOK_TRANSLATE;

View File

@ -150,7 +150,7 @@ static struct path **classify(struct path **anchor, struct path *path)
%token TOK_ALIGN TOK_ARRAY TOK_CLEAR TOK_DRILL TOK_EMPTY
%token TOK_MILL TOK_OFFSET TOK_REMAINDER TOK_RESET
%token TOK_MILL TOK_OFFSET TOK_OPTIMIZE TOK_REMAINDER TOK_RESET
%token TOK_TRANSLATE TOK_Z
%token TOK_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE
%token TOK_DOG TOK_INSIDE
@ -208,6 +208,10 @@ command:
tool_comp_paths(paths,
!!($2 & OO_DOG), !!($2 & OO_INSIDE));
}
| TOK_OPTIMIZE
{
paths = optimize_paths(paths);
}
| TOK_TRANSLATE dimen dimen
{
translate(paths, $2, $3, 0);

View File

@ -12,6 +12,7 @@
#include <stddef.h>
#include <math.h>
#include "path.h"
#include "shape.h"
@ -88,3 +89,48 @@ struct path *try_mill(struct path *path, double diam, double step)
path->first->z, path->r_tool, diam/2, step);
return NULL;
}
/*
* This isn't a perfect solution for the traveling salesman problem, but it's
* easy to implement and usually produces results that don't look overly
* offensive.
*/
struct path *optimize_paths(struct path *paths)
{
struct path **walk, **best = NULL;
struct path *res = NULL, **anchor = &res;
struct path *curr;
struct point *p;
double best_d = 0, d;
for (walk = &paths; *walk; walk = &(*walk)->next) {
p = (*walk)->first;
if (!p)
continue;
d = hypot(p->x, p->y);
if (!best || d < best_d) {
best = walk;
best_d = d;
}
}
while (best) {
curr = *best;
*anchor = *best;
anchor = &curr->next;
*best = curr->next;
best = NULL;
for (walk = &paths; *walk; walk = &(*walk)->next) {
p = (*walk)->first;
if (!p)
continue;
d = hypot(p->x-curr->last->x, p->y-curr->last->y);
if (!best || d < best_d) {
best = walk;
best_d = d;
}
}
}
return res;
}

View File

@ -20,5 +20,6 @@
void tool_comp_paths(struct path *paths, int dog_bone, int all_inside);
struct path *try_drill(struct path *path, double d_min, double d_max);
struct path *try_mill(struct path *path, double diam, double step);
struct path *optimize_paths(struct path *paths);
#endif /* !OPS_H */