Projet total V1
Dependencies: mbed
main.cpp@0:eac65d0c5a1c, 2016-06-15 (annotated)
- Committer:
- Paolo804
- Date:
- Wed Jun 15 09:00:08 2016 +0000
- Revision:
- 0:eac65d0c5a1c
Projet total V1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Paolo804 | 0:eac65d0c5a1c | 1 | #include "mbed.h" |
Paolo804 | 0:eac65d0c5a1c | 2 | #include <fonctions_demodulation.h> |
Paolo804 | 0:eac65d0c5a1c | 3 | #include <fonctions_distance.h> |
Paolo804 | 0:eac65d0c5a1c | 4 | |
Paolo804 | 0:eac65d0c5a1c | 5 | |
Paolo804 | 0:eac65d0c5a1c | 6 | AnalogIn adc(A0); |
Paolo804 | 0:eac65d0c5a1c | 7 | |
Paolo804 | 0:eac65d0c5a1c | 8 | int i,j,k; |
Paolo804 | 0:eac65d0c5a1c | 9 | |
Paolo804 | 0:eac65d0c5a1c | 10 | #define NB_VALEURS 280 |
Paolo804 | 0:eac65d0c5a1c | 11 | #define NB_VALEURS_BIT 36 |
Paolo804 | 0:eac65d0c5a1c | 12 | #define NB_VALEURS_MOYENNE_HAUTE 10 |
Paolo804 | 0:eac65d0c5a1c | 13 | |
Paolo804 | 0:eac65d0c5a1c | 14 | float acquisition[NB_VALEURS]; |
Paolo804 | 0:eac65d0c5a1c | 15 | float acquisition_distance[NB_VALEURS]; |
Paolo804 | 0:eac65d0c5a1c | 16 | float seuil; |
Paolo804 | 0:eac65d0c5a1c | 17 | |
Paolo804 | 0:eac65d0c5a1c | 18 | //Déclarations pour la distance |
Paolo804 | 0:eac65d0c5a1c | 19 | |
Paolo804 | 0:eac65d0c5a1c | 20 | |
Paolo804 | 0:eac65d0c5a1c | 21 | struct maximum valeur_max[3]; |
Paolo804 | 0:eac65d0c5a1c | 22 | struct minimum valeur_min[3]; |
Paolo804 | 0:eac65d0c5a1c | 23 | struct distance signal; |
Paolo804 | 0:eac65d0c5a1c | 24 | struct signal_caracteristiques signal_car; |
Paolo804 | 0:eac65d0c5a1c | 25 | //Valeurs 13 Juin : Mesure 1 |
Paolo804 | 0:eac65d0c5a1c | 26 | //struct distance donnee[]={{562,458,260,0.3999}, {559,430,260,0.49},{524,396,223,0.57},{458,367,160,0.6},{413,345,111,0.6},{380,330,82,0.6},{368,324,73,0.59},{354,318,56,0.62},{341,313,45,0.61}}; |
Paolo804 | 0:eac65d0c5a1c | 27 | |
Paolo804 | 0:eac65d0c5a1c | 28 | //Valeurs 14 Juin : Mesure 2 |
Paolo804 | 0:eac65d0c5a1c | 29 | //struct distance donnee[]={{565,454,275,0.4}, {560,418,270,0.53},{433,349,143,0.58},{389,329,98,0.59},{360,317,72,0.61},{338,307,50,0.61},{324,303,34,0.61},{316,300,26.5,0.61},{313,299,13.5,0.61}}; |
Paolo804 | 0:eac65d0c5a1c | 30 | |
Paolo804 | 0:eac65d0c5a1c | 31 | //Valeurs 14 Juin : Mesure 3 (2 47Ohm en parallèle) |
Paolo804 | 0:eac65d0c5a1c | 32 | struct distance donnee[]={{563,497,256,0.25}, {563,460,263,0.39},{562,434,257,0.49},{538,402,234,0.58},{464,368,156,0.6},{425,352,118,0.62},{389,336,85,0.625},{375,329,71,0.64},{360,323,57,0.64}}; |
Paolo804 | 0:eac65d0c5a1c | 33 | |
Paolo804 | 0:eac65d0c5a1c | 34 | |
Paolo804 | 0:eac65d0c5a1c | 35 | int indice; |
Paolo804 | 0:eac65d0c5a1c | 36 | float moyenne; |
Paolo804 | 0:eac65d0c5a1c | 37 | //Fin déclarations pour la distance |
Paolo804 | 0:eac65d0c5a1c | 38 | |
Paolo804 | 0:eac65d0c5a1c | 39 | |
Paolo804 | 0:eac65d0c5a1c | 40 | int main() { |
Paolo804 | 0:eac65d0c5a1c | 41 | char mot; |
Paolo804 | 0:eac65d0c5a1c | 42 | float moyenne; |
Paolo804 | 0:eac65d0c5a1c | 43 | mot=0x00; |
Paolo804 | 0:eac65d0c5a1c | 44 | while(1){ |
Paolo804 | 0:eac65d0c5a1c | 45 | //Aquisition pour seuil_moyen |
Paolo804 | 0:eac65d0c5a1c | 46 | for(i=0; i< NB_VALEURS; i++){ |
Paolo804 | 0:eac65d0c5a1c | 47 | acquisition[i]=adc.read(); |
Paolo804 | 0:eac65d0c5a1c | 48 | } |
Paolo804 | 0:eac65d0c5a1c | 49 | seuil = 0; |
Paolo804 | 0:eac65d0c5a1c | 50 | for(i=0; i< NB_VALEURS; i++){ |
Paolo804 | 0:eac65d0c5a1c | 51 | seuil += acquisition[i]; |
Paolo804 | 0:eac65d0c5a1c | 52 | } |
Paolo804 | 0:eac65d0c5a1c | 53 | seuil /= NB_VALEURS; |
Paolo804 | 0:eac65d0c5a1c | 54 | |
Paolo804 | 0:eac65d0c5a1c | 55 | //Acquisition pour la démodulation |
Paolo804 | 0:eac65d0c5a1c | 56 | while(adc.read() > seuil); |
Paolo804 | 0:eac65d0c5a1c | 57 | while(adc.read() < seuil); |
Paolo804 | 0:eac65d0c5a1c | 58 | for(i=0; i< NB_VALEURS; i++){ |
Paolo804 | 0:eac65d0c5a1c | 59 | acquisition[i]=adc.read(); |
Paolo804 | 0:eac65d0c5a1c | 60 | } |
Paolo804 | 0:eac65d0c5a1c | 61 | //Reajustement du seuil : |
Paolo804 | 0:eac65d0c5a1c | 62 | float max[NB_VALEURS_MOYENNE_HAUTE][2]; |
Paolo804 | 0:eac65d0c5a1c | 63 | //Moyenne des 1 : |
Paolo804 | 0:eac65d0c5a1c | 64 | for(i=0;i<NB_VALEURS_MOYENNE_HAUTE;i++){ |
Paolo804 | 0:eac65d0c5a1c | 65 | max[i][0] = 0; //initialisation des indices |
Paolo804 | 0:eac65d0c5a1c | 66 | max[i][1] = acquisition[0]; //initialisation des max |
Paolo804 | 0:eac65d0c5a1c | 67 | } |
Paolo804 | 0:eac65d0c5a1c | 68 | char already_max=0; |
Paolo804 | 0:eac65d0c5a1c | 69 | for(i=0;i<NB_VALEURS_MOYENNE_HAUTE;i++){ //prise de 10 valeurs max |
Paolo804 | 0:eac65d0c5a1c | 70 | for(j=0;j < NB_VALEURS;j++){ |
Paolo804 | 0:eac65d0c5a1c | 71 | for(k=0;k<i;k++){ |
Paolo804 | 0:eac65d0c5a1c | 72 | if(j == max[k][0]){ |
Paolo804 | 0:eac65d0c5a1c | 73 | already_max = 1; |
Paolo804 | 0:eac65d0c5a1c | 74 | break; |
Paolo804 | 0:eac65d0c5a1c | 75 | } |
Paolo804 | 0:eac65d0c5a1c | 76 | else already_max = 0; |
Paolo804 | 0:eac65d0c5a1c | 77 | } |
Paolo804 | 0:eac65d0c5a1c | 78 | if(acquisition[j] > max[i][1] && !already_max){ |
Paolo804 | 0:eac65d0c5a1c | 79 | max[i][1] = acquisition[j]; |
Paolo804 | 0:eac65d0c5a1c | 80 | max[i][0] = j; |
Paolo804 | 0:eac65d0c5a1c | 81 | } |
Paolo804 | 0:eac65d0c5a1c | 82 | } |
Paolo804 | 0:eac65d0c5a1c | 83 | } |
Paolo804 | 0:eac65d0c5a1c | 84 | float moyenne_haute = 0; |
Paolo804 | 0:eac65d0c5a1c | 85 | for(i=0;i<NB_VALEURS_MOYENNE_HAUTE;i++){ |
Paolo804 | 0:eac65d0c5a1c | 86 | moyenne_haute += max[i][1]; |
Paolo804 | 0:eac65d0c5a1c | 87 | } |
Paolo804 | 0:eac65d0c5a1c | 88 | moyenne_haute /= NB_VALEURS_MOYENNE_HAUTE; |
Paolo804 | 0:eac65d0c5a1c | 89 | |
Paolo804 | 0:eac65d0c5a1c | 90 | //moyenne des 0; |
Paolo804 | 0:eac65d0c5a1c | 91 | |
Paolo804 | 0:eac65d0c5a1c | 92 | for (i=0; i<8; i++){ |
Paolo804 | 0:eac65d0c5a1c | 93 | moyenne = 0; |
Paolo804 | 0:eac65d0c5a1c | 94 | for (j=0;j<NB_VALEURS_BIT;j++){ |
Paolo804 | 0:eac65d0c5a1c | 95 | moyenne += acquisition[i*NB_VALEURS_BIT + j]; |
Paolo804 | 0:eac65d0c5a1c | 96 | } |
Paolo804 | 0:eac65d0c5a1c | 97 | moyenne /= NB_VALEURS_BIT; |
Paolo804 | 0:eac65d0c5a1c | 98 | mot |= (moyenne > seuil)?0x01:0x00; |
Paolo804 | 0:eac65d0c5a1c | 99 | if (i == 7) break; |
Paolo804 | 0:eac65d0c5a1c | 100 | mot = mot << 1; |
Paolo804 | 0:eac65d0c5a1c | 101 | } |
Paolo804 | 0:eac65d0c5a1c | 102 | |
Paolo804 | 0:eac65d0c5a1c | 103 | for (i=0; i<8; i++){ |
Paolo804 | 0:eac65d0c5a1c | 104 | mot = decale_mot(mot); |
Paolo804 | 0:eac65d0c5a1c | 105 | if(mot == 0xAC){ |
Paolo804 | 0:eac65d0c5a1c | 106 | printf("Mot present\n"); |
Paolo804 | 0:eac65d0c5a1c | 107 | break; |
Paolo804 | 0:eac65d0c5a1c | 108 | } |
Paolo804 | 0:eac65d0c5a1c | 109 | } |
Paolo804 | 0:eac65d0c5a1c | 110 | |
Paolo804 | 0:eac65d0c5a1c | 111 | //---------------------- |
Paolo804 | 0:eac65d0c5a1c | 112 | //MESURE DISTANCE |
Paolo804 | 0:eac65d0c5a1c | 113 | //---------------------- |
Paolo804 | 0:eac65d0c5a1c | 114 | for(i=0;i<NB_VALEURS;i++){ |
Paolo804 | 0:eac65d0c5a1c | 115 | acquisition_distance[i] = acquisition[i]*1000; |
Paolo804 | 0:eac65d0c5a1c | 116 | } |
Paolo804 | 0:eac65d0c5a1c | 117 | for(i=0;i<NB_VALEURS;i++){ |
Paolo804 | 0:eac65d0c5a1c | 118 | moyenne += acquisition_distance[i]; |
Paolo804 | 0:eac65d0c5a1c | 119 | } |
Paolo804 | 0:eac65d0c5a1c | 120 | moyenne /= NB_VALEURS; |
Paolo804 | 0:eac65d0c5a1c | 121 | signal.moyenne=moyenne; |
Paolo804 | 0:eac65d0c5a1c | 122 | init_tab_max(valeur_max, acquisition_distance[0]); |
Paolo804 | 0:eac65d0c5a1c | 123 | init_tab_min(valeur_min, acquisition_distance[0]); |
Paolo804 | 0:eac65d0c5a1c | 124 | have_max(acquisition_distance, valeur_max); |
Paolo804 | 0:eac65d0c5a1c | 125 | signal.max = (valeur_max[0].valeur+valeur_max[1].valeur+valeur_max[2].valeur)/3; |
Paolo804 | 0:eac65d0c5a1c | 126 | have_min(acquisition_distance, valeur_min); |
Paolo804 | 0:eac65d0c5a1c | 127 | signal.min=(valeur_min[0].valeur+valeur_min[1].valeur+valeur_min[2].valeur)/3; |
Paolo804 | 0:eac65d0c5a1c | 128 | signal.ecart=signal.max-signal.min; |
Paolo804 | 0:eac65d0c5a1c | 129 | signal.rapport=(signal.max-signal.moyenne)/signal.ecart; |
Paolo804 | 0:eac65d0c5a1c | 130 | printf("signal.max: %f\n", signal.max); |
Paolo804 | 0:eac65d0c5a1c | 131 | printf("signal.min: %f\n", signal.min); |
Paolo804 | 0:eac65d0c5a1c | 132 | printf("signal.moyenne: %f\n", signal.moyenne); |
Paolo804 | 0:eac65d0c5a1c | 133 | printf("signal.ecart: %f\n", signal.ecart); |
Paolo804 | 0:eac65d0c5a1c | 134 | printf("signal.rapport: %f\n", signal.rapport); |
Paolo804 | 0:eac65d0c5a1c | 135 | |
Paolo804 | 0:eac65d0c5a1c | 136 | init_struct(signal_car); |
Paolo804 | 0:eac65d0c5a1c | 137 | verifff(signal, donnee, &signal_car); |
Paolo804 | 0:eac65d0c5a1c | 138 | printf_SC(signal_car); |
Paolo804 | 0:eac65d0c5a1c | 139 | printf("Distance : %f\n", calcul_distance_V2(signal, signal_car)); |
Paolo804 | 0:eac65d0c5a1c | 140 | |
Paolo804 | 0:eac65d0c5a1c | 141 | |
Paolo804 | 0:eac65d0c5a1c | 142 | //---------------------- |
Paolo804 | 0:eac65d0c5a1c | 143 | //FIN MESURE DISTANCE |
Paolo804 | 0:eac65d0c5a1c | 144 | //---------------------- |
Paolo804 | 0:eac65d0c5a1c | 145 | |
Paolo804 | 0:eac65d0c5a1c | 146 | wait(0.5); |
Paolo804 | 0:eac65d0c5a1c | 147 | } |
Paolo804 | 0:eac65d0c5a1c | 148 | } |