コード例 #1
0
ファイル: InvPartEditor.cpp プロジェクト: nixz/covise
void InvPartEditor::selectByName(char *regExp)
{
    regex_t preg;
    int err = regcomp(&preg, regExp, REG_ICASE | REG_NOSUB);
    if (0 != err)
    {
        //obviously the regular expression was erroneous
        showerr(err);
        return;
    }
    int i;
    for (i = 0; i < numberOfParts_; i++)
    {
        if (0 == regexec(&preg, parts_[i].name_, 0, NULL, REG_NOSUB))
        {
            XmToggleButtonSetState(parts_[i].visible_, True, False);
        }
    }
    apply();
}
コード例 #2
0
ファイル: fandriver2.c プロジェクト: wushuangzhi/Fan-driver
int run() {
	int ret = 0, childpid;
	struct tf_config *newconfig=NULL;
	FILE *pidfile;
	rbuf = malloc(sizeof(char) * 128);

	prefix = "\n";

	if ((config = readconfig(config_file)) == NULL) {
		message(LOG_ERR, MSG_ERR_CONF_NOFILE);
		return ERR_CONF_NOFILE;
	}

	if (config->init_fan()) {
		ret = ERR_FAN_INIT;
		goto bail;
	}

	if (config->get_temp() == ERR_T_GET) {
		ret = ERR_T_GET;
		goto bail;
	}

	if (chk_sanity && ((pidfile = fopen(PID_FILE, "r")) != NULL)) {
		fclose(pidfile);
		message_fg(LOG_ERR, MSG_ERR_RUNNING);
		ret = ERR_PIDFILE;
		goto bail;
	}

	if (depulse) message(LOG_INFO, MSG_INF_DEPULSE(sleeptime, depulse_tmp));

	// So we try to detect most errors before forking...

	if (!nodaemon) {  //如果本程序可以作为一个后台应用程序
		if ((childpid = fork()) != 0) {
			if (!quiet) fprintf(stderr, "Daemon PID: %d\n", childpid);
			ret = 0;
			goto bail;
		}
		if (childpid < 0) {
			perror("fork()");
			ret = ERR_FORK;
			goto bail;
		}
	}

	if ((pidfile = fopen(PID_FILE, "w+")) == NULL) {
		showerr(PID_FILE);
		ret = ERR_PIDFILE;
		goto bail;
	}
	fprintf(pidfile, "%d\n", getpid());
	fclose(pidfile);

	while (1) {
		interrupted = 0;
		if ((ret = fancontrol())) break;
		else if (interrupted == SIGHUP) {
			message(LOG_DEBUG, MSG_DBG_CONF_RELOAD);
			if ((newconfig = readconfig(config_file)) != NULL) {
				free_config(config);
				config = newconfig;
			}
			else message(LOG_ERR, MSG_ERR_CONF_RELOAD);
		}
		else if (SIGINT <= interrupted && interrupted <= SIGTERM) {
			message(LOG_WARNING, "\nCaught deadly signal. ");
			break;
		}
	}

	message(LOG_WARNING, MSG_INF_TERM);
	config->uninit_fan();

	unlink(PID_FILE);

bail:
	free_config(config);
	return ret;
}
コード例 #3
0
ファイル: errorprocess.cpp プロジェクト: sintrb/nesa
/*
该函数用于显示错误信息
2011-01-29
20:00
*/
void  errorprocess::showerr(TYPE_ERROR err)
{
	showerr(err, "");
}
コード例 #4
0
/**************************************************
* Just home the motor and do a bunch of random
* moves.
**************************************************/
int main( void )
{
   // The libraries define one global object of type
   // CopleyMotionLibraries named cml.
   //
   // This object has a couple handy member functions
   // including this one which enables the generation of
   // a log file for debugging
   cml.SetDebugLevel( LOG_EVERYTHING );

   // Create an object used to access the low level CAN network.
   // This examples assumes that we're using the Copley PCI CAN card.
#if defined( USE_CAN )
   CopleyCAN hw( "CAN0" );
   hw.SetBaud( canBPS );
#elif defined( WIN32 )
   WinUdpEcatHardware hw( "eth0" );
#else
   LinuxEcatHardware hw( "eth0" );
#endif

   // Open the network object
#if defined( USE_CAN )
   CanOpen net;
#else
   EtherCAT net;
#endif
   const Error *err = net.Open( hw );
   showerr( err, "Opening network" );

   // Initialize the amplifiers using default settings
   Amp amp[AMPCT];
   AmpSettings set;
   set.guardTime = 0;
   printf( "Doing init\n" );
   int i;
   for( i=0; i<AMPCT; i++ )
   {
      printf( "Initing %d\n", canNodeID+i );
      err = amp[i].Init( net, canNodeID+i, set );
      showerr( err, "Initting amp" );

      MtrInfo mtrInfo;
      err = amp[i].GetMtrInfo( mtrInfo );
      showerr( err, "Getting motor info\n" );

      err = amp[i].SetCountsPerUnit( mtrInfo.ctsPerRev );
      showerr( err, "Setting cpr\n" );
   }

   // Create a linkage object holding these amps
   Linkage link;
   err = link.Init( AMPCT, amp );
   showerr( err, "Linkage init" );

   // Home the amps
   HomeConfig hcfg;
   hcfg.method  = CHM_NONE;
   hcfg.offset  = 0;

   for( i=0; i<AMPCT; i++ )
   {
      // Home the amp.  Notice that the linkage object may be used 
      // like an array to reference the amplifiers.
      err = link[i].GoHome( hcfg );
      showerr( err, "Going home" );
   }

   // Wait for all amplifiers to finish the home by waiting on the
   // linkage object itself.
   printf( "Waiting for home to finish...\n" );
   err = link.WaitMoveDone( 20000 ); 
   showerr( err, "waiting on home" );

   // Setup the velocity, acceleration, deceleration & jerk limits
   // for multi-axis moves using the linkage object
   err = link.SetMoveLimits( 10, 10, 10, 100 );
   showerr( err, "setting move limits" );

   // Do a bunch of random moves.
   for( int j=0; j<5000; j++ )
   {
      // Create an N dimensional position to move to
      Point<AMPCT> pos;

      printf( "%d: moving to ", j );
      for( i=0; i<AMPCT; i++ )
      {
	 pos[i] = (rand() % 100000) / 100000.0;

         if( i ) pos[i] = pos[0];

	 printf( "%.3lf ", pos[i] );
      }
      printf( "\n" );

      // This function will cause the linkage object to create a 
      // multi-axis S-curve move to the new position.  This 
      // trajectory will be passed down to the amplifiers using
      // the PVT trajectory mode
      err = link.MoveTo( pos );
      showerr( err, "Moving linkage" );

      // Wait for the move to finish
      err = link.WaitMoveDone( 1000 * 30 );
      showerr( err, "waiting on linkage done" );
   }

   return 0;
}
コード例 #5
0
ファイル: pegasus-cluster.c プロジェクト: bingzhang/pegasus
static
void
parseCommandline( int argc, char* argv[], 
		  int* fail_hard, int* old_mode, int* cpus )
{
  char *s, *ptr = strrchr( argv[0], '/' );
  int option, tmp;

  /* exit code 0 is always good, just in case */
  memset( success, 0, sizeof(success) );
  success[0] = 1;
  *cpus = 1; 

  if ( ptr == NULL ) ptr = argv[0];
  else ptr++;
  application = ptr;

  /* default progress report location from environment variable */
  if ( (s = getenv("SEQEXEC_PROGRESS_REPORT")) != NULL ) {
    if ( (progress = open( s, O_WRONLY | O_APPEND | O_CREAT, 0666 )) == -1 ) {
      showerr( "%s: open progress %s: %d: %s\n",
	       application, s, errno, strerror(errno) );
    }
  }

  /* default parallelism from environment variable */ 
  if ( (s = getenv("SEQEXEC_CPUS")) != NULL ) { 
    if ( strcasecmp( s, "auto" ) == 0 ) *cpus = processors();
    else *cpus = atoi(s); 
    if ( *cpus < 0 ) *cpus = 1; 
  }

  opterr = 0;
  while ( (option = getopt( argc, argv, "R:S:defhn:s:" )) != -1 ) {
    switch ( option ) {
    case 'R':
      if ( progress != -1 ) close(progress);
      if ( (progress = open( optarg, O_WRONLY | O_APPEND | O_CREAT, 0666 )) == -1 ) {
	showerr( "%s: open progress %s: %d: %s\n",
		 application, optarg, errno, strerror(errno) );
      }
      break;

    case 'S':
      tmp = atoi(optarg);
      if ( tmp > 0 && tmp < sizeof(success) ) success[tmp] = 1;
      else showerr( "%s: Ignoring unreasonable success code %d\n", application, tmp );
      break;

    case 'd':
      debug++;
      break;

    case 'e':
      *old_mode = 1;
      *fail_hard = 0;
      break;

    case 'f':
      *fail_hard = 1;
      *old_mode = 0;
      break;

    case 'n':
      if ( strcasecmp( optarg, "auto" ) == 0 ) *cpus = processors();
      else *cpus = atoi(optarg); 
      if ( *cpus < 0 ) *cpus = 1; 
      break;

    case 's':
      if ( freopen( optarg, "w", stdout ) == NULL ) {
	showerr( "%s: open status %s: %d: %s\n",
		 application, optarg, errno, strerror(errno) );
	exit(2);
      }
      break;

    case 'h':
    case '?':
      helpMe( ptr, 0 );
      break;

    default:
      helpMe( ptr, 1 );
      break;
    }
  }

  if ( (argc - optind) > 1 ) helpMe( ptr, 1 );
  if ( argc != optind ) {
    if ( (freopen( argv[optind], "r", stdin )) == NULL ) {
      showerr( "%s: open input %s: %d: %s\n",
	       application, argv[optind], errno, strerror(errno) );
      exit(3);
    }
  }
}
コード例 #6
0
/* initialize variables */
int init_hist_np()
{
	chamber_p  chamb;
	int        ipl;
	double     d;
	int        i, n;

	/* initialyze for Target Chamber MWDC */
	chamb = &tgc_mwdc;
	chamb->name = "TGC";
	chamb->type = CHAMB_MWDC;
	chamb->npl  = 10;
	chamb->plane = (plane_p)malloc(sizeof(plane_t)*chamb->npl);
	chamb->plane[0].name = "VT1";
	chamb->plane[1].name = "VT2";
	chamb->plane[2].name = "VT3";
	chamb->plane[3].name = "VT4";
	chamb->plane[4].name = "X1";
	chamb->plane[5].name = "X2";
	chamb->plane[6].name = "U1";
	chamb->plane[7].name = "U2";
	chamb->plane[8].name = "V1";
	chamb->plane[9].name = "V2";
	for(ipl=0; ipl<chamb->npl; ipl++){
		chamb->plane[ipl].chamb = chamb;
	}
	chamb_init_hist(chamb);
	n = 1<<chamb->npl;
	chamb->matrix = (void*)malloc(sizeof(mat_p)*n);
	for(i=0; i<n; i++) ((mat_p*)chamb->matrix)[i] = (mat_p)NULL;
	chamb->mb = matrix_new(4,1);
	chamb->mc = matrix_new(4,1);
	if(chamb->matrix==NULL||chamb->mb==NULL||chamb->mc==NULL){
		showerr("init_hist_np: No enough memory available\n");
		exit(1);
	}

	/* initialyze for Front-end Chamber MWDC */
	chamb = &fec_mwdc;
	chamb->name = "FEC";
	chamb->type = CHAMB_MWDC;
	chamb->npl  = 6;
	chamb->plane = (plane_p)malloc(sizeof(plane_t)*chamb->npl);
	chamb->plane[0].name = "Y1";
	chamb->plane[1].name = "Y2";
	chamb->plane[2].name = "V1";
	chamb->plane[3].name = "V2";
	chamb->plane[4].name = "U1";
	chamb->plane[5].name = "U2";
	for(ipl=0; ipl<chamb->npl; ipl++){
		chamb->plane[ipl].chamb = chamb;
	}
	chamb_init_hist(chamb);
	n = 1<<chamb->npl;
	chamb->matrix = (void*)malloc(sizeof(mat_p)*n);
	for(i=0; i<n; i++) ((mat_p*)chamb->matrix)[i] = (mat_p)NULL;
	chamb->mb = matrix_new(4,1);
	chamb->mc = matrix_new(4,1);
	if(chamb->matrix==NULL||chamb->mb==NULL||chamb->mc==NULL){
		showerr("init_hist_np: No enough memory available\n");
		exit(1);
	}
}
コード例 #7
0
/* description:	Initialize the motor,the motor can work in three diffrient mode
								posiotion,velocity,torque.this one is initialed to torque,modify
								the code if needed
//		function: void motor_init(void)
//			@param: 
//return value:	
*/
void motor_init(void)
{  
	static char message[32];
	uint8 err;
	sprintf(message, "velocity started:\r\n");
  UART0_SendStr (message);
	
	
	//get initial position step:0
	uint32 pos;
	err=GetPosition(&pos);
	if(err){showerr(err,0);}
  else{
	sprintf(message, "initial pos: %4d\r\n",pos);
  UART0_SendStr (message);
		}

	//	set homing mode step:1
	err=SetHomeMode(1);
  if(err){showerr(err,1);}
	
	//	set homing method step:2
	//	here the mean of homing is that
	//  to use the current position as homing position
	err=Dnld8(OBJID_HOME_METHOD, 0, (uint8)35,2);
  if(err){showerr(err,2);} 
	 
	//	shutdown step:3
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x06,3);
  if(err){showerr(err,3);}
	
	//wait at least 3ms to avoid the Priority inversion
   sysDelayNS(3);
	 
	//	switch on step:4
  err=Dnld16(OBJID_CONTROL, 0, (uint16)0x07,4);
  if(err){showerr(err,4);}
	
	//	enable operation step:5
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x0f,5);
  if(err){showerr(err,5);}
	
	//	 start home mode step:6
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x1f,6);
  if(err){showerr(err,6);}
	 
	//	 home mode active step:7
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x1f,7);
  if(err){showerr(err,7);}
   
   sysDelayNS(10);
	 
	//get current position step:8
	err=GetPosition(&pos);
	if(err){showerr(err,8);}
	else{
	sprintf(message, "current pos: %4d\r\n",pos);
  UART0_SendStr (message);
		}
	//===================================
    
  //	set position mode step:9
	err=SetPositionMode(1);
  if(err){showerr(err,9);}	
	
  //	shutdown step:10
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x06,2);
  if(err){showerr(err,10);}
  
	//	switch on step:11
  err=Dnld16(OBJID_CONTROL, 0, (uint16)0x07,3);
  if(err){showerr(err,11);}
	
	//wait at least 3ms to avoid the Priority inversion
   sysDelayNS(3);

	//	enable operation step:12
	err=Dnld16(OBJID_CONTROL, 0, (uint16)0x0f,4);
  if(err){showerr(err,12);}

