Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

#include <stdlib.h>
#include <stdio.h>
#include "MIKRO.h"


#include <getopt.h>

#define MIKRO_COM "/dev/ttyUSB0"

int help(){
  fprintf(stderr,"Usage: mikro [-i node][-n node] [-u up] [-d down] [-r node] [-h node] [-a] [-g] [-m pos]\n");
  fprintf(stderr,"      Options:\n");
  fprintf(stderr,"[-n node] -i type  .. initialize node + save to EEPROM\n");
  fprintf(stderr,"            (1=3MLin,2=3MRot,3=4MLin,4=4MRot,0=skip\n");
  fprintf(stderr," -n node -h   .. homing procedure for node\n");
  fprintf(stderr," -n node -r   .. reset node\n");
  fprintf(stderr," -n node -u   .. move node for +1000\n");
  fprintf(stderr," -n node -d   .. move node for -1000\n");
  fprintf(stderr,"[-n node] -a   .. current status of the nodes\n");
  fprintf(stderr," -n node -v value -s cmd   .. set value of the cmd on the node\n");
  fprintf(stderr," -n node -g cmd   .. get value of the cmd on the node\n");          
  fprintf(stderr," -n node -m position   .. move node to position\n");
  fprintf(stderr," -l delaysec  .. loop test with the delay delaysec\n");          
  return 0;
}

int main (int argc, char ** argv){
  int i,j,k;
  int node=0,opt,value=0,itype=0;
  int nr_nodes=3;
  int ierr;
  int pos,xpos,ypos,zpos;
  char custcmd[20];
  char statbits[16][10]={"Moving","In-Pos","Mode","AMN Mode","%Done","DNet","DNErr","FD-Error",
                         "Disable","R-Lim","Local","Estop","Event1","P-Lim","Event2","N-Lim"};

  MIKRO_Open (MIKRO_COM);

  // ":" just indicates that this option needs an argument
  while ((opt = getopt(argc, argv, "i:av:s:l:udn:c:pm:g:hre")) != -1) {
    switch (opt) {
     case 'i':
      itype = atoi(optarg);
      if(node != 0)
        MIKRO_Init (node,itype);
       else
        for(i=1; i<nr_nodes+1; i++) MIKRO_Init (i,itype);
      break;
     case 'a':
      if(node != 0) {
        pos=0;
        ierr=MIKRO_GetStat(node);
        MIKRO_GetPosition (node, &pos);
        printf("node %d position %d status =%04x\n",node,pos,ierr);
        for(i=0; i<16; i++){
          printf("%d: %s\n", (ierr&1),statbits[i]);
          ierr>>=1;
        }
      }else{
        pos=0;
        for (j=1;j<nr_nodes+1;j++){
          ierr=MIKRO_GetStat(j);
          MIKRO_GetPosition (j, &pos);
          printf("node %d position %d status =%04x\n",j,pos,ierr);
          for(i=0; i<16; i++){
            printf("%d: %s\n", (ierr&1),statbits[i]);
            ierr>>=1;
          }
        }
      }
      break;
     case 'l':
      printf("MIKRO_MoveTo Loop\n");
      for (i=0;i<5;i++){
        xpos=i*1000+10000;
        MIKRO_MoveTo (1, xpos);
        for (j=0;j<5;j++){
          ypos=j*1000+10000;
          MIKRO_MoveTo (2, ypos);
          for (k=0;k<50;k++){
            zpos=k*1000+10000;
            MIKRO_MoveTo (3, zpos);
            printf("x=%d y=%d z=%d\n",xpos,ypos,zpos);
            Delay(atof(optarg));
          }
        }
      }
      break;
     case 'n':
      node = atoi(optarg);
      break;
     case 'm':
      MIKRO_MoveTo (node, atoi(optarg));
      printf("MIKRO_MoveTo node=%d pos=%d \n",node,atoi(optarg));
      MIKRO_GetPosition (node, &i);
      printf("node %d position %d \n",node,i);
      break;
     case 'v':
      value=atoi(optarg);
      break;
     case 's':
      MIKRO_Set (node,optarg,value);
      printf("MIKRO_Set node %d  cmd=%s val=%d\n",node,optarg, value);
      break;
     case 'g':
      MIKRO_Get (node,optarg,&i);
      printf("MIKRO_Get node %d  cmd=%s val=%d\n",node,optarg, i);
      break;
     case 'h':
      printf("MIKRO_ReferenceMove node=%d\n",node);
      MIKRO_ReferenceMove (node);
      break;
     case 'r':
      printf("MIKRO_Reset node=%d\n",node);
      MIKRO_Reset (node);
      break;
     case 'u':
      MIKRO_Set(node,"lr", 1000);
      MIKRO_Cmd(node,"mv");
      break;
     case 'd':
      MIKRO_Set(node,"lr", -1000);
      MIKRO_Cmd(node,"mv");
      break;
     case 'e':
      MIKRO_Cmd(node,"ab");
      MIKRO_Cmd(node,"n 2");
      MIKRO_Cmd(node,"en");
      break;
     case 'c': // cust. com.
      sprintf(custcmd,"%s",optarg);
      MIKRO_Cmd(node,custcmd);
      break;
     case 'p': // get pos.
      if(node != 0){
        MIKRO_GetPosition (node, &pos);
        printf("%d\n",pos);
      }
      break;
     default: // '?'
      help();
      break;
    }
  }
  if (argc==1) help();
  MIKRO_Close ();
  return 0;
}