7Robot_Freescale / Mbed 2 deprecated freescal_cup_k22f

Dependencies:   mbed freescal_cup_k22f

Dependents:   freescal_cup_k22f

Committer:
RobinN7
Date:
Wed Jan 14 18:41:06 2015 +0000
Revision:
15:b77dc649e4f3
Parent:
14:000be67805b2
Child:
16:88433b5650df
Am?lioration passe-bas

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobinN7 0:3af30bfbc3e5 1
RobinN7 0:3af30bfbc3e5 2 //Bibliothéque
RobinN7 0:3af30bfbc3e5 3 #include "mbed.h"
RobinN7 0:3af30bfbc3e5 4 #include "QEI.h"
RobinN7 0:3af30bfbc3e5 5 #include "Gestion_Moteur.h"
RobinN7 0:3af30bfbc3e5 6 #include "Camera.h"
RobinN7 0:3af30bfbc3e5 7 #include "Servo.h"
RobinN7 0:3af30bfbc3e5 8
RobinN7 0:3af30bfbc3e5 9 //Differents objet/variable global
RobinN7 0:3af30bfbc3e5 10
AlexandreN7 1:49100fa5e278 11 //test de commit
RobinN7 0:3af30bfbc3e5 12
RobinN7 14:000be67805b2 13 Serial uart(PTD3, PTD2); //xbee
RobinN7 14:000be67805b2 14 //Serial uart(USBTX, USBRX); //port série usb ACM0
RobinN7 0:3af30bfbc3e5 15 Servo servo(PTD0);
AlexandreN7 9:43c8e6d6724d 16 AnalogIn pot1(PTC1);
RobinN7 0:3af30bfbc3e5 17
RobinN7 0:3af30bfbc3e5 18 int main() {
RobinN7 0:3af30bfbc3e5 19 // Initialisation
RobinN7 0:3af30bfbc3e5 20
RobinN7 0:3af30bfbc3e5 21 int indexMin=0;
RobinN7 0:3af30bfbc3e5 22 int indexMax=128;
RobinN7 0:3af30bfbc3e5 23 int max_detect=indexMin;
AlexandreN7 9:43c8e6d6724d 24 float Kp_servo = 0;
RobinN7 0:3af30bfbc3e5 25 uart.baud(115200);
RobinN7 0:3af30bfbc3e5 26 init_led();
RobinN7 0:3af30bfbc3e5 27
RobinN7 0:3af30bfbc3e5 28 // Init UART baudrate
RobinN7 0:3af30bfbc3e5 29
RobinN7 0:3af30bfbc3e5 30
RobinN7 0:3af30bfbc3e5 31 // Lancement boucle
RobinN7 0:3af30bfbc3e5 32 while(1){
RobinN7 0:3af30bfbc3e5 33
RobinN7 0:3af30bfbc3e5 34 readline();
RobinN7 15:b77dc649e4f3 35 passebas(2);
RobinN7 14:000be67805b2 36 //derivation();
RobinN7 15:b77dc649e4f3 37 //passebas(4);
RobinN7 15:b77dc649e4f3 38
AlexandreN7 8:8f886cd6a59f 39 uart.printf("S");//debug START
RobinN7 0:3af30bfbc3e5 40 for (int indice_pixel=0; indice_pixel<128; indice_pixel++)
RobinN7 0:3af30bfbc3e5 41 {
RobinN7 0:3af30bfbc3e5 42 uart.printf("%d,",pixel[indice_pixel]);
RobinN7 0:3af30bfbc3e5 43 }
AlexandreN7 8:8f886cd6a59f 44 uart.printf("E");//debug END
RobinN7 0:3af30bfbc3e5 45
RobinN7 0:3af30bfbc3e5 46 for (int j=indexMin; j<indexMax; j++)
RobinN7 0:3af30bfbc3e5 47 {
RobinN7 0:3af30bfbc3e5 48 if (pixel[j]>pixel[max_detect])
RobinN7 0:3af30bfbc3e5 49 {
RobinN7 0:3af30bfbc3e5 50 max_detect=j;
RobinN7 0:3af30bfbc3e5 51 }
RobinN7 6:a4e49784b533 52 }
RobinN7 14:000be67805b2 53 // Réduction proportionelle de la vitesse moteur si l'angle du servo augmente
RobinN7 6:a4e49784b533 54 if (max_detect>64)
RobinN7 6:a4e49784b533 55 {
RobinN7 15:b77dc649e4f3 56 consigne_moteur_1=6*(1-(max_detect-64)/150.);
RobinN7 15:b77dc649e4f3 57 consigne_moteur_2=6*(1-(max_detect-64)/100.);
RobinN7 0:3af30bfbc3e5 58 }
RobinN7 6:a4e49784b533 59 else
RobinN7 6:a4e49784b533 60 {
RobinN7 15:b77dc649e4f3 61 consigne_moteur_1=7*(1-(64-max_detect)/100.);
RobinN7 15:b77dc649e4f3 62 consigne_moteur_2=7*(1-(64-max_detect)/150.);
RobinN7 6:a4e49784b533 63 }
RobinN7 13:61c50db20069 64 // Lecture du potentiometre
RobinN7 13:61c50db20069 65 Kp_servo=2.0*pot1.read_u16()/65000.0;
RobinN7 13:61c50db20069 66
RobinN7 13:61c50db20069 67 servo = Kp_servo*(double(max_detect)/128.-0.5)+0.5;
RobinN7 0:3af30bfbc3e5 68
AlexandreN7 12:3384196374ca 69
RobinN7 0:3af30bfbc3e5 70 }
RobinN7 0:3af30bfbc3e5 71 }
RobinN7 0:3af30bfbc3e5 72