1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-22 23:43:00 +02:00

cngt/cngt.c: added positioning-only mode

Invoke with only the initial Z, without a height and without file or
reference points. E.g.,

cngt -60
This commit is contained in:
Werner Almesberger 2011-08-31 15:39:40 -03:00
parent 6795057567
commit eb8964da6f

View File

@ -20,12 +20,14 @@
#define MAX_POS 10 #define MAX_POS 10
#define STEP 5 /* xy movement step, 5 mm */ #define STEP 5 /* xy movement step, 5 mm */
#define STEP_Z 1 /* z movement step, 1 mm */
static double pos_x[MAX_POS]; static double pos_x[MAX_POS];
static double pos_y[MAX_POS]; static double pos_y[MAX_POS];
static double z0, height; static double z0, height;
static double cx, cy, cz; static double cx, cy, cz;
static int positioning = 0;
#define UNITS(mm) ((mm)*40.0) #define UNITS(mm) ((mm)*40.0)
@ -58,10 +60,20 @@ static int do_key(char c)
switch (c) { switch (c) {
case 'u': case 'u':
up(); if (positioning) {
cz += STEP_Z;
move();
} else {
up();
}
return 0; return 0;
case 'd': case 'd':
down(); if (positioning) {
cz -= STEP_Z;
move();
} else {
down();
}
return 0; return 0;
case 'q': case 'q':
return 1; return 1;
@ -71,7 +83,8 @@ static int do_key(char c)
/* Only x/y positioning */ /* Only x/y positioning */
up(); if (!positioning)
up();
switch (c) { switch (c) {
case 'h': case 'h':
@ -87,6 +100,8 @@ static int do_key(char c)
cx += STEP; cx += STEP;
break; break;
default: default:
if (positioning)
return 0;
if (c < '0' || c > '9') if (c < '0' || c > '9')
return 0; return 0;
cx = pos_x[c-'0']; cx = pos_x[c-'0'];
@ -141,7 +156,10 @@ static void gp_minmax(const char *name,
static void usage(const char *name) static void usage(const char *name)
{ {
fprintf(stderr, "usage: %s z0 height (file | x y ...)\n", name); fprintf(stderr,
"usage: %s z0 height [file | x y ...]\n"
" %s z0\n"
, name, name);
exit(1); exit(1);
} }
@ -152,27 +170,32 @@ int main(int argc, char **argv)
int i; int i;
char c; char c;
if (argc < 4) if (argc < 2)
usage(*argv); usage(*argv);
z0 = atof(argv[1]); z0 = atof(argv[1]);
height = atof(argv[2]);
if (argc & 1) { if (argc == 2) {
for (i = 3; i != argc; i += 2) { positioning = 1;
pos_x[(i-3)/2] = atof(argv[i]); height = 0;
pos_y[(i-3)/2] = atof(argv[i+1]);
}
} else { } else {
if (argc != 4) height = atof(argv[2]);
usage(*argv); if (argc & 1) {
gp_minmax(argv[3], &xa, &ya, &xb, &yb); for (i = 3; i != argc; i += 2) {
pos_x[1] = pos_x[4] = pos_x[7] = xa; pos_x[(i-3)/2] = atof(argv[i]);
pos_x[2] = pos_x[5] = pos_x[8] = (xa+xb)/2; pos_y[(i-3)/2] = atof(argv[i+1]);
pos_x[3] = pos_x[6] = pos_x[9] = xb; }
pos_y[1] = pos_y[2] = pos_y[3] = ya; } else {
pos_y[4] = pos_y[5] = pos_y[6] = (ya+yb)/2; if (argc != 4)
pos_y[7] = pos_y[8] = pos_y[9] = yb; usage(*argv);
gp_minmax(argv[3], &xa, &ya, &xb, &yb);
pos_x[1] = pos_x[4] = pos_x[7] = xa;
pos_x[2] = pos_x[5] = pos_x[8] = (xa+xb)/2;
pos_x[3] = pos_x[6] = pos_x[9] = xb;
pos_y[1] = pos_y[2] = pos_y[3] = ya;
pos_y[4] = pos_y[5] = pos_y[6] = (ya+yb)/2;
pos_y[7] = pos_y[8] = pos_y[9] = yb;
}
} }
serial_open("/dev/ttyUSB0"); serial_open("/dev/ttyUSB0");
@ -183,9 +206,12 @@ int main(int argc, char **argv)
cz = z0+height; cz = z0+height;
move(); move();
while ((c = getkey())) while ((c = getkey())) {
if (do_key(c)) if (do_key(c))
break; break;
if (positioning)
printf("%f %f %f\r\n", cx, cy, cz);
}
up(); up();
serial_close(); serial_close();
return 0; return 0;