7Robot_Freescale / Mbed 2 deprecated freescal_cup_k22f

Dependencies:   mbed freescal_cup_k22f

Dependents:   freescal_cup_k22f

Committer:
RobinN7
Date:
Wed Jan 21 10:30:39 2015 +0000
Revision:
25:f9d3d30cbb5d
Parent:
21:9430357e777c
Child:
26:a836e62e0c98
op op op

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
RobinN7 21:9430357e777c 5 DigitalOut clk(PTE1); //clock cameras
RobinN7 21:9430357e777c 6 DigitalOut si(PTE0); // start cameras
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
RobinN7 25:f9d3d30cbb5d 13 extern unsigned int pixel1[128]= {0},pixel1_prec[128]= {0}; //
RobinN7 25:f9d3d30cbb5d 14 extern unsigned int pixel2[128]= {0},pixel2_prec[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 19:5e8260f3bdb2 33 pixel1[index_pixel]=pix1.read_u16();
RobinN7 25:f9d3d30cbb5d 34 pixel2[127 - index_pixel]=pix2.read_u16();
RobinN7 0:3af30bfbc3e5 35 index_pixel ++;
RobinN7 0:3af30bfbc3e5 36 }
RobinN7 0:3af30bfbc3e5 37 wait_us(10);
RobinN7 0:3af30bfbc3e5 38 compteur++;
AlexandreN7 8:8f886cd6a59f 39
RobinN7 0:3af30bfbc3e5 40 if (index_pixel == 128)
AlexandreN7 8:8f886cd6a59f 41 capture_finie = 1;
RobinN7 0:3af30bfbc3e5 42 }
RobinN7 25:f9d3d30cbb5d 43 wait_ms(100);
RobinN7 0:3af30bfbc3e5 44 }
RobinN7 0:3af30bfbc3e5 45
RobinN7 15:b77dc649e4f3 46 void passebas(int ordre)
RobinN7 0:3af30bfbc3e5 47 {
AlexandreN7 10:3424e7b66671 48
AlexandreN7 19:5e8260f3bdb2 49 unsigned int tamponpixel1[256] = {0};
AlexandreN7 19:5e8260f3bdb2 50 unsigned int tamponpixel2[256] = {0};
RobinN7 15:b77dc649e4f3 51 int i=0;
RobinN7 15:b77dc649e4f3 52
RobinN7 2:804797b0b298 53 // Passe bas en partant de la gauche sur tamponpixel[0:127]
RobinN7 15:b77dc649e4f3 54 // et de la droite sur tamponpixel[128:255]
AlexandreN7 8:8f886cd6a59f 55 for (i=ordre; i<128; i++) {
RobinN7 15:b77dc649e4f3 56 for (int a=0; a<=ordre; a++) {
AlexandreN7 19:5e8260f3bdb2 57 tamponpixel1[i]+=pixel1[i-a];
AlexandreN7 19:5e8260f3bdb2 58 tamponpixel1[255-i]+=pixel1[127-i+a];
AlexandreN7 19:5e8260f3bdb2 59 tamponpixel2[i]+=pixel2[i-a];
AlexandreN7 19:5e8260f3bdb2 60 tamponpixel2[255-i]+=pixel2[127-i+a];
AlexandreN7 19:5e8260f3bdb2 61
RobinN7 0:3af30bfbc3e5 62 }
AlexandreN7 19:5e8260f3bdb2 63 tamponpixel1[i]/=(ordre+1);
AlexandreN7 19:5e8260f3bdb2 64 tamponpixel1[255-i]/=(ordre+1);
AlexandreN7 19:5e8260f3bdb2 65 tamponpixel2[i]/=(ordre+1);
AlexandreN7 19:5e8260f3bdb2 66 tamponpixel2[255-i]/=(ordre+1);
RobinN7 0:3af30bfbc3e5 67 }
AlexandreN7 8:8f886cd6a59f 68
RobinN7 15:b77dc649e4f3 69 // Prolongement par continuité à gauche et à droite
RobinN7 15:b77dc649e4f3 70 for (i=0; i<ordre; i++) {
AlexandreN7 19:5e8260f3bdb2 71 tamponpixel1[i]=tamponpixel1[ordre];
AlexandreN7 19:5e8260f3bdb2 72 tamponpixel1[255-i]=tamponpixel1[255-ordre];
AlexandreN7 19:5e8260f3bdb2 73 tamponpixel2[i]=tamponpixel2[ordre];
AlexandreN7 19:5e8260f3bdb2 74 tamponpixel2[255-i]=tamponpixel2[255-ordre];
RobinN7 0:3af30bfbc3e5 75 }
AlexandreN7 8:8f886cd6a59f 76
RobinN7 0:3af30bfbc3e5 77 // Actualisation de l'image filtrée
RobinN7 0:3af30bfbc3e5 78 for (i=0;i<128;i++)
RobinN7 0:3af30bfbc3e5 79 {
AlexandreN7 19:5e8260f3bdb2 80 pixel1[i]=(tamponpixel1[i]+tamponpixel1[127+i])/2;
AlexandreN7 19:5e8260f3bdb2 81 pixel2[i]=(tamponpixel2[i]+tamponpixel2[127+i])/2;
RobinN7 0:3af30bfbc3e5 82 }
AlexandreN7 8:8f886cd6a59f 83 }
AlexandreN7 8:8f886cd6a59f 84
AlexandreN7 8:8f886cd6a59f 85 //fonction qui dérive le signal de la camera
AlexandreN7 8:8f886cd6a59f 86 void derivation()
AlexandreN7 8:8f886cd6a59f 87 {
AlexandreN7 19:5e8260f3bdb2 88 unsigned int tamponpixel1[128] = {0};
AlexandreN7 19:5e8260f3bdb2 89 unsigned int tamponpixel2[128] = {0};
AlexandreN7 8:8f886cd6a59f 90
AlexandreN7 8:8f886cd6a59f 91 for (int i=1; i<128; i++) {
AlexandreN7 19:5e8260f3bdb2 92 tamponpixel1[i]=(pixel1[i]-pixel1[i-1]);
AlexandreN7 19:5e8260f3bdb2 93 tamponpixel2[i]=(pixel2[i]-pixel2[i-1]);
AlexandreN7 8:8f886cd6a59f 94 }
AlexandreN7 19:5e8260f3bdb2 95 tamponpixel1[0]=tamponpixel1[1];
AlexandreN7 19:5e8260f3bdb2 96 tamponpixel2[0]=tamponpixel2[1];
AlexandreN7 8:8f886cd6a59f 97
AlexandreN7 8:8f886cd6a59f 98 // Actualisation de l'image filtrée
AlexandreN7 8:8f886cd6a59f 99 for (int i=0; i<128; i++) {
AlexandreN7 19:5e8260f3bdb2 100 pixel1[i]=tamponpixel1[i];
AlexandreN7 19:5e8260f3bdb2 101 pixel2[i]=tamponpixel2[i];
AlexandreN7 8:8f886cd6a59f 102 }
AlexandreN7 8:8f886cd6a59f 103
RobinN7 25:f9d3d30cbb5d 104 }
RobinN7 25:f9d3d30cbb5d 105 /*
RobinN7 25:f9d3d30cbb5d 106 void moyenne_temporel()
RobinN7 25:f9d3d30cbb5d 107 {
RobinN7 25:f9d3d30cbb5d 108 pixel1_prec[128]= {0}
RobinN7 25:f9d3d30cbb5d 109
RobinN7 25:f9d3d30cbb5d 110
RobinN7 25:f9d3d30cbb5d 111
RobinN7 25:f9d3d30cbb5d 112 }
RobinN7 25:f9d3d30cbb5d 113 */