00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <stdio.h>
00018 #include <string.h>
00019 #include <stdlib.h>
00020 #include <float.h>
00021 #include <signal.h>
00022 #include <math.h>
00023 #include <unistd.h>
00024 #include "emcmotglb.h"
00025 #include "usrmotintf.h"
00026
00027
00028 #define TWO_PI 6.28318530717958647692
00029 #define SLEEP_USECS 10000
00030
00031 static int done = 0;
00032 static void quit(int sig)
00033 {
00034 done = 1;
00035 }
00036
00037 int main(int argc, char *argv[])
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
00048 for (t = 1; t < argc; t++) {
00049 if (! strcmp(argv[t], "-ini")) {
00050
00051 if (t == argc - 1) {
00052 fprintf(stderr, "can't read -ini parameter; using default %s\n", EMCMOT_INIFILE);
00053 }
00054 else {
00055
00056 strncpy(EMCMOT_INIFILE, argv[t + 1], EMCMOT_INIFILE_LEN - 1);
00057 EMCMOT_INIFILE[EMCMOT_INIFILE_LEN - 1] = 0;
00058 t++;
00059 }
00060 continue;
00061 }
00062 if (! strcmp(argv[t], "-axis")) {
00063
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
00073 t++;
00074 }
00075 continue;
00076 }
00077 if (! strcmp(argv[t], "-range")) {
00078
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
00088 t++;
00089 }
00090 continue;
00091 }
00092 if (! strcmp(argv[t], "-freq")) {
00093
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
00104 freqinv = 1.0 / freq;
00105 t++;
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 }