7Robot_Freescale / Mbed 2 deprecated freescal_cup_k22f

Dependencies:   mbed freescal_cup_k22f

Dependents:   freescal_cup_k22f

Committer:
AlexandreN7
Date:
Tue Jan 13 16:18:03 2015 +0000
Revision:
8:8f886cd6a59f
Parent:
3:f6a91455109c
Child:
10:3424e7b66671
ajout d'une fonction de d?rivation non test?e

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
RobinN7 0:3af30bfbc3e5 4 DigitalOut clk(PTC2);
RobinN7 0:3af30bfbc3e5 5 DigitalOut si(PTB3);
RobinN7 0:3af30bfbc3e5 6 AnalogIn pix(PTB2);
RobinN7 0:3af30bfbc3e5 7
RobinN7 0:3af30bfbc3e5 8
AlexandreN7 8:8f886cd6a59f 9 extern unsigned int pixel[128]= {0}; //
RobinN7 0:3af30bfbc3e5 10
AlexandreN7 8:8f886cd6a59f 11 void readline(void) // fonction de détection de la ligne
RobinN7 0:3af30bfbc3e5 12 {
RobinN7 0:3af30bfbc3e5 13 clk=0; // la clock est nulle au départ
RobinN7 0:3af30bfbc3e5 14 int compteur = 0,index_pixel = 0, capture_finie = 0;
AlexandreN7 8:8f886cd6a59f 15
AlexandreN7 8:8f886cd6a59f 16 while (!capture_finie) {
RobinN7 0:3af30bfbc3e5 17 if (compteur & 1) // si compteur impair => front descendant
RobinN7 0:3af30bfbc3e5 18 clk = 0;
RobinN7 0:3af30bfbc3e5 19 else // compteur pair => montant
RobinN7 0:3af30bfbc3e5 20 clk = 1;
RobinN7 0:3af30bfbc3e5 21 if(compteur == 5)
RobinN7 0:3af30bfbc3e5 22 si = 1;
AlexandreN7 8:8f886cd6a59f 23
RobinN7 0:3af30bfbc3e5 24 if (compteur == 7)
AlexandreN7 8:8f886cd6a59f 25 si=0;
AlexandreN7 8:8f886cd6a59f 26 if ( (compteur & 1) && compteur >= 7) { // mesure sur front descendant,
RobinN7 0:3af30bfbc3e5 27 // pc.printf("lecture pixel\n");
RobinN7 0:3af30bfbc3e5 28 pixel[index_pixel]=pix.read_u16();
RobinN7 0:3af30bfbc3e5 29 index_pixel ++;
RobinN7 0:3af30bfbc3e5 30 }
RobinN7 0:3af30bfbc3e5 31 wait_us(10);
RobinN7 0:3af30bfbc3e5 32 compteur++;
AlexandreN7 8:8f886cd6a59f 33
RobinN7 0:3af30bfbc3e5 34 if (index_pixel == 128)
AlexandreN7 8:8f886cd6a59f 35 capture_finie = 1;
RobinN7 0:3af30bfbc3e5 36 }
RobinN7 0:3af30bfbc3e5 37 wait_ms(1);
RobinN7 0:3af30bfbc3e5 38 }
RobinN7 0:3af30bfbc3e5 39
RobinN7 0:3af30bfbc3e5 40 void passebas()
RobinN7 0:3af30bfbc3e5 41 {
AlexandreN7 8:8f886cd6a59f 42 unsigned int tamponpixel[256] = {0};
RobinN7 3:f6a91455109c 43 int ordre=7, i=0;
AlexandreN7 8:8f886cd6a59f 44
RobinN7 2:804797b0b298 45 // Passe bas en partant de la gauche sur tamponpixel[0:127]
AlexandreN7 8:8f886cd6a59f 46 for (i=ordre; i<128; i++) {
AlexandreN7 8:8f886cd6a59f 47 for (int a=0; a<ordre; a++) {
RobinN7 0:3af30bfbc3e5 48 tamponpixel[i]+=pixel[i-a];
RobinN7 0:3af30bfbc3e5 49 }
RobinN7 0:3af30bfbc3e5 50 tamponpixel[i]/=ordre;
RobinN7 0:3af30bfbc3e5 51 }
AlexandreN7 8:8f886cd6a59f 52
RobinN7 2:804797b0b298 53 // Passe bas en partant de la droite sur tamponpixel[128:255]
AlexandreN7 8:8f886cd6a59f 54 for (i=127-ordre; i>=0; i--) {
AlexandreN7 8:8f886cd6a59f 55 for (int a=0; a<ordre; a++) {
RobinN7 2:804797b0b298 56 tamponpixel[255-i]+=pixel[i+a];
RobinN7 0:3af30bfbc3e5 57 }
RobinN7 2:804797b0b298 58 tamponpixel[255-i]/=ordre;
RobinN7 0:3af30bfbc3e5 59 }
AlexandreN7 8:8f886cd6a59f 60
AlexandreN7 8:8f886cd6a59f 61
RobinN7 0:3af30bfbc3e5 62 // Actualisation de l'image filtrée
AlexandreN7 8:8f886cd6a59f 63 for (i=0; i<128; i++) {
RobinN7 0:3af30bfbc3e5 64 pixel[i]=tamponpixel[i];
RobinN7 0:3af30bfbc3e5 65 }
AlexandreN7 8:8f886cd6a59f 66 }
AlexandreN7 8:8f886cd6a59f 67
AlexandreN7 8:8f886cd6a59f 68 //fonction qui dérive le signal de la camera
AlexandreN7 8:8f886cd6a59f 69 void derivation()
AlexandreN7 8:8f886cd6a59f 70 {
AlexandreN7 8:8f886cd6a59f 71 unsigned int tamponpixel[256] = {0};
AlexandreN7 8:8f886cd6a59f 72
AlexandreN7 8:8f886cd6a59f 73 for (int i=1; i<128; i++) {
AlexandreN7 8:8f886cd6a59f 74 tamponpixel[i]=pixel[i-1]-pixel[i];
AlexandreN7 8:8f886cd6a59f 75 }
AlexandreN7 8:8f886cd6a59f 76
AlexandreN7 8:8f886cd6a59f 77 // Actualisation de l'image filtrée
AlexandreN7 8:8f886cd6a59f 78 for (int i=0; i<128; i++) {
AlexandreN7 8:8f886cd6a59f 79 pixel[i]=tamponpixel[i];
AlexandreN7 8:8f886cd6a59f 80 }
AlexandreN7 8:8f886cd6a59f 81
RobinN7 0:3af30bfbc3e5 82 }