Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "MIKRO.h"
  4.  
  5.  
  6. #include <getopt.h>
  7.  
  8. #define MIKRO_COM "/dev/ttyUSB0"
  9.  
  10. int help(){
  11.   fprintf(stderr,"Usage: mikro [-i node][-n node] [-u up] [-d down] [-r node] [-h node] [-a] [-g] [-m pos]\n");
  12.   fprintf(stderr,"      Options:\n");
  13.   fprintf(stderr,"[-n node] -i type  .. initialize node + save to EEPROM\n");
  14.   fprintf(stderr,"            (1=3MLin,2=3MRot,3=4MLin,4=4MRot,0=skip\n");
  15.   fprintf(stderr," -n node -h   .. homing procedure for node\n");
  16.   fprintf(stderr," -n node -r   .. reset node\n");
  17.   fprintf(stderr," -n node -u   .. move node for +1000\n");
  18.   fprintf(stderr," -n node -d   .. move node for -1000\n");
  19.   fprintf(stderr,"[-n node] -a   .. current status of the nodes\n");
  20.   fprintf(stderr," -n node -v value -s cmd   .. set value of the cmd on the node\n");
  21.   fprintf(stderr," -n node -g cmd   .. get value of the cmd on the node\n");          
  22.   fprintf(stderr," -n node -m position   .. move node to position\n");
  23.   fprintf(stderr," -l delaysec  .. loop test with the delay delaysec\n");          
  24.   return 0;
  25. }
  26.  
  27. int main (int argc, char ** argv){
  28.   int i,j,k;
  29.   int node=0,opt,value=0,itype=0;
  30.   int nr_nodes=3;
  31.   int ierr;
  32.   int pos,xpos,ypos,zpos;
  33.   char custcmd[20];
  34.   char statbits[16][10]={"Moving","In-Pos","Mode","AMN Mode","%Done","DNet","DNErr","FD-Error",
  35.                          "Disable","R-Lim","Local","Estop","Event1","P-Lim","Event2","N-Lim"};
  36.  
  37.   MIKRO_Open (MIKRO_COM);
  38.  
  39.   // ":" just indicates that this option needs an argument
  40.   while ((opt = getopt(argc, argv, "i:av:s:l:udn:c:pm:g:hre")) != -1) {
  41.     switch (opt) {
  42.      case 'i':
  43.       itype = atoi(optarg);
  44.       if(node != 0)
  45.         MIKRO_Init (node,itype);
  46.        else
  47.         for(i=1; i<nr_nodes+1; i++) MIKRO_Init (i,itype);
  48.       break;
  49.      case 'a':
  50.       if(node != 0) {
  51.         pos=0;
  52.         ierr=MIKRO_GetStat(node);
  53.         MIKRO_GetPosition (node, &pos);
  54.         printf("node %d position %d status =%04x\n",node,pos,ierr);
  55.         for(i=0; i<16; i++){
  56.           printf("%d: %s\n", (ierr&1),statbits[i]);
  57.           ierr>>=1;
  58.         }
  59.       }else{
  60.         pos=0;
  61.         for (j=1;j<nr_nodes+1;j++){
  62.           ierr=MIKRO_GetStat(j);
  63.           MIKRO_GetPosition (j, &pos);
  64.           printf("node %d position %d status =%04x\n",j,pos,ierr);
  65.           for(i=0; i<16; i++){
  66.             printf("%d: %s\n", (ierr&1),statbits[i]);
  67.             ierr>>=1;
  68.           }
  69.         }
  70.       }
  71.       break;
  72.      case 'l':
  73.       printf("MIKRO_MoveTo Loop\n");
  74.       for (i=0;i<5;i++){
  75.         xpos=i*1000+10000;
  76.         MIKRO_MoveTo (1, xpos);
  77.         for (j=0;j<5;j++){
  78.           ypos=j*1000+10000;
  79.           MIKRO_MoveTo (2, ypos);
  80.           for (k=0;k<50;k++){
  81.             zpos=k*1000+10000;
  82.             MIKRO_MoveTo (3, zpos);
  83.             printf("x=%d y=%d z=%d\n",xpos,ypos,zpos);
  84.             Delay(atof(optarg));
  85.           }
  86.         }
  87.       }
  88.       break;
  89.      case 'n':
  90.       node = atoi(optarg);
  91.       break;
  92.      case 'm':
  93.       MIKRO_MoveTo (node, atoi(optarg));
  94.       printf("MIKRO_MoveTo node=%d pos=%d \n",node,atoi(optarg));
  95.       MIKRO_GetPosition (node, &i);
  96.       printf("node %d position %d \n",node,i);
  97.       break;
  98.      case 'v':
  99.       value=atoi(optarg);
  100.       break;
  101.      case 's':
  102.       MIKRO_Set (node,optarg,value);
  103.       printf("MIKRO_Set node %d  cmd=%s val=%d\n",node,optarg, value);
  104.       break;
  105.      case 'g':
  106.       MIKRO_Get (node,optarg,&i);
  107.       printf("MIKRO_Get node %d  cmd=%s val=%d\n",node,optarg, i);
  108.       break;
  109.      case 'h':
  110.       printf("MIKRO_ReferenceMove node=%d\n",node);
  111.       MIKRO_ReferenceMove (node);
  112.       break;
  113.      case 'r':
  114.       printf("MIKRO_Reset node=%d\n",node);
  115.       MIKRO_Reset (node);
  116.       break;
  117.      case 'u':
  118.       MIKRO_Set(node,"lr", 1000);
  119.       MIKRO_Cmd(node,"mv");
  120.       break;
  121.      case 'd':
  122.       MIKRO_Set(node,"lr", -1000);
  123.       MIKRO_Cmd(node,"mv");
  124.       break;
  125.      case 'e':
  126.       MIKRO_Cmd(node,"ab");
  127.       MIKRO_Cmd(node,"n 2");
  128.       MIKRO_Cmd(node,"en");
  129.       break;
  130.      case 'c': // cust. com.
  131.       sprintf(custcmd,"%s",optarg);
  132.       MIKRO_Cmd(node,custcmd);
  133.       break;
  134.      case 'p': // get pos.
  135.       if(node != 0){
  136.         MIKRO_GetPosition (node, &pos);
  137.         printf("%d\n",pos);
  138.       }
  139.       break;
  140.      default: // '?'
  141.       help();
  142.       break;
  143.     }
  144.   }
  145.   if (argc==1) help();
  146.   MIKRO_Close ();
  147.   return 0;
  148. }
  149.