7Robot_Freescale / Mbed 2 deprecated freescal_cup_k22f

Dependencies:   mbed freescal_cup_k22f

Dependents:   freescal_cup_k22f

source/main.cpp

Committer:
RobinN7
Date:
2015-01-17
Revision:
17:31e000d82b21
Parent:
16:88433b5650df
Child:
20:24ebe046ebe9

File content as of revision 17:31e000d82b21:


//Bibliothéque
#include "mbed.h"
#include "QEI.h"
#include "Gestion_Moteur.h"
#include "Camera.h"
#include "Servo.h"

//Differents objet/variable global

//test de commit

Serial uart(PTD3, PTD2); //xbee
//Serial uart(USBTX, USBRX); //port série usb ACM0
Servo servo(PTD0);
AnalogIn pot1(PTC1);

int main() {
 // Initialisation
 
    int indexMin=0;   
    int indexMax=128;  
    int max_detect=indexMin;
    float Kp_servo = 0;
    uart.baud(115200); 
    init_led();
   
    // Init UART baudrate

         
    // Lancement boucle
    while(1){
        
        readline();
        passebas(12);
        derivation();
        //passebas(4); 
           
        uart.printf("S");//debug START
        for (int indice_pixel=0; indice_pixel<128; indice_pixel++)   
        {
            uart.printf("%d,",pixel[indice_pixel]);
        }
        uart.printf("E");//debug END
        
        for (int j=indexMin; j<indexMax; j++)
        {
            if (pixel[j]>pixel[max_detect])
            {
                max_detect=j;
            }
        }    
        // Réduction proportionelle de la vitesse moteur si l'angle du servo augmente
        if (max_detect>64)
        {
            consigne_moteur_1=6*(1-(max_detect-64)/150.);
            consigne_moteur_2=6*(1-(max_detect-64)/100.);
        }
        else
        {
            consigne_moteur_1=7*(1-(64-max_detect)/100.);
            consigne_moteur_2=7*(1-(64-max_detect)/150.); 
        }
        // Lecture du potentiometre
        Kp_servo=2.0*pot1.read_u16()/65000.0;
        
        servo = Kp_servo*(double(max_detect)/128.-0.5)+0.5;


    }
}