Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

alter.c File Reference

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <float.h>
#include <signal.h>
#include <math.h>
#include <unistd.h>
#include "emcmotglb.h"
#include "usrmotintf.h"

Include dependency graph for alter.c:

Include dependency graph

Go to the source code of this file.

Defines

#define TWO_PI   6.28318530717958647692
#define SLEEP_USECS   10000

Functions

void quit (int sig)
int main (int argc, char *argv[])

Variables

int done = 0


Define Documentation

#define SLEEP_USECS   10000
 

Definition at line 29 of file alter.c.

#define TWO_PI   6.28318530717958647692
 

Definition at line 28 of file alter.c.


Function Documentation

int main int    argc,
char *    argv[]
 

Definition at line 37 of file alter.c.

00038 {
00039   int t;
00040   int axis = 0;
00041   double range = 1.0;
00042   double freq = 1.0;
00043   double freqinv = 1.0;
00044   double alter;
00045   double x;
00046 
00047   /* look for EMC_INIFILE, or leave as default if not found */
00048   for (t = 1; t < argc; t++) {
00049     if (! strcmp(argv[t], "-ini")) {
00050       /* make sure -ini isn't last, since we'll look at next arg */
00051       if (t == argc - 1) {
00052         fprintf(stderr, "can't read -ini parameter; using default %s\n", EMCMOT_INIFILE);
00053       }
00054       else {
00055         /* got it */
00056         strncpy(EMCMOT_INIFILE, argv[t + 1], EMCMOT_INIFILE_LEN - 1);
00057         EMCMOT_INIFILE[EMCMOT_INIFILE_LEN - 1] = 0;
00058         t++;                    /* step over arg */
00059       }
00060       continue;
00061     }
00062     if (! strcmp(argv[t], "-axis")) {
00063       /* make sure -axis isn't last, since we'll look at next arg */
00064       if (t == argc - 1) {
00065         fprintf(stderr, "can't read -axis parameter; using default %d\n", axis);
00066       }
00067       else {
00068         if (1 != sscanf(argv[t + 1], "%d", &axis)) {
00069           fprintf(stderr, "bad value for axis: %s\n", argv[t + 1]);
00070           exit(1);
00071         }
00072         /* got it */
00073         t++;                    /* step over arg */
00074       }
00075       continue;
00076     }
00077     if (! strcmp(argv[t], "-range")) {
00078       /* make sure -range isn't last, since we'll look at next arg */
00079       if (t == argc - 1) {
00080         fprintf(stderr, "can't read -range parameter; using default %f\n", range);
00081       }
00082       else {
00083         if (1 != sscanf(argv[t + 1], "%lf", &range)) {
00084           fprintf(stderr, "bad value for range: %s\n", argv[t + 1]);
00085           exit(1);
00086         }
00087         /* got it */
00088         t++;                    /* step over arg */
00089       }
00090       continue;
00091     }
00092     if (! strcmp(argv[t], "-freq")) {
00093       /* make sure -freq isn't last, since we'll look at next arg */
00094       if (t == argc - 1) {
00095         fprintf(stderr, "can't read -freq parameter; using default %f\n", freq);
00096       }
00097       else {
00098         if (1 != sscanf(argv[t + 1], "%lf", &freq) ||
00099             freq < DBL_MIN) {
00100           fprintf(stderr, "bad value for freq: %s\n", argv[t + 1]);
00101           exit(1);
00102         }
00103         /* got it */
00104         freqinv = 1.0 / freq;   /* already checked freq against DBL_MIN */
00105         t++;                    /* step over arg */
00106       }
00107       continue;
00108     }
00109   }
00110 
00111   if (0 != usrmotIniLoad(EMCMOT_INIFILE)) {
00112     fprintf(stderr, "can't initialize from %s\n", EMCMOT_INIFILE);
00113     exit(1);
00114   }
00115 
00116   if (0 != usrmotInit()) {
00117     fprintf(stderr, "can't connect to motion controller\n");
00118     exit(1);
00119   }
00120 
00121   done = 0;
00122   signal(SIGINT, quit);
00123   x = 0;
00124 
00125   while (! done) {
00126     alter = range * sin(TWO_PI * freq * x);
00127     usrmotAlter(axis, alter);
00128     x += ((double) SLEEP_USECS) / 1000000.0;
00129     if (x > freqinv) {
00130       x = 0.0;
00131     }
00132     usleep(SLEEP_USECS);
00133   }
00134 
00135   usrmotExit();
00136 
00137   exit(0);
00138 }

void quit int    sig [static]
 

Definition at line 32 of file alter.c.

00033 {
00034   done = 1;
00035 }


Variable Documentation

int done = 0 [static]
 

Definition at line 31 of file alter.c.


Generated on Sun Dec 2 15:27:45 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001