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

ppmcdiag.c

Go to the documentation of this file.
00001 /***************************************************************************
00002                           ppmcdiag.c  -  description
00003                              -------------------
00004     begin                : Mon Oct 23 2000
00005     copyright            : (C) 2000 by Eric Keller
00006     email                : eek105
00007  ***************************************************************************/
00008 
00009 #include <stdio.h>
00010 #include <string.h>
00011 #include <signal.h>
00012 #include <stdlib.h>
00013 #include <ctype.h>
00014 #include <math.h>
00015 #include <unistd.h>
00016 #include "ppmc.h"
00017 //#include "extintf.h"
00018 //unsigned int ppmc_base_addr=0x378;
00019 /* ident tag */
00020 static char ident[] = "$Id: ppmcdiag.c,v 1.1 2001/08/23 20:54:33 paul_c Exp $";
00021 
00022 
00023 /*
00024   Be root to run it
00025   */
00026 
00027 #define NUM_AXES 4
00028 enum {POS = 1, LIMIT, HOME, INDEX, LATCH, DAC, SERVO,SERVOF};
00029 static int done = 0;
00030 static void quit(int sig)
00031 {
00032   done = 1;
00033 }
00034 
00035 
00036 
00037 
00038 int main(int argc, char *argv[])
00039 {
00040   int which = POS;
00041   int newline=0;
00042   double pos[NUM_AXES];
00043   double oldpos[NUM_AXES];
00044   int lim[NUM_AXES*2];
00045   int oldlim[NUM_AXES*2];
00046   int home[NUM_AXES];
00047   int oldhome[NUM_AXES];
00048   double dacval[NUM_AXES];
00049   int index;
00050   int latch;
00051   int axis;
00052   double volts;
00053   int t,var;
00054   char buf[80];
00055   char *cptr;
00056   //printf("diags ppmc test program\n");
00057   if (argc==1)
00058         {
00059       printf("syntax: %s {pos | dac | limit | home | index <axis> | latch <axis> | servo{f}}\n", argv[0]);
00060             exit(-1);   //the program was hard to write, it should be hard to use
00061         }
00062         if (argc > 1)
00063   {
00064       if (!strcmp(argv[1], "pos"))
00065             {
00066                         which = POS;
00067                         }
00068       else if (!strcmp(argv[1], "dac"))
00069                         {
00070                         which = DAC;
00071                         }
00072       else if (!strcmp(argv[1], "limit"))
00073                         {
00074                         which = LIMIT;
00075                         }
00076       else if (!strcmp(argv[1], "home"))
00077                         {
00078                         which = HOME;
00079                         }
00080       else if (!strcmp(argv[1], "servo"))
00081                         {
00082                         which = SERVO;
00083                         }
00084       else if (!strcmp(argv[1], "servof"))
00085                         {
00086                         which = SERVOF;
00087                         }
00088       else if (!strcmp(argv[1], "index"))
00089                         {
00090                         if (1 == sscanf(argv[2], "%d", &axis))
00091                 {
00092                 which = INDEX;
00093                 }
00094                         else
00095                 {
00096                 printf("syntax: %s {pos | dac | limit | home | index <axis> | latch <axis>} | servo\n", argv[0]);
00097                 exit(-1);
00098                 }
00099                         }
00100       else if (!strcmp(argv[1], "latch"))
00101                         {
00102                         if (1 == sscanf(argv[2], "%d", &axis))
00103                 {
00104                 which = LATCH;
00105                 }
00106                         else
00107                 {
00108                 printf("syntax: %s {pos | dac | limit | home | index <axis> | latch <axis>}\n", argv[0]);
00109                 exit(-1);
00110                 }
00111                 }
00112      else
00113                 {
00114               printf("syntax: %s {limit | home | index <axis> | latch <axis>}\n", argv[0]);
00115                         exit(-1);
00116                 }
00117   } // end if argc>1
00118   
00119 
00120   signal(SIGINT, quit);
00121 
00122   ppmcMotInit(NULL);
00123   printf("parport addr 0x%x \n", ppmc_base_addr);
00124 
00125   if (which == POS)
00126   {
00127       while (! done)
00128                         {
00129                                 newline = 0;
00130                                 ppmcEncoderReadAll(NUM_AXES, pos);
00131                                 for (t = 0; t < NUM_AXES; t++)
00132                         {
00133                         if(fabs(pos[t]-oldpos[t]) > 1000.0 && !newline)
00134                                                 {
00135                                                 newline=1;
00136                                                 printf("\n");
00137                                                 }
00138                         oldpos[t] = pos[t];
00139                         }
00140                                 for (t = 0; t < NUM_AXES; t++)
00141                         {
00142                         printf("%+15.3f\t", pos[t]);
00143                         }
00144                                 printf("\r");
00145                                 fflush(stdout);
00146                                 usleep(10000);
00147                         }
00148   }
00149   if (which == SERVO)
00150   {
00151       while (! done)
00152        {
00153           newline = 0;
00154           ppmcEncoderReadAll(NUM_AXES, pos);
00155           for (t = 0; t < NUM_AXES; t++)
00156           {
00157           if(fabs(pos[t]-oldpos[t]) > 1000.0 && !newline)
00158             {
00159             newline=1;
00160             printf("\n");
00161             }
00162           oldpos[t] = pos[t];
00163        }
00164        for (t = 0; t < NUM_AXES; t++)
00165          {
00166            printf("%+12.1f ", pos[t]);
00167            dacval[t] = (pos[t] / 1000.0);
00168          }
00169        printf("   ");
00170        for (t = 0; t < NUM_AXES; t++)
00171          {
00172            printf("%+10.2f ",dacval[t]);
00173          }
00174        printf("\n");
00175        ppmcDacWriteAll(NUM_AXES,dacval);
00176        fflush(stdout);
00177        usleep(10000);
00178     }
00179   }
00180   if (which == SERVOF)
00181   {
00182       while (! done)
00183        {
00184           newline = 0;
00185           ppmcEncoderReadAll(NUM_AXES, pos);
00186           for (t = 0; t < NUM_AXES; t++)
00187          {
00188              dacval[t] = (pos[t] / 1000.0);
00189          }
00190        ppmcDacWriteAll(NUM_AXES,dacval);
00191     }
00192   }
00193   else if (which == LIMIT)
00194   {
00195       while (! done)
00196                         {
00197                         newline=0;
00198                         for (t = 0; t < NUM_AXES; t++)
00199                 {
00200                 ppmcMaxLimitSwitchRead(1, &lim[2*t]);
00201                 if(oldlim[2*t] != lim[2*t] && !newline)
00202                                         {
00203                                         printf("\n");
00204                                         newline=1;
00205                                         }
00206                 oldlim[2*t] = lim[2*t];
00207                 ppmcMinLimitSwitchRead(1, &lim[2*t+1]);
00208                 if(oldlim[2*t+1] != lim[2*t+1] && !newline)
00209                                         {
00210                                         printf("\n");
00211                                         newline=1;
00212                                         }
00213                 oldlim[2*t+1] = lim[2*t+1];
00214                 }
00215                         if(newline)
00216                 {
00217                 for (t = 0; t < NUM_AXES; t++)
00218                                         {
00219                                         printf("%+d\t", lim[2*t]);
00220                                         printf("%+d\t", lim[2*t+1]);
00221                                         }
00222                 printf("\n");
00223                 fflush(stdout);
00224             }
00225                 usleep(10000);
00226                 }
00227   }
00228   else if (which == HOME)
00229   {
00230       while (! done)
00231                         {
00232                         newline=0;
00233                         for (t = 0; t < NUM_AXES; t++)
00234                 {
00235                 ppmcHomeSwitchRead(t, &home[t]);
00236                 if(oldhome[t] != home[t] && !newline)
00237                                         {
00238                                         printf("\n");
00239                                                 newline=1;
00240                                         }
00241                 oldhome[t] = home[t];
00242                 }
00243                         if(newline)
00244                 {
00245                         for (t = 0; t < NUM_AXES; t++)
00246                                                 {
00247                                                 printf("%d\t", home[t]);
00248                                                 }
00249                         printf("\r");
00250                         fflush(stdout);
00251                 }
00252                         usleep(10000);
00253                 }
00254   }
00255   else if (which == INDEX)
00256   {
00257       if (axis < 0 || axis >= NUM_AXES)
00258                         {
00259                         printf("syntax: %s {limit | home | index <axis> | latch <axis>}\n", argv[0]);
00260                         exit(1);
00261                         }
00262 
00263       ppmcEncoderResetIndex(axis);
00264       while (! done)
00265                         {
00266                         ppmcEncoderReadLevel(axis, &index);
00267                         printf("%d ", index);
00268                         fflush(stdout);
00269                         usleep(10000);
00270                         }
00271   }
00272   else if (which == LATCH)
00273   {
00274       if (axis < 0 || axis >= NUM_AXES)
00275                         {
00276                         printf("syntax: %s {limit | home | index <axis> | latch <axis>}\n", argv[0]);
00277                         exit(1);
00278                         }
00279 
00280       ppmcEncoderResetIndex(axis);
00281       while (! done)
00282                         {
00283                                 ppmcEncoderReadLatch(axis, &latch);
00284                                 printf("%d ", latch);
00285                                 fflush(stdout);
00286                                 usleep(10000);
00287                         }
00288         }
00289   else if (which == DAC)
00290         {
00291       printf("Axis? ");
00292       fgets(buf,80,stdin);
00293       axis = (int) strtol(buf,0,0);
00294       while( !done)
00295                         {
00296                                 printf("DAC(%d)",axis);
00297                                 printf("volts? ");
00298                                 if(fgets(buf,80,stdin) == NULL)
00299                                 {
00300                                         printf("got null in dac\n");
00301                                         break;
00302                                 }
00303                                 if(!isdigit(buf[0]) && buf[0] != '-')
00304                                 {
00305                                         printf("non numeric volts , quitting\n");
00306                                         break;
00307                                 }
00308                                 cptr = buf;
00309                                 while((*cptr >= '0' && *cptr <= '9')
00310                                                                 || *cptr == '-' || *cptr == '.' || *cptr == 'E')
00311                                 {
00312                                         cptr++;
00313                                 }
00314                         *cptr = 0;
00315                         volts = strtod(buf,0);
00316                         printf("volts=%f\n",volts);
00317                         ppmcDacWrite(axis, volts);
00318                         }
00319   }  //end if dac
00320 
00321   //ppmcAioQuit();
00322   //ppmcDioQuit();
00323   extMotQuit();
00324 
00325   return 0;
00326 }
00327 
00328 

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