I need a program to produce gCode for cutting rectangles starting at xstart,ystart and cutting to far side xend,yend. I have a program that does that but the more parameters on the line in the Makefile, the easier is to make a mistake. It would be nice to specify these as -1.56,0 and 0,2.4 instead of -1.56 0 0 2.4. So I revised the program from:
float xStart=atof(argv[1]);
float yStart=atof(argv[2]);
float xEnd=atof(argv[3]);
float yEnd=atof(argv[4]);
to:
int parsePair(char* pairString, float* x, float *y)
{
return(sscanf(pairString, "%f,%f", x, y));
}
...
float xStart, yStart;
if(parsePair(argv[1], &xStart, &yStart) != 2)
{
printf("unable to parse %s\n", argv[1]);
displayValidArgs();
exit(2);
}
float xEnd, yEnd;
if(parsePair(argv[2], &xEnd, &yEnd) != 2)
{
printf("unable to parse %s\n", argv[1]);
displayValidArgs();
exit(2);
}
The Makefile command goes from:
./mkrectangle -1.593 0 0 2.2179 -.2 -.01 -.6 3 3 .125 rectangle.ngc -a
to:
./mkrectpair -1.593,0 0,2.2179 -.2 -.01 -.5 3 3 .125 rectpair.ngc -a
A minor improvement but I may create something more complex with n pairs as vertices.
No comments:
Post a Comment