// 	while(1){;} //just for debug
}
コード例 #8
0
int main( void )
{

   ////////////////////////////////////////////////////////////////////////////////////////// VVV Initialization and Homing VVV
   //cout << "ayy lmao\n"; //For debugging

   ////////////////////Set up Copley Libraries///////////
   // The libraries define one global object of type
   // CopleyMotionLibraries named cml.
   //
   // This object has a couple handy member functions
   // including this one which enables the generation of
   // a log file for debugging
   cml.SetDebugLevel( LOG_EVERYTHING );

   // Create an object used to access the low level CAN network.
   // This examples assumes that we're using the Copley PCI CAN card.
   #if defined( USE_CAN )
      KvaserCAN hw( "CAN0" );
      hw.SetBaud( canBPS );
   #elif defined( WIN32 )
      WinUdpEcatHardware hw( "eth0" );
   #else
      LinuxEcatHardware hw( "eth0" );
   #endif

      // Open the network object
   #if defined( USE_CAN )
      CanOpen net;
   #else
      EtherCAT net;
   #endif

   const Error *err;
   int i;
   Amp amp[AMPCT];
   if(robotPlugged){
      err = net.Open( hw );
      showerr( err, "Opening network" );

      // Initialize the amplifiers using default settings
      AmpSettings set;
      set.guardTime = 0;

      cout << "Doing initialization"<<endl;
      for( i=0; i<AMPCT; i++ )
      {
         //printf( "Initiating Amplifier %d\n", canNodeID+i );
         cout << "Initializing Amplifier " << (canNodeID+i) << endl;

         err = amp[i].Init( net, canNodeID+i, set );
         showerr( err, "Initting amp" );

         MtrInfo mtrInfo;
         err = amp[i].GetMtrInfo( mtrInfo );
         showerr( err, "Getting motor info\n" );

         // err = amp[i].SetCountsPerUnit( mtrInfo.ctsPerRev );
         // printf( "CountsPerRev %d\n", mtrInfo.ctsPerRev );

         err = amp[i].SetCountsPerUnit( 8000.0/5.0);     // User Units are now in mm
         showerr( err, "Setting cpr\n" );
      }
   }
      // Create a linkage object holding these amps
      Linkage link;

   if(robotPlugged){
      err = link.Init( AMPCT, amp );
      showerr( err, "Linkage init" );

      // Home the amps
      HomeConfig hcfg;
      err = link[0].GetHomeConfig(hcfg);
      showerr(err, "get Home Config");
      hcfg.velFast = 5;
      hcfg.velSlow = 1;
      hcfg.accel = 10;
      hcfg.method  = CHM_NHOME_INDX;   // CHM_NONE;
      hcfg.offset  = 0;
      printf( "Home Velocity %f \n", hcfg.velFast );
      printf( "Home Velocity Slow %f \n", hcfg.velSlow );

      
      // Setup the velocity, acceleration, deceleration & jerk limits
      // for multi-axis moves using the linkage object
      err = link.SetMoveLimits( 75, 75, 75, 100 );
      showerr( err, "setting move limits" );

      // Create an N dimensional position to move to
      Point<AMPCT> act;

      for( i=0; i<AMPCT; i++ )
      {
         // Assuming we are low to the ground and centered, first move forward 30mm. 
         //Notice that the linkage object may be used like an array to reference the amplifiers.
         double currentPosition;
         err = link[i].GetPositionActual(currentPosition);
         printf( "Current Position %f \n", currentPosition );
         showerr( err, "ActualPosition" );
         
         act[i]= currentPosition+50; //in mm

         // if(currentPosition<0){
         //    act[i]= currentPosition+(0-currentPosition)+2.5; //in mm
         // }else{
         //    act[i]= 2.5;
         // }
         printf( "Goal Position %f mm \n", act[i]);
      }

      err = link.MoveTo( act );
      showerr( err, "Moving linkage" );

      // Wait for all amplifiers to finish the initial move by waiting on the
      // linkage object itself.
      printf( "Waiting for move up to finish...\n" );
      err = link.WaitMoveDone( 20000 ); 
      showerr( err, "waiting on initial move" );
      

      for( i=0; i<AMPCT; i++ )
      {
         // Home the amp.  Notice that the linkage object may be used 
         // like an array to reference the amplifiers.
         if(i==0){
            hcfg.offset  = 2;
         }else if(i==2 || i==3){
            hcfg.offset  = -0.75;
         }else if(i==4){
            hcfg.offset  = -1;
         }else{
            hcfg.offset  = 0;
         }

         err = link[i].GoHome(hcfg); // hcfg 
         showerr( err, "Going home" );
      }

      // Wait for all amplifiers to finish the home by waiting on the
      // linkage object itself.
      printf( "Waiting for home to finish...\n" );
      err = link.WaitMoveDone( 20000 ); 
      showerr( err, "waiting on home" );
   }
   
   ////////////////////////////////////////////////////////////////////////////////////////// ^^^ Initialization and Homing Complete. ^^^

   // Create an N dimensional position to move to
   Point<AMPCT> act;

   act[0] = 99-1;
   act[1] = 99-2;
   act[2] = 99-2.5;
   act[3] = 99-1;
   act[4] = 99-2;
   act[5] = 99-.5;
   // Z is 45.75 inches


   if(robotPlugged){
      err = link.MoveTo( act );
      showerr( err, "Moving linkage" );
      // Wait for all amplifiers to finish the initial move by waiting on the
      // linkage object itself.
      printf( "Waiting for move up to finish...\n" );
      err = link.WaitMoveDone( 20000 ); 
      showerr( err, "waiting on initial move" );
   }

   // Create an N dimensional slide vector
   // Point<AMPCT> q;
   double q[AMPCT];
   char msgBack;
   char qMsg[sizeof(double)];
   double qTemp;

   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////Main Function
   while(isRunning){
      std::cout<< "RUN CHECK\n";

      msgBack = std::cin.get();
      std::cout<< "CPP Receieves Message!\n";
      isRunning = msgBack-48;

      if(isRunning){
         std::cout<< "RUN OK\n";

         //Check if valid q. If not, then isRunning = false, break. Or, try again. 
         int checker = 0;
         for (int i = 0; i<AMPCT; i++){
            std::cout<< "GIMME\n";

            for (int j = 0; j<sizeof(double); j++){
                  qMsg[j] = std::cin.get();
                  std::cout<< qMsg[j] <<endl;
            }

            //printf("Received:%s\n", qMsg );

            memcpy(&qTemp,&qMsg,sizeof(double));
            printf( "Converted %f \n", qTemp);

            q[i] = qTemp;
            
            if(SIGMA2ACTUATOR - q[i]<=250 && SIGMA2ACTUATOR - q[i] >= 0){
               checker++;
            }
         }
         for (int i = 0; i<AMPCT; i+=2){
            if(sqrt(q[i]*q[i]+q[i]*q[i+1]+q[i+1]*q[i+1])<=MAXWIDTH){
               checker+=2;
            }
         }

         if(checker == 2*AMPCT){
            checker = 0;
            std::cout<< "GOOD Q\n";
            std::cout<< "Moving to point...\n";
            //If all safe, Assign vector act[] with the new coords. If not, stay. 
            //Convert from q (sigma coords) to actuator coords (0 to 300mm)
            act[0] = SIGMA2ACTUATOR - q[0];
            act[1] = SIGMA2ACTUATOR - q[1];
            act[2] = SIGMA2ACTUATOR - q[2];
            act[3] = SIGMA2ACTUATOR - q[3];
            act[4] = SIGMA2ACTUATOR - q[4];
            act[5] = SIGMA2ACTUATOR - q[5];
            if(robotPlugged){
               err = link.MoveTo( act );
               showerr( err, "Moving linkage" );

               // Wait for all amplifiers to finish the initial move by waiting on the
               // linkage object itself.
               printf( "Waiting for move up to finish...\n" );
               err = link.WaitMoveDone( 20000 ); 
               showerr( err, "waiting on initial move" );
            }
         }else{
            checker = 0;
            std::cout<< "BAD Q\n";
            std::cout<< "Please try again...\n";
         }      
         
         // tell Python we're done with this move. 
         std::cout<<"Move Done.\n";
      }else{
         std::cout<<"Ending Program...\n";
      }

   }

   //////////////////////////////////////////////////////////////////////////////////////Go to home position before ending

   act[0] = 0;
   act[1] = 0;
   act[2] = 0;
   act[3] = 0;
   act[4] = 0;
   act[5] = 0;

   //cout << "Press ENTER to coninue...";
   //std::cin.ignore();
   if(robotPlugged){
      err = link.MoveTo( act );
      showerr( err, "Moving linkage" );

      // Wait for all amplifiers to finish the initial move by waiting on the
      // linkage object itself.
      printf( "Waiting for move up to finish...\n" );
      err = link.WaitMoveDone( 20000 ); 
      showerr( err, "waiting on initial move" );
   }
   
   return 0;
}