예제 #1
0
//! The main function.
int main(int argc, char **argv)
{
  pruIo *Io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1); //! ouvrir l'interruption Pruss (/ dev / uio5),charger les instructions de pasm_init.p au PRU et les exécute, et appeler les fonctions initialize des UDT du sous-système.
  do {
    if (Io->Errr) {
               printf("initialisation failed (%s)\n", Io->Errr); break;}

    if (pruio_cap_config(Io, P_IN, 2.)) { //         Cette fonction configure un axe d'en-tête pour la capture et Analyse Pulse (CAP) trains. La configuration des broches est vérifié. Si elle est pas configuré comme entrée pour le module de la Cap dans le sous-système PWM, libpruio essaie d'adapter le muxing broches.
          printf("failed setting input @P_IN (%s)\n", Io->Errr); break;}

    float_t
        f1 //                         Variable for calculated frequency.
      , d1 //                        Variable for calculated duty cycle.
      , f0 = 31250 //                            The required frequency.
      , d0 = .5;   //                           The required duty cycle.
      
    if (pruio_pwm_setValue(Io, P_OUT, f0, d0)) { //Cette fonction définit la sortie PWM sur une broche d'en-tête. sortie PWM peuvent être soit générés par un eHRPWM ou d'un module eCAP. En fonction du nombre de broches spécifié (paramètre à billes), le module PWM correspondant est configuré pour la fréquence et le rapport cyclique déterminé.
        printf("failed setting output @P_OUT (%s)\n", Io->Errr); break;}


    if (pruio_config(Io, 1, 0x1FE, 0, 4)) { //Cette fonction est utilisée pour télécharger la configuration de l'hôte (ARM) au conducteur (PRU). Le PRU s'arrêté (si en cours d'exécution) et les nouvelles configurations se charger. Aussi les instructions Pru_Run se ré-initialisés.
                       printf("config failed (%s)\n", Io->Errr); break;}

    struct termios oldt, newt; //             make terminal non-blocking
    tcgetattr( STDIN_FILENO, &oldt );
    newt = oldt;
    newt.c_lflag &= ~( ICANON );
    newt.c_cc[VMIN] = 0;
    newt.c_cc[VTIME] = 1;
    tcsetattr( STDIN_FILENO, TCSANOW, &newt );

    while(1) { //                                       run endless loop
      if (1 == isleep(1)) {
        
        if (pruio_pwm_setValue(Io, P_OUT, f0, d0)) { //   set new output
           printf("failed setting PWM output (%s)\n", Io->Errr); break;}

        printf("\n--> Frequency: %10f , Duty: %10f\n", f0, d0); //  info
      }

      if (pruio_cap_Value(Io, P_IN, &f1, &d1)) { //    get current input
          printf("failed reading input @P_IN (%s)\n", Io->Errr); break;}

      printf("\r    Frequency: %10f , Duty: %10f     ", f1, d1); // info
      fflush(STDIN_FILENO);
    }

finish:
    tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); //         reset terminal

    printf("\n");
  } while (0);

  pruio_destroy(Io);       /* destroy driver structure */
	return 0;
}
예제 #2
0
파일: mpu_main.c 프로젝트: mvf4z7/rosa
int main( int argc, char *argv[] )
{
    float temp;
    uint32 cur_time;
    uint32 start_time;
    float duty_cycle;
    float target_temp;
    char print_string[ 200 ];

    util_print_procId();

    force_stop = FALSE;
    door_open = FALSE;

    timer_init();

    if( argc != 2 )
    {
        util_print_debug( "Error: The only argument is the path to the JSON file.\n" );
        return( -1 );
    }

    //Set up signal handler:
    if( signal( SIGINT, signalHandler ) == SIG_ERR )
    {
        util_print_debug( "MPU: Error setting up ctrl-c interrupt.\n" );
        return( -1 );
    }

    util_print_debug( argv[ 1 ] );

    if( !pid_init( argv[ 1 ] ) )
    {
        util_print_debug( "Error: There was an error loading the profile.\n" );
        return( -1 );
    }

    pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1);

    start_time = 0;
    cur_time = 0;
    duty_cycle = 1.0;

    if( pruio_config( io, 1, 0x1FE, 0, 4 ) )
    {
        sprintf( print_string, "config failed (%s)\n", io->Errr );
        util_print_debug( print_string );
        return( -1 );
    }
    
    pruio_pwm_setValue( io, P_OUT, PWM_FREQ, duty_cycle );
    pruio_pwm_setValue( io, SERVO_PIN, SERVO_FREQ, SERVO_DUTY_CLOSE ); //close door

    while( !force_stop )
    {
        temp = util_calc_temp( io->Adc->Value[ 1 ] );
        target_temp = pid_find_target( cur_time / 1000.0 );
        duty_cycle = pid_calc( target_temp, temp );
        pruio_pwm_setValue( io, SERVO_PIN, SERVO_FREQ, SERVO_DUTY_IDLE );

        if( duty_cycle == -1 )
        {
            force_stop = TRUE;
        }

        // DOOR CRACKING CODE
        if ( ( temp - target_temp) > 5.0 )
        {
          // OPEN DOOR
            pruio_pwm_setValue( io, SERVO_PIN, SERVO_FREQ, SERVO_DUTY_OPEN );
            door_open = TRUE;
        }

        else if ( ( duty_cycle > 0.0 ) && door_open )
        {
          // CLOSE DOOR
            pruio_pwm_setValue( io, SERVO_PIN, SERVO_FREQ, SERVO_DUTY_CLOSE );
            door_open = FALSE;
        }

        pruio_pwm_setValue( io, P_OUT, -1, duty_cycle );

        util_print_point( cur_time / 1000, target_temp, temp );

        //block for 2 seconds.
        while( ( cur_time - start_time <= PWM_PERIOD_MS ) && !force_stop )
        {
            if( !timer_get( &cur_time ) )
            {
                printf( "There was an error with the timer.\n" );
                return( 0 );
            }
        }

        start_time = start_time + PWM_PERIOD_MS;
    }

    // I WISH WE COULD WAIT UNTIL THE OVEN IS AT 100 DEGREES C TO CLOSE THIS DOWN
    pruio_pwm_setValue( io, P_OUT, -1, 0.0f );
    pruio_pwm_setValue( io, SERVO_PIN, SERVO_FREQ, SERVO_DUTY_CLOSE ); // CLOSE THE DOOR
    
    // STALL BEFORE SHUTTING DOWN PWM
    timer_get( &start_time );
    cur_time = start_time;
    while( ( cur_time - start_time ) < 500 )
    {
        timer_get( &cur_time );
    }

    pruio_destroy(io);       /* destroy driver structure */ 
    
    return 0;
}
예제 #3
0
파일: adc_test.c 프로젝트: mvf4z7/rosa
//! The main function.
int main(int argc, char **argv)
{
  pruIo *Io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1); //! create new driver structure
  do {
    if (Io->Errr) {
               printf("initialisation failed (%s)\n", Io->Errr); break;}

    if (pruio_cap_config(Io, P_IN, 2.)) { //         configure input pin
          printf("failed setting input @P_IN (%s)\n", Io->Errr); break;}

    float_t
        f1 //                         Variable for calculated frequency.
      , d1 //                        Variable for calculated duty cycle.
      , f0 = .5 //                            The required frequency.
      , d0 = .5;   //                           The required duty cycle.
    if (pruio_pwm_setValue(Io, P_OUT, f0, d0)) {
        printf("failed setting output @P_OUT (%s)\n", Io->Errr); break;}

    //           pin config OK, transfer local settings to PRU and start
    if (pruio_config(Io, 1, 0x1FE, 0, 4)) {
                       printf("config failed (%s)\n", Io->Errr); break;}

    struct termios oldt, newt; //             make terminal non-blocking
    tcgetattr( STDIN_FILENO, &oldt );
    newt = oldt;
    newt.c_lflag &= ~( ICANON );
    newt.c_cc[VMIN] = 0;
    newt.c_cc[VTIME] = 1;
    tcsetattr( STDIN_FILENO, TCSANOW, &newt );

    while(1) { //                                       run endless loop
      if (1 == isleep(1)) {
        switch (getchar()) { //                       evaluate keystroke
          case '0' : d0 = 0.0; break;
          case '1' : d0 = 0.1; break;
          case '2' : d0 = 0.2; break;
          case '3' : d0 = 0.3; break;
          case '4' : d0 = 0.4; break;
          case '5' : d0 = 0.5; break;
          case '6' : d0 = 0.6; break;
          case '7' : d0 = 0.7; break;
          case '8' : d0 = 0.8; break;
          case '9' : d0 = 0.9; break;
          case ',' : d0 = 1.0; break;
          case 'm' : f0 = (f0 > 5.5 ? f0 - 5. : .5); break;
          case 'p' : f0 = (f0 < 999995. ? f0 + 5. : 1000000.); break;
          case '*' : f0 = (f0 < 1000000 ? f0 * 2 : 1000000.); break;
          case '/' : f0 = (f0 > .5 ? f0 / 2 : .5); break;
          case '+' : f0 = 1000000; break;
          case '-' : f0 = .5; break;
          default: goto finish;
        };
        if (pruio_pwm_setValue(Io, P_OUT, f0, d0)) { //   set new output
           printf("failed setting PWM output (%s)\n", Io->Errr); break;}

        printf("\n--> Frequency: %10f , Duty: %10f\n", f0, d0); //  info
      }

      if (pruio_cap_Value(Io, P_IN, &f1, &d1)) { //    get current input
          printf("failed reading input @P_IN (%s)\n", Io->Errr); break;}

      printf("\r    Frequency: %10f , Duty: %10f     ", f1, d1); // info
      fflush(STDIN_FILENO);
    }

finish:
    tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); //         reset terminal

    printf("\n");
  } while (0);

  pruio_destroy(Io);       /* destroy driver structure */
	return 0;
}
예제 #4
0
//-------------------------------! The main function.
int main(int argc, char **argv)
{   float_t f1 = 500.0F; 			//      Variable for calculated frequency.
    float_t d1 = 0.9F; 				//      Variable for calculated duty cycle.
    float_t f0 = 500.0F;   			//      The required frequency.
    float_t d0 = .9F;    			//      The required duty cycle.
    float_t MINFREQ = 2.0F;         //
    char buffer[256], *msg = buffer;
    pruIo *Io;
    int charX=0;

    Io = pruio_new(PRUIO_DEF_ACTIVE, 16, 0x98, 0); 		//pruIo* pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD);
    pruio_destroy(Io);       							//destroy driver structure
    Io = pruio_new(PRUIO_DEF_ACTIVE, 16, 0x98, 0); 		//pruIo* pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD);

    //output GpioUdt::setValue PwmMod::setValue
    //input  GpioUdt::config   CapMod::config

    msg= pruio_pwm_setValue(Io, P_FANA, f0, d0);
    if(msg)printf("1%s\n",msg);	//char* pruio_pwm_setValue(pruIo* Io, uint8 Ball, float_t Hz, float_t Du);
    msg= pruio_pwm_setValue(Io, P_FANB, f0, d0);
    if(msg)printf("2%s\n",msg);	//char* pruio_pwm_setValue(pruIo* Io, uint8 Ball, float_t Hz, float_t Du);
    msg= pruio_config(Io, 1, 0x1FE, 1e6, 0);
    if(msg)printf("3%s\n",msg);	//char* pruio_config(pruIo* Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds);
    msg= pruio_cap_config(Io, (uint8)P_IN, MINFREQ);			//NO NON-FLOAT with decimal, get interpreted at double
    if(msg)printf("4%s\n",msg);	//char* pruio_cap_config(pruIo* Io, uint8 Ball, float_t FLow);


// not using ring buffer mode. couldn't get 2 PWM outputs to work with SAMP>1
// So TMR value is ignored
//	msg= pruio_rb_start(Io);						if(msg)printf("5%s\n",msg);	//char* pruio_rb_start(pruIo* Io);

	printf("Samples: %d\n",    Io->Adc->Samples);
	printf("TimerVal: %d ns\n",Io->Adc->TimerVal);
//	printf("Dram[0]= %d\n",Io->DRam[0] );			//most recent write position

    struct termios oldt, newt; //             make terminal non-blocking
    int localerr=0;
    if( 0>tcgetattr( STDIN_FILENO, &oldt ) )
   	{	localerr = errno;
    	printf("tcgetattr failed, error = %d\n",localerr);
   	}
    newt = oldt;
    newt.c_lflag &= ~( ICANON );
    newt.c_cc[VMIN] = 0;
    newt.c_cc[VTIME] = 1;
    tcsetattr( STDIN_FILENO, TCSANOW, &newt );

    int irun=1;
    while(irun)								// Terminate on ESC, else run endless loop
    {	if (1 == isleep(1000)) 				// got a char
    	{	charX = getchar();
    		switch (charX)					// evaluate keystroke
			{ 	case '0' : d0 = 0.0; break;
				case '1' : d0 = 0.1; break;
				case '2' : d0 = 0.2; break;
				case '3' : d0 = 0.3; break;
				case '4' : d0 = 0.4; break;
				case '5' : d0 = 0.5; break;
				case '6' : d0 = 0.6; break;
				case '7' : d0 = 0.7; break;
				case '8' : d0 = 0.8; break;
				case '9' : d0 = 0.9; break;
				case ',' : d0 = 1.0; break;
				case 'm' : f0 = (f0 > 5.5 ? f0 - 5. : .5); break;
				case 'p' : f0 = (f0 < 999995. ? f0 + 5. : 1000000.); break;
				case '*' : f0 = (f0 < 1000000 ? f0 * 2 : 1000000.); break;
				case '/' : f0 = (f0 > .5 ? f0 / 2 : .5); break;
				case '+' : f0 = 1000000; break;
				case '-' : f0 = .5; break;
				default: {irun = 0; break;}				//anything other than above, quit
			};

    		if(irun)
    		{	msg = pruio_pwm_setValue(Io, P_FANA, f0, d0);
				if(msg)
				{	printf("6failed setting PWMA output (%s)\n", Io->Errr); irun=0;
				}else
				{	printf("6\n");
				}
				msg = pruio_pwm_setValue(Io, P_FANB, f0, d0);
				if(msg)
				{	printf("7failed setting PWMB output (%s)\n", Io->Errr); irun=0;
				}else
				{	printf("7\n");
				}
    		}
    	}

    	if(irun)
    	{	  if (pruio_cap_Value(Io, P_IN, &f1, &d1)) 		//    get current input
			  {		printf("8failed reading input @P_IN=%d (%s)\n", P_IN, Io->Errr); break;
			  }
			   printf("Freq %6.1f Duty: %6.1f Freq: %6.1f Duty: %6.1f ADC: %4d %4d %4d\n", f0, d0, f1, d1,Io->Adc->Value[1],Io->Adc->Value[2],Io->Adc->Value[3]); // info
			  fflush(STDIN_FILENO);
    	}
    } //end while


    tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); 		//         reset terminal
    printf("Exiting\n");

    if (pruio_pwm_setValue(Io, P_FANA, f0, 1))	   //   set new output
	{   printf("failed setting PWMA output (%s)\n", Io->Errr);
	}
    if (pruio_pwm_setValue(Io, P_FANB, f0, 1))	   //   set new output
	{   printf("failed setting PWMB output (%s)\n", Io->Errr);
	}

    pruio_destroy(Io);       					//destroy driver structure
	return 0;
}