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
1 changed files with 47 additions and 21 deletions

View File

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