From: <emc...@us...> - 2004-02-29 20:39:31
|
Update of /cvsroot/emc/emc/src/ncutils/deltazfix In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16674 Added Files: deltazfix.c Log Message: Adding ncutils to the project. --- NEW FILE: deltazfix.c --- /***************************************************************************** * * NAME: Feedrate fix * * PURPOSE: This program is a g-code filter that * looks at the amount of z movement between subsequent * g-code commands and inserts an appropriate feedrate. * I was using this filter with steppermod.o where I was loosing steps * in the Z-zxis during steep z moves. * * It is here for example only, in case you find yourself in a similiar * situation. * * * RESTRICTIONS: * * * REVISION: DLH - ORIGINAL VERSION 1/20/02 11:14AM * ***************************************************************************** * * ****************************************************************************/ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <signal.h> #include <math.h> #include <ctype.h> #include <time.h> #ifdef __GNUC__ #include <sys/wait.h> #include <unistd.h> #endif #define TRUE 1 #define FALSE 0 #ifndef __GNUC__ /***************************************************************************** * non-linux getopt provided by: * Author: Hi_Tech_Assassin * Email : Hi_...@ha... ****************************************************************************/ char *optarg; int getopt (int argc, char *const *argv, const char *shortopts) { int x, step=0, i, y, found=0; static int optPosition; /* used to keep position of shortopts on each call*/ /* this loop enssures that if a switch is not found it loops until one is found in list or EOF when all shortopts have been searched */ while(optPosition<=strlen(shortopts)-1) { if(shortopts[optPosition+1]!=':') // locate the next : char { do { step++; } while(shortopts[optPosition+step]!=':'); step++; } else step=2; optPosition+=step; /* we do this at start of each iteration because if function return occurs we miss our chance */ for(x=1;x<argc;x++) { if(argv[x][0]=='-') { /* check if switch is in our list, otherwise alert caller with return of NULL */ found=0; for(y=0; !found && y<=strlen(shortopts)-1;y++) if(shortopts[y]!=':') if(argv[x][1]==shortopts[y]) found=1; if(!found) { optarg=NULL; return NULL; } /* this is loop necessary because of the multi char support between : s */ for(i=0; i<=step-1; i++) { if(argv[x][1]==shortopts[optPosition-(step-i)]) { if(x+1 < argc) { if(argv[x+1][0]!='-') optarg=argv[x+1]; else optarg=NULL; } else optarg=NULL; return shortopts[optPosition-(step-i)]; } } } } } return EOF; } #endif double getz(char *inpstr) { //G01 X1.6500 Y1.7500 Z0.5702 char tempstr[255]; char *zstr; strcpy(tempstr,inpstr); strtok( tempstr, "Z" ); zstr = strtok( NULL, "Z" ); return(atof(zstr)); } int main(int argc, char *argv[]) { char *s; int c; char *args[64]; char infilename[255]; char outfilename[255]; char inpstr[255]; FILE *infile; FILE *outfile; int infast=0; int inslow=0; int startf=0; double curz; double oldz; while ((c = getopt(argc, argv, "i:o:")) != EOF) { switch(c) { case 'i': strcpy(infilename,optarg); printf("Input=%s\n", infilename); break; case 'o': strcpy(outfilename,optarg); printf("Ouput=%s\n", outfilename); break; default: printf("Invalid option specified\n"); printf("%s [-i infile] [-o outfile]\n", argv[0]); return 1; break; } } printf("Deltafix v0.1 Started...\n"); if ( ( infile = fopen( infilename, "rt" ) ) == NULL ) { printf( "Can't open infile: %s \n", infilename); return ( 0 ); } if ( ( outfile = fopen( outfilename, "wt" ) ) == NULL ) { printf( "Can't open outfile: %s \n", outfilename); return ( 0 ); } do { memset( inpstr, 0x00, sizeof( inpstr ) ); fgets( inpstr, 255, infile ); //keep reading lines.. printf(inpstr); if ( (strstr(inpstr,"x") || strstr(inpstr,"X")) && (strstr(inpstr,"y") || strstr(inpstr,"Y")) && (strstr(inpstr,"z") || strstr(inpstr,"Z")) ) { curz=getz(inpstr); if(startf==0) //first ime through { oldz=curz; startf=1; } if ((fabs(curz-oldz) < 0.01)) { fputs("F7.0\n",outfile); goto jumphere; } if ((fabs(curz-oldz) >= 0.0100) && (fabs(curz-oldz) < 0.0150) ) { fputs("F5.0\n",outfile); goto jumphere; } if ((fabs(curz-oldz) >= 0.0150) && (fabs(curz-oldz) < 0.0200) ) { fputs("F3.0\n",outfile); goto jumphere; } if ((fabs(curz-oldz) >= 0.0200) && (fabs(curz-oldz) < 0.0250) ) { fputs("F3.0\n",outfile); goto jumphere; } if ((fabs(curz-oldz) >= 0.0250)) { fputs("F1.0\n",outfile); goto jumphere; } jumphere: oldz=curz; } fputs(inpstr,outfile); } while ( !feof( infile ) ); return(0); } |