7Robot_Freescale / Mbed 2 deprecated freescal_cup_k22f

Dependencies:   mbed freescal_cup_k22f

Dependents:   freescal_cup_k22f

Committer:
AlexandreN7
Date:
Sat Jan 17 13:25:59 2015 +0000
Revision:
18:278f49df6df3
Parent:
16:88433b5650df
Child:
19:5e8260f3bdb2
interfa?age de la seconde camera en parallele

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobinN7 0:3af30bfbc3e5 1 #include "mbed.h"
RobinN7 0:3af30bfbc3e5 2 #include "Camera.h"
RobinN7 0:3af30bfbc3e5 3
AlexandreN7 18:278f49df6df3 4 // les 2 cameras sont en parallèle
AlexandreN7 18:278f49df6df3 5 DigitalOut clk(PTE1); //clocl camera
AlexandreN7 18:278f49df6df3 6 DigitalOut si(PTE0); // start camera
AlexandreN7 18:278f49df6df3 7
AlexandreN7 18:278f49df6df3 8 AnalogIn pix1(PTB2);//lecture camera1
AlexandreN7 18:278f49df6df3 9 AnalogIn pix2(PTB3);//lecture camera2
RobinN7 0:3af30bfbc3e5 10
RobinN7 0:3af30bfbc3e5 11
AlexandreN7 18:278f49df6df3 12
AlexandreN7 18:278f49df6df3 13 extern unsigned int pixel1[128]= {0}; //
AlexandreN7 18:278f49df6df3 14 extern unsigned int pixel2[128]= {0}; //
RobinN7 0:3af30bfbc3e5 15
AlexandreN7 8:8f886cd6a59f 16 void readline(void) // fonction de détection de la ligne
RobinN7 0:3af30bfbc3e5 17 {
RobinN7 0:3af30bfbc3e5 18 clk=0; // la clock est nulle au départ
RobinN7 0:3af30bfbc3e5 19 int compteur = 0,index_pixel = 0, capture_finie = 0;
AlexandreN7 8:8f886cd6a59f 20
AlexandreN7 8:8f886cd6a59f 21 while (!capture_finie) {
RobinN7 0:3af30bfbc3e5 22 if (compteur & 1) // si compteur impair => front descendant
RobinN7 0:3af30bfbc3e5 23 clk = 0;
RobinN7 0:3af30bfbc3e5 24 else // compteur pair => montant
RobinN7 0:3af30bfbc3e5 25 clk = 1;
RobinN7 0:3af30bfbc3e5 26 if(compteur == 5)
RobinN7 0:3af30bfbc3e5 27 si = 1;
AlexandreN7 8:8f886cd6a59f 28
RobinN7 0:3af30bfbc3e5 29 if (compteur == 7)
AlexandreN7 8:8f886cd6a59f 30 si=0;
AlexandreN7 8:8f886cd6a59f 31 if ( (compteur & 1) && compteur >= 7) { // mesure sur front descendant,
RobinN7 0:3af30bfbc3e5 32 // pc.printf("lecture pixel\n");
AlexandreN7 18:278f49df6df3 33 pixel1[index_pixel]=pix.read_u16();
RobinN7 0:3af30bfbc3e5 34 index_pixel ++;
RobinN7 0:3af30bfbc3e5 35 }
RobinN7 0:3af30bfbc3e5 36 wait_us(10);
RobinN7 0:3af30bfbc3e5 37 compteur++;
AlexandreN7 8:8f886cd6a59f 38
RobinN7 0:3af30bfbc3e5 39 if (index_pixel == 128)
AlexandreN7 8:8f886cd6a59f 40 capture_finie = 1;
RobinN7 0:3af30bfbc3e5 41 }
RobinN7 0:3af30bfbc3e5 42 wait_ms(1);
RobinN7 0:3af30bfbc3e5 43 }
RobinN7 0:3af30bfbc3e5 44
RobinN7 15:b77dc649e4f3 45 void passebas(int ordre)
RobinN7 0:3af30bfbc3e5 46 {
AlexandreN7 10:3424e7b66671 47
AlexandreN7 8:8f886cd6a59f 48 unsigned int tamponpixel[256] = {0};
RobinN7 15:b77dc649e4f3 49 int i=0;
RobinN7 15:b77dc649e4f3 50
RobinN7 2:804797b0b298 51 // Passe bas en partant de la gauche sur tamponpixel[0:127]
RobinN7 15:b77dc649e4f3 52 // et de la droite sur tamponpixel[128:255]
AlexandreN7 8:8f886cd6a59f 53 for (i=ordre; i<128; i++) {
RobinN7 15:b77dc649e4f3 54 for (int a=0; a<=ordre; a++) {
AlexandreN7 18:278f49df6df3 55 tamponpixel[i]+=pixel1[i-a];
AlexandreN7 18:278f49df6df3 56 tamponpixel[255-i]+=pixel1[127-i+a];
RobinN7 0:3af30bfbc3e5 57 }
RobinN7 15:b77dc649e4f3 58 tamponpixel[i]/=(ordre+1);
RobinN7 15:b77dc649e4f3 59 tamponpixel[255-i]/=(ordre+1);
RobinN7 0:3af30bfbc3e5 60 }
AlexandreN7 8:8f886cd6a59f 61
RobinN7 15:b77dc649e4f3 62 // Prolongement par continuité à gauche et à droite
RobinN7 15:b77dc649e4f3 63 for (i=0; i<ordre; i++) {
RobinN7 15:b77dc649e4f3 64 tamponpixel[i]=tamponpixel[ordre];
RobinN7 15:b77dc649e4f3 65 tamponpixel[255-i]=tamponpixel[255-ordre];
RobinN7 0:3af30bfbc3e5 66 }
AlexandreN7 8:8f886cd6a59f 67
RobinN7 0:3af30bfbc3e5 68 // Actualisation de l'image filtrée
RobinN7 0:3af30bfbc3e5 69 for (i=0;i<128;i++)
RobinN7 0:3af30bfbc3e5 70 {
AlexandreN7 18:278f49df6df3 71 pixel1[i]=(tamponpixel[i]+tamponpixel[127+i])/2;
AlexandreN7 10:3424e7b66671 72
RobinN7 0:3af30bfbc3e5 73 }
AlexandreN7 8:8f886cd6a59f 74 }
AlexandreN7 8:8f886cd6a59f 75
AlexandreN7 8:8f886cd6a59f 76 //fonction qui dérive le signal de la camera
AlexandreN7 8:8f886cd6a59f 77 void derivation()
AlexandreN7 8:8f886cd6a59f 78 {
RobinN7 15:b77dc649e4f3 79 unsigned int tamponpixel[128] = {0};
AlexandreN7 8:8f886cd6a59f 80
AlexandreN7 8:8f886cd6a59f 81 for (int i=1; i<128; i++) {
AlexandreN7 18:278f49df6df3 82 tamponpixel[i]=(pixel1[i]-pixel1[i-1]);
AlexandreN7 8:8f886cd6a59f 83 }
RobinN7 15:b77dc649e4f3 84 tamponpixel[0]=tamponpixel[1];
AlexandreN7 8:8f886cd6a59f 85
AlexandreN7 8:8f886cd6a59f 86 // Actualisation de l'image filtrée
AlexandreN7 8:8f886cd6a59f 87 for (int i=0; i<128; i++) {
AlexandreN7 18:278f49df6df3 88 pixel1[i]=tamponpixel[i];
AlexandreN7 8:8f886cd6a59f 89 }
AlexandreN7 8:8f886cd6a59f 90
RobinN7 0:3af30bfbc3e5 91 }