1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-23 04:58:38 +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':
if (positioning) {
cz += STEP_Z;
move();
} else {
up(); up();
}
return 0; return 0;
case 'd': case 'd':
if (positioning) {
cz -= STEP_Z;
move();
} else {
down(); down();
}
return 0; return 0;
case 'q': case 'q':
return 1; return 1;
@ -71,6 +83,7 @@ static int do_key(char c)
/* Only x/y positioning */ /* Only x/y positioning */
if (!positioning)
up(); up();
switch (c) { switch (c) {
@ -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,12 +170,16 @@ 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 == 2) {
positioning = 1;
height = 0;
} else {
height = atof(argv[2]);
if (argc & 1) { if (argc & 1) {
for (i = 3; i != argc; i += 2) { for (i = 3; i != argc; i += 2) {
pos_x[(i-3)/2] = atof(argv[i]); pos_x[(i-3)/2] = atof(argv[i]);
@ -174,6 +196,7 @@ int main(int argc, char **argv)
pos_y[4] = pos_y[5] = pos_y[6] = (ya+yb)/2; pos_y[4] = pos_y[5] = pos_y[6] = (ya+yb)/2;
pos_y[7] = pos_y[8] = pos_y[9] = yb; pos_y[7] = pos_y[8] = pos_y[9] = yb;
} }
}
serial_open("/dev/ttyUSB0"); serial_open("/dev/ttyUSB0");
serial_printf("\nIN;!MC0\n"); serial_printf("\nIN;!MC0\n");
@ -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;