Beispiel #1
0
int main( void )
{
 initApp();
 initQEI();
 initSM();
 initRS485();
 //int* Z0;
 //Z0=(int*)&TXdata.Z;
 
 
/*        TRISAbits.TRISA4 = 0;     // verbunden mit RB8
        TRISBbits.TRISB4 = 0;     // verbunden mit RB9 
        PORTAbits.RA4 = 1; 
        PORTBbits.RB4 = 1;
*/ 
 
 while(1) 
 {
  readData();
  sendData();
//  blink_led(10);
 
//  GMSstep(-1);
// *Z0=(int)POS2CNT;
 } 
 return 0; 
}  
Beispiel #2
0
int main(void)
{
    //Set clock so it runs directly on the crystal
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    volatile unsigned long ulLoop;

    // Initialisation des ports
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //Enable les GPIO pour les timings des interrupts et autres
    GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_2, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPD);
    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2);

    //Mettre les interrupts du port E en haute prorités: évite collisions avec QEI logiciel
    IntPrioritySet(INT_GPIOE,0);
    //Activer les interruptions
    IntMasterEnable();


    //Initialisation des variables globales
    ulLoop = 0;
    receive_buffer.read=0;
    receive_buffer.write=0;
    send_buffer.read=0;
    send_buffer.write=0;
    send_buffer2.read=0;
    send_buffer2.write=0;
    buffer_commande.read = 0;
    buffer_commande.write = 0;
    //QEI
    position=0;
    speed=0;
    state=0;
    state_m2=0;
    state_m3=0;
    position_m2=0;
    position_m3=0;
    //Asservissement
    previous_error0=0;
    previous_error1=0;
    previous_error2=0;
    previous_error3=0;
    I0=0;
    I1=0;
    I2=0;
    I3=0;
    consigne0=0;
    consigne1=0;
    consigne2=0;
    consigne3=0;
    //Pour les déplacements rapides @6400
    Kd0 = 0.1;
    Ki0 = 7;
    Kp0 = 1.75;
    Kd1 = 0.1;
    Ki1 = 7;
    Kp1 = 1.75;
    Kd2 = 0.1;
    Ki2 = 7;
    Kp2 = 1.75;
    Kd3 = 0.1;
    Ki3 = 7;
    Kp3 = 1.75;
    Tf0 = 0.1;
    Tf1 = 0.1;
    Tf2 = 0.1;
    Tf3 = 0.1;
    //Pour les déplacements moyens @3200
    Kd0_m = 0.05;
    Ki0_m = 10;
    Kp0_m = 1.6;
    Kd1_m = 0.05;
    Ki1_m = 10;
    Kp1_m = 1.5;
    Kd2_m = 0.05;
    Ki2_m = 10;
    Kp2_m = 1.5;
    Kd3_m = 0.05;
    Ki3_m = 10;
    Kp3_m = 1.6;
    //Pour les mouvements lents @1600
    Kd0_s = 0.05;
    Ki0_s = 12;
    Kp0_s = 1.2;
    Kd1_s = 0.05;
    Ki1_s = 12;
    Kp1_s = 1.2;
    Kd2_s = 0.05;
    Ki2_s = 12;
    Kp2_s = 1.2;
    Kd3_s = 0.2;
    Ki3_s = 12;
    Kp3_s = 1.2;
    //Pour les mouvements de dessin @800
    Kd0_d = 0.2;
    Ki0_d = 10;
    Kp0_d = 1.2;
    Kd1_d = 0.05;
    Ki1_d = 10;
    Kp1_d = 1.2;
    Kd2_d = 0.05;
    Ki2_d = 10;
    Kp2_d = 1.2;
    Kd3_d = 0.2;
    Ki3_d = 10;
    Kp3_d = 1.2;
    /*Kd0_s = 0.05;
    Ki0_s = 12;//5.64;
    Kp0_s = 1.2;
    Kd1_s = 0.05;
    Ki1_s = 12;//5.64;
    Kp1_s = 1.2;
    Kd2_s = 0.05;
    Ki2_s = 12;//5.64;
    Kp2_s = 1.2;
    Kd3_s = 0.05;
    Ki3_s = 12;//5.64;
    Kp3_s = 1.2;*/
    dt = 0.1;
    tolerancePos = 0;
    posqei1 = 0;
    speedqei1=0;





    initCommande();
    initMotorCommand();
    initLED();
    initPrehenseur();
    initPWM();
    initUART();
    initQEI();
    //init_lcd();
    initTimer();



    while(1)
    {
        EncoderHandler(); // Traitement des encodeurs en quadrature pour les moteurs 2 et 3

        //si un charactère dans la Receive FIFO
        /*if(!(UART0_FR_R & UART_FR_RXFE)) //&& (send_buffer.read > send_buffer.write-256))
        {
        	receive_buffer.buffer[receive_buffer.write%BUFFER_LEN] = UART0_DR_R;
        	receive_buffer.write++;
        }*/

        /*
        if(!(UART0_FR_R & UART_FR_TXFF) && (send_buffer.read < send_buffer.write))
        {
        	UART0_DR_R = send_buffer.buffer[send_buffer.read%BUFFER_LEN];
        	send_buffer.read++;
        }*/
        /*if(receive_buffer.write - receive_buffer.read > 7){
        	long i;
        	short commande[8];
        	for(i=0; i < 8; i++){
        		commande[i] = receive_buffer.buffer[receive_buffer.read%BUFFER_LEN];
        		receive_buffer.read++;
        	}
        	traiterNouvelleCommande(commande); //Traitement des commandes
        }
        if(buffer_commande.write - buffer_commande.read >= 8){
        	CommandHandler();
        }*/
    }
}