Projet total V1
Dependencies: mbed
fonctions_distance.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 <fonctions_distance.h> |
Paolo804 | 0:eac65d0c5a1c | 2 | |
Paolo804 | 0:eac65d0c5a1c | 3 | void init_tab_max(struct maximum tab[3], float acquisition){ |
Paolo804 | 0:eac65d0c5a1c | 4 | int i; |
Paolo804 | 0:eac65d0c5a1c | 5 | for (i=0;i<3;i++){ |
Paolo804 | 0:eac65d0c5a1c | 6 | tab[i].valeur=acquisition; |
Paolo804 | 0:eac65d0c5a1c | 7 | tab[i].indice=0; |
Paolo804 | 0:eac65d0c5a1c | 8 | } |
Paolo804 | 0:eac65d0c5a1c | 9 | } |
Paolo804 | 0:eac65d0c5a1c | 10 | |
Paolo804 | 0:eac65d0c5a1c | 11 | void init_tab_min(struct minimum tab[3], float acquisition){ |
Paolo804 | 0:eac65d0c5a1c | 12 | int i; |
Paolo804 | 0:eac65d0c5a1c | 13 | for(i=0;i<3;i++){ |
Paolo804 | 0:eac65d0c5a1c | 14 | tab[i].valeur=acquisition; |
Paolo804 | 0:eac65d0c5a1c | 15 | tab[i].indice=0; |
Paolo804 | 0:eac65d0c5a1c | 16 | } |
Paolo804 | 0:eac65d0c5a1c | 17 | } |
Paolo804 | 0:eac65d0c5a1c | 18 | |
Paolo804 | 0:eac65d0c5a1c | 19 | bool appartient_max(int i, struct maximum tab_max[3]){ |
Paolo804 | 0:eac65d0c5a1c | 20 | int indice; |
Paolo804 | 0:eac65d0c5a1c | 21 | bool state; |
Paolo804 | 0:eac65d0c5a1c | 22 | state=false; |
Paolo804 | 0:eac65d0c5a1c | 23 | for(indice=0;indice<3;indice++){ |
Paolo804 | 0:eac65d0c5a1c | 24 | if (tab_max[indice].indice == i) state = true; |
Paolo804 | 0:eac65d0c5a1c | 25 | } |
Paolo804 | 0:eac65d0c5a1c | 26 | return state; |
Paolo804 | 0:eac65d0c5a1c | 27 | } |
Paolo804 | 0:eac65d0c5a1c | 28 | |
Paolo804 | 0:eac65d0c5a1c | 29 | |
Paolo804 | 0:eac65d0c5a1c | 30 | bool appartient_min(int i, struct minimum tab_min[3]){ |
Paolo804 | 0:eac65d0c5a1c | 31 | int indice; |
Paolo804 | 0:eac65d0c5a1c | 32 | bool state; |
Paolo804 | 0:eac65d0c5a1c | 33 | state=false; |
Paolo804 | 0:eac65d0c5a1c | 34 | for(indice=0;indice<3;indice++){ |
Paolo804 | 0:eac65d0c5a1c | 35 | if (tab_min[indice].indice == i) state = true; |
Paolo804 | 0:eac65d0c5a1c | 36 | } |
Paolo804 | 0:eac65d0c5a1c | 37 | return state; |
Paolo804 | 0:eac65d0c5a1c | 38 | } |
Paolo804 | 0:eac65d0c5a1c | 39 | |
Paolo804 | 0:eac65d0c5a1c | 40 | void have_max(float tab[NB_VALEURS], struct maximum tab_max[3]){ |
Paolo804 | 0:eac65d0c5a1c | 41 | int i,j; |
Paolo804 | 0:eac65d0c5a1c | 42 | for(j=0;j<3;j++){ |
Paolo804 | 0:eac65d0c5a1c | 43 | for(i=0;i<NB_VALEURS;i++){ |
Paolo804 | 0:eac65d0c5a1c | 44 | if (tab_max[j].valeur < tab[i] && appartient_max(i, tab_max) != true){ //La valeur du tableau est supérieure et aucune autre case du tabelau de structure ne contient cette valeur; |
Paolo804 | 0:eac65d0c5a1c | 45 | tab_max[j].valeur=tab[i]; |
Paolo804 | 0:eac65d0c5a1c | 46 | tab_max[j].indice=i; |
Paolo804 | 0:eac65d0c5a1c | 47 | } |
Paolo804 | 0:eac65d0c5a1c | 48 | } |
Paolo804 | 0:eac65d0c5a1c | 49 | } |
Paolo804 | 0:eac65d0c5a1c | 50 | } |
Paolo804 | 0:eac65d0c5a1c | 51 | |
Paolo804 | 0:eac65d0c5a1c | 52 | void have_min(float tab[NB_VALEURS], struct minimum tab_min[3]){ // A modifier avec la rejection de valeur; |
Paolo804 | 0:eac65d0c5a1c | 53 | int i,j; |
Paolo804 | 0:eac65d0c5a1c | 54 | for(j=0;j<3;j++){ |
Paolo804 | 0:eac65d0c5a1c | 55 | for(i=0;i<NB_VALEURS;i++){ |
Paolo804 | 0:eac65d0c5a1c | 56 | if (tab_min[j].valeur > tab[i] && appartient_min(i, tab_min) != true){ |
Paolo804 | 0:eac65d0c5a1c | 57 | tab_min[j].valeur=tab[i]; |
Paolo804 | 0:eac65d0c5a1c | 58 | tab_min[j].indice=i; |
Paolo804 | 0:eac65d0c5a1c | 59 | } |
Paolo804 | 0:eac65d0c5a1c | 60 | } |
Paolo804 | 0:eac65d0c5a1c | 61 | } |
Paolo804 | 0:eac65d0c5a1c | 62 | } |
Paolo804 | 0:eac65d0c5a1c | 63 | |
Paolo804 | 0:eac65d0c5a1c | 64 | //ALGO DETECTION DISTANCE |
Paolo804 | 0:eac65d0c5a1c | 65 | float abs_minus(float a, float b){ |
Paolo804 | 0:eac65d0c5a1c | 66 | float retour; |
Paolo804 | 0:eac65d0c5a1c | 67 | if ((a-b)>=0) retour = a-b; |
Paolo804 | 0:eac65d0c5a1c | 68 | else retour = b-a; |
Paolo804 | 0:eac65d0c5a1c | 69 | return retour; |
Paolo804 | 0:eac65d0c5a1c | 70 | } |
Paolo804 | 0:eac65d0c5a1c | 71 | |
Paolo804 | 0:eac65d0c5a1c | 72 | void init_struct(struct signal_caracteristiques tableau){ |
Paolo804 | 0:eac65d0c5a1c | 73 | tableau.indice_max=0; |
Paolo804 | 0:eac65d0c5a1c | 74 | tableau.indice_moyenne=0; |
Paolo804 | 0:eac65d0c5a1c | 75 | tableau.indice_ecart=0; |
Paolo804 | 0:eac65d0c5a1c | 76 | tableau.indice_rapport=0; |
Paolo804 | 0:eac65d0c5a1c | 77 | } |
Paolo804 | 0:eac65d0c5a1c | 78 | |
Paolo804 | 0:eac65d0c5a1c | 79 | void verifff(struct distance signal, struct distance donnee[], struct signal_caracteristiques *signal_carac){ |
Paolo804 | 0:eac65d0c5a1c | 80 | int i; |
Paolo804 | 0:eac65d0c5a1c | 81 | init_struct(*signal_carac); |
Paolo804 | 0:eac65d0c5a1c | 82 | for(i=1;i<9;i++){ |
Paolo804 | 0:eac65d0c5a1c | 83 | if (abs_minus(signal.max, donnee[signal_carac->indice_max].max) > abs_minus(signal.max, donnee[i].max))signal_carac->indice_max=i; |
Paolo804 | 0:eac65d0c5a1c | 84 | if (abs_minus(signal.moyenne, donnee[signal_carac->indice_moyenne].moyenne) > abs_minus(signal.moyenne, donnee[i].moyenne))signal_carac->indice_moyenne=i; |
Paolo804 | 0:eac65d0c5a1c | 85 | if (abs_minus(signal.ecart, donnee[signal_carac->indice_ecart].ecart) > abs_minus(signal.ecart, donnee[i].ecart))signal_carac->indice_ecart=i; |
Paolo804 | 0:eac65d0c5a1c | 86 | if (abs_minus(signal.rapport, donnee[signal_carac->indice_rapport].rapport) > abs_minus(signal.rapport, donnee[i].rapport))signal_carac->indice_rapport=i; |
Paolo804 | 0:eac65d0c5a1c | 87 | } |
Paolo804 | 0:eac65d0c5a1c | 88 | } |
Paolo804 | 0:eac65d0c5a1c | 89 | |
Paolo804 | 0:eac65d0c5a1c | 90 | void printf_SC(struct signal_caracteristiques sig){ |
Paolo804 | 0:eac65d0c5a1c | 91 | printf("indice_max: %d\n", sig.indice_max); |
Paolo804 | 0:eac65d0c5a1c | 92 | printf("indice_moyenne: %d\n", sig.indice_moyenne); |
Paolo804 | 0:eac65d0c5a1c | 93 | printf("indice_ecart: %d\n", sig.indice_ecart); |
Paolo804 | 0:eac65d0c5a1c | 94 | printf("indice_rapport: %d\n", sig.indice_rapport); |
Paolo804 | 0:eac65d0c5a1c | 95 | } |
Paolo804 | 0:eac65d0c5a1c | 96 | |
Paolo804 | 0:eac65d0c5a1c | 97 | int calcul_distance_V1(struct distance signal, struct distance donnee[], struct signal_caracteristiques caracteristiques){ |
Paolo804 | 0:eac65d0c5a1c | 98 | int distance; |
Paolo804 | 0:eac65d0c5a1c | 99 | if (caracteristiques.indice_rapport < 3){ |
Paolo804 | 0:eac65d0c5a1c | 100 | if (abs_minus(signal.rapport, donnee[0].rapport) <= abs_minus(signal.rapport, donnee[1].rapport)) distance = 20; |
Paolo804 | 0:eac65d0c5a1c | 101 | else { |
Paolo804 | 0:eac65d0c5a1c | 102 | if (abs_minus(signal.rapport, donnee[1].rapport) < abs_minus(signal.rapport, donnee[2].rapport)) distance = 30; |
Paolo804 | 0:eac65d0c5a1c | 103 | else distance = 40; |
Paolo804 | 0:eac65d0c5a1c | 104 | } |
Paolo804 | 0:eac65d0c5a1c | 105 | } |
Paolo804 | 0:eac65d0c5a1c | 106 | else{ |
Paolo804 | 0:eac65d0c5a1c | 107 | if (abs_minus(signal.ecart, donnee[3].ecart) < abs_minus(signal.ecart, donnee[4].ecart)) distance = 50; |
Paolo804 | 0:eac65d0c5a1c | 108 | else { |
Paolo804 | 0:eac65d0c5a1c | 109 | if (signal.ecart < donnee[8].ecart) distance = 100; |
Paolo804 | 0:eac65d0c5a1c | 110 | else if (signal.ecart < donnee[7].ecart) distance = 90; |
Paolo804 | 0:eac65d0c5a1c | 111 | else if (signal.ecart < donnee[6].ecart) distance = 80; |
Paolo804 | 0:eac65d0c5a1c | 112 | else if (signal.ecart < donnee[5].ecart) distance = 70; |
Paolo804 | 0:eac65d0c5a1c | 113 | else distance = 60; |
Paolo804 | 0:eac65d0c5a1c | 114 | } |
Paolo804 | 0:eac65d0c5a1c | 115 | } |
Paolo804 | 0:eac65d0c5a1c | 116 | return distance; |
Paolo804 | 0:eac65d0c5a1c | 117 | } |
Paolo804 | 0:eac65d0c5a1c | 118 | |
Paolo804 | 0:eac65d0c5a1c | 119 | float convert_indice(int indice){ |
Paolo804 | 0:eac65d0c5a1c | 120 | return indice*10+20; |
Paolo804 | 0:eac65d0c5a1c | 121 | } |
Paolo804 | 0:eac65d0c5a1c | 122 | |
Paolo804 | 0:eac65d0c5a1c | 123 | float calcul_distance_V2(struct distance signal, struct signal_caracteristiques caracteristiques){ |
Paolo804 | 0:eac65d0c5a1c | 124 | float distance; |
Paolo804 | 0:eac65d0c5a1c | 125 | if(convert_indice(caracteristiques.indice_rapport) <= 40) |
Paolo804 | 0:eac65d0c5a1c | 126 | distance = convert_indice(caracteristiques.indice_rapport); |
Paolo804 | 0:eac65d0c5a1c | 127 | else if(convert_indice(caracteristiques.indice_ecart) == 100) |
Paolo804 | 0:eac65d0c5a1c | 128 | distance = 100; |
Paolo804 | 0:eac65d0c5a1c | 129 | else |
Paolo804 | 0:eac65d0c5a1c | 130 | distance = 0.5*convert_indice(caracteristiques.indice_rapport) + 0.5*convert_indice(caracteristiques.indice_ecart); |
Paolo804 | 0:eac65d0c5a1c | 131 | return distance; |
Paolo804 | 0:eac65d0c5a1c | 132 | |
Paolo804 | 0:eac65d0c5a1c | 133 | } |
Paolo804 | 0:eac65d0c5a1c | 134 | //FIN ALGO DETECTION DISTANCE |