programme ines avce xbee

Dependencies:   MMA8451Q mbed xbee_lib

Fork of Programme_course by Freescale_Cachan

Committer:
inesmas3
Date:
Wed Feb 08 15:16:04 2017 +0000
Revision:
1:4a9196bcf97a
Parent:
0:3ec7fc598e48
Child:
2:ddf9879f0e25
modif de ines updated au 8 fev 17

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Freescale_cup 0:3ec7fc598e48 1 #include "Mlib.h"
Freescale_cup 0:3ec7fc598e48 2
inesmas3 1:4a9196bcf97a 3 void Gestion_bosse()
inesmas3 1:4a9196bcf97a 4 {
inesmas3 1:4a9196bcf97a 5 if(BOSSE_ACTIVE)//Si on active la détection de la bosse
inesmas3 1:4a9196bcf97a 6 {
inesmas3 1:4a9196bcf97a 7 led5=0;
inesmas3 1:4a9196bcf97a 8 led6=0;
inesmas3 1:4a9196bcf97a 9 led7=0;
inesmas3 1:4a9196bcf97a 10
inesmas3 1:4a9196bcf97a 11 pc.printf("bosse: %d , X: %1.2f , ajustement : %hi\n ",bosse,middle_3F(last_three),ajust_vit_bosse);
inesmas3 1:4a9196bcf97a 12
inesmas3 1:4a9196bcf97a 13
inesmas3 1:4a9196bcf97a 14 last_three[2] = last_three[1]; // les 3 dernieres valeurs de X sont stockées daans un tableau
inesmas3 1:4a9196bcf97a 15 last_three[1] = last_three[0];
inesmas3 1:4a9196bcf97a 16 last_three[0] = acc.getAccX();
inesmas3 1:4a9196bcf97a 17
inesmas3 1:4a9196bcf97a 18 if(bosse == 1)
inesmas3 1:4a9196bcf97a 19 {
inesmas3 1:4a9196bcf97a 20 ajust_vit_bosse = 60;
inesmas3 1:4a9196bcf97a 21 led6=1;
inesmas3 1:4a9196bcf97a 22 led4=1;
inesmas3 1:4a9196bcf97a 23 }
inesmas3 1:4a9196bcf97a 24 else if(bosse == 3)
inesmas3 1:4a9196bcf97a 25 ajust_vit_bosse = -80;
inesmas3 1:4a9196bcf97a 26
inesmas3 1:4a9196bcf97a 27 else
inesmas3 1:4a9196bcf97a 28 {
inesmas3 1:4a9196bcf97a 29 ajust_vit_bosse = 0;
inesmas3 1:4a9196bcf97a 30 led7=1;
inesmas3 1:4a9196bcf97a 31 led1=1;
inesmas3 1:4a9196bcf97a 32 }
inesmas3 1:4a9196bcf97a 33
inesmas3 1:4a9196bcf97a 34 if((abs(middle_3F(last_three)) > 0.13 ) && (bosse == 0)) // si montée détectée
inesmas3 1:4a9196bcf97a 35 {
inesmas3 1:4a9196bcf97a 36 bosse = 1;
inesmas3 1:4a9196bcf97a 37 //tep = (int)t_debut.read_ms();
inesmas3 1:4a9196bcf97a 38 }
inesmas3 1:4a9196bcf97a 39 else if(bosse == 1 && (middle_3F(last_three) > -0.1))
inesmas3 1:4a9196bcf97a 40 {
inesmas3 1:4a9196bcf97a 41 bosse = 2;
inesmas3 1:4a9196bcf97a 42 }
inesmas3 1:4a9196bcf97a 43 else if(bosse == 2 && (middle_3F(last_three) > 0.19))
inesmas3 1:4a9196bcf97a 44 {
inesmas3 1:4a9196bcf97a 45 bosse = 3;
inesmas3 1:4a9196bcf97a 46
inesmas3 1:4a9196bcf97a 47 }
inesmas3 1:4a9196bcf97a 48 else if(bosse==3 && (middle_3F(last_three) > 0.19))
inesmas3 1:4a9196bcf97a 49 {
inesmas3 1:4a9196bcf97a 50 ajust_vit_bosse = -50;
inesmas3 1:4a9196bcf97a 51 led5=1;
inesmas3 1:4a9196bcf97a 52 led2=1;
inesmas3 1:4a9196bcf97a 53 pc.printf("bosse: %d , X: %1.2f , ajustement : %hi\n",bosse,middle_3F(last_three),ajust_vit_bosse);
inesmas3 1:4a9196bcf97a 54 }
inesmas3 1:4a9196bcf97a 55
inesmas3 1:4a9196bcf97a 56 else if (bosse==3 && (middle_3F(last_three) < 0.19))
inesmas3 1:4a9196bcf97a 57 {
inesmas3 1:4a9196bcf97a 58 bosse=0;
inesmas3 1:4a9196bcf97a 59 ajust_vit_bosse=0;
inesmas3 1:4a9196bcf97a 60 }
inesmas3 1:4a9196bcf97a 61 }
inesmas3 1:4a9196bcf97a 62 }
inesmas3 1:4a9196bcf97a 63
Freescale_cup 0:3ec7fc598e48 64 /***********AUTRES_FCT***************/
Freescale_cup 0:3ec7fc598e48 65
inesmas3 1:4a9196bcf97a 66 char middle_3(char *tab) // prend la valeur du milieu quand les valeurs sont rangées
Freescale_cup 0:3ec7fc598e48 67 {
Freescale_cup 0:3ec7fc598e48 68 tri_a_bulle(tab, 3);
Freescale_cup 0:3ec7fc598e48 69 return tab[1];
Freescale_cup 0:3ec7fc598e48 70 }
Freescale_cup 0:3ec7fc598e48 71
Freescale_cup 0:3ec7fc598e48 72 int middle_3U(int *tab)
Freescale_cup 0:3ec7fc598e48 73 {
Freescale_cup 0:3ec7fc598e48 74 tri_a_bulleU(tab, 3);
Freescale_cup 0:3ec7fc598e48 75 return tab[1];
Freescale_cup 0:3ec7fc598e48 76 }
Freescale_cup 0:3ec7fc598e48 77
Freescale_cup 0:3ec7fc598e48 78 float middle_3F(float *tab)
Freescale_cup 0:3ec7fc598e48 79 {
Freescale_cup 0:3ec7fc598e48 80
Freescale_cup 0:3ec7fc598e48 81 return tri_a_bulleF(tab, 3);
Freescale_cup 0:3ec7fc598e48 82 }
Freescale_cup 0:3ec7fc598e48 83
Freescale_cup 0:3ec7fc598e48 84
inesmas3 1:4a9196bcf97a 85 void tri_a_bulle(char* t, int const size) // permet de trier les valeurs du tableau dans l'ordre croissant
Freescale_cup 0:3ec7fc598e48 86 {
Freescale_cup 0:3ec7fc598e48 87 int en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 88 int i,j;
Freescale_cup 0:3ec7fc598e48 89
Freescale_cup 0:3ec7fc598e48 90 for (i = 0; (i < size) && en_desordre; ++i)
Freescale_cup 0:3ec7fc598e48 91 {
Freescale_cup 0:3ec7fc598e48 92 en_desordre = 0;
Freescale_cup 0:3ec7fc598e48 93 for (j = 1; j < (size - i); ++j)
Freescale_cup 0:3ec7fc598e48 94 {
Freescale_cup 0:3ec7fc598e48 95 if (t[j-1] > t[j])
Freescale_cup 0:3ec7fc598e48 96 {
Freescale_cup 0:3ec7fc598e48 97 int temp = t[j-1];
Freescale_cup 0:3ec7fc598e48 98 t[j-1] = t[j];
Freescale_cup 0:3ec7fc598e48 99 t[j] = temp;
Freescale_cup 0:3ec7fc598e48 100 en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 101 }
Freescale_cup 0:3ec7fc598e48 102 }
Freescale_cup 0:3ec7fc598e48 103 }
Freescale_cup 0:3ec7fc598e48 104 }
Freescale_cup 0:3ec7fc598e48 105 void tri_a_bulleU(int* t, int const size)
Freescale_cup 0:3ec7fc598e48 106 {
Freescale_cup 0:3ec7fc598e48 107 int en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 108 int i,j;
Freescale_cup 0:3ec7fc598e48 109
Freescale_cup 0:3ec7fc598e48 110 for (i = 0; (i < size) && en_desordre; ++i)
Freescale_cup 0:3ec7fc598e48 111 {
Freescale_cup 0:3ec7fc598e48 112 en_desordre = 0;
Freescale_cup 0:3ec7fc598e48 113 for (j = 1; j < (size - i); ++j)
Freescale_cup 0:3ec7fc598e48 114 {
Freescale_cup 0:3ec7fc598e48 115 if (t[j-1] > t[j])
Freescale_cup 0:3ec7fc598e48 116 {
Freescale_cup 0:3ec7fc598e48 117 int temp = t[j-1];
Freescale_cup 0:3ec7fc598e48 118 t[j-1] = t[j];
Freescale_cup 0:3ec7fc598e48 119 t[j] = temp;
Freescale_cup 0:3ec7fc598e48 120 en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 121 }
Freescale_cup 0:3ec7fc598e48 122 }
Freescale_cup 0:3ec7fc598e48 123 }
Freescale_cup 0:3ec7fc598e48 124 }
Freescale_cup 0:3ec7fc598e48 125 float tri_a_bulleF(float* t2, int const size)
Freescale_cup 0:3ec7fc598e48 126 {
Freescale_cup 0:3ec7fc598e48 127 float t[3];
Freescale_cup 0:3ec7fc598e48 128 t[0] = t2[0];
Freescale_cup 0:3ec7fc598e48 129 t[1] = t2[1];
Freescale_cup 0:3ec7fc598e48 130 t[2] = t2[2];
Freescale_cup 0:3ec7fc598e48 131
Freescale_cup 0:3ec7fc598e48 132
Freescale_cup 0:3ec7fc598e48 133 int en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 134 int i,j;
Freescale_cup 0:3ec7fc598e48 135
Freescale_cup 0:3ec7fc598e48 136 for (i = 0; (i < size) && en_desordre; ++i)
Freescale_cup 0:3ec7fc598e48 137 {
Freescale_cup 0:3ec7fc598e48 138 en_desordre = 0;
Freescale_cup 0:3ec7fc598e48 139 for (j = 1; j < (size - i); ++j)
Freescale_cup 0:3ec7fc598e48 140 {
Freescale_cup 0:3ec7fc598e48 141 if (t[j-1] > t[j])
Freescale_cup 0:3ec7fc598e48 142 {
Freescale_cup 0:3ec7fc598e48 143 float temp = t[j-1];
Freescale_cup 0:3ec7fc598e48 144 t[j-1] = t[j];
Freescale_cup 0:3ec7fc598e48 145 t[j] = temp;
Freescale_cup 0:3ec7fc598e48 146 en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 147 }
Freescale_cup 0:3ec7fc598e48 148 }
Freescale_cup 0:3ec7fc598e48 149 }
Freescale_cup 0:3ec7fc598e48 150 return t[1];
Freescale_cup 0:3ec7fc598e48 151 }
Freescale_cup 0:3ec7fc598e48 152
Freescale_cup 0:3ec7fc598e48 153 unsigned char Moyenne(unsigned char *tab)
Freescale_cup 0:3ec7fc598e48 154 {
Freescale_cup 0:3ec7fc598e48 155 int i = 0;
Freescale_cup 0:3ec7fc598e48 156 int somme = 0;
Freescale_cup 0:3ec7fc598e48 157 for(i = 0; i < 128;i++)
Freescale_cup 0:3ec7fc598e48 158 {
Freescale_cup 0:3ec7fc598e48 159 somme+=tab[i];
Freescale_cup 0:3ec7fc598e48 160 }
Freescale_cup 0:3ec7fc598e48 161 return somme/128.0;
Freescale_cup 0:3ec7fc598e48 162 }
Freescale_cup 0:3ec7fc598e48 163 char Moyenne2(char *tab, int nb)
Freescale_cup 0:3ec7fc598e48 164 {
Freescale_cup 0:3ec7fc598e48 165 int i = 0;
Freescale_cup 0:3ec7fc598e48 166 int somme = 0;
Freescale_cup 0:3ec7fc598e48 167 for(i = 0; i < nb;i++)
Freescale_cup 0:3ec7fc598e48 168 {
Freescale_cup 0:3ec7fc598e48 169 somme+=tab[i];
Freescale_cup 0:3ec7fc598e48 170 }
Freescale_cup 0:3ec7fc598e48 171 return float(somme/nb);
Freescale_cup 0:3ec7fc598e48 172 }
Freescale_cup 0:3ec7fc598e48 173
Freescale_cup 0:3ec7fc598e48 174 void menu()
Freescale_cup 0:3ec7fc598e48 175 {
Freescale_cup 0:3ec7fc598e48 176 static int p = 0;
Freescale_cup 0:3ec7fc598e48 177 p++;
Freescale_cup 0:3ec7fc598e48 178 wait(0.1);
inesmas3 1:4a9196bcf97a 179 if(BP2) // bouton B
Freescale_cup 0:3ec7fc598e48 180 {
Freescale_cup 0:3ec7fc598e48 181 seuil_der++;
Freescale_cup 0:3ec7fc598e48 182 if(seuil_der == 2) seuil_der = -1;
Freescale_cup 0:3ec7fc598e48 183 led1 = 0;
Freescale_cup 0:3ec7fc598e48 184 wait(0.5);
Freescale_cup 0:3ec7fc598e48 185 }
Freescale_cup 0:3ec7fc598e48 186 if(seuil_der == 0)
Freescale_cup 0:3ec7fc598e48 187 {
Freescale_cup 0:3ec7fc598e48 188 led1 = p%2;
Freescale_cup 0:3ec7fc598e48 189 }
Freescale_cup 0:3ec7fc598e48 190 else if(seuil_der == 1)
Freescale_cup 0:3ec7fc598e48 191 {
Freescale_cup 0:3ec7fc598e48 192 led1 = 1;
Freescale_cup 0:3ec7fc598e48 193 }
Freescale_cup 0:3ec7fc598e48 194 else
Freescale_cup 0:3ec7fc598e48 195 {
Freescale_cup 0:3ec7fc598e48 196 led1 = 0;
Freescale_cup 0:3ec7fc598e48 197 }
Freescale_cup 0:3ec7fc598e48 198 if(S1 == 1)
Freescale_cup 0:3ec7fc598e48 199 {
Freescale_cup 0:3ec7fc598e48 200 led2 = 1;
Freescale_cup 0:3ec7fc598e48 201 }
Freescale_cup 0:3ec7fc598e48 202 else led2 = 0;
Freescale_cup 0:3ec7fc598e48 203 if(S2 == 1)
Freescale_cup 0:3ec7fc598e48 204 {
Freescale_cup 0:3ec7fc598e48 205 led3 = 1;
Freescale_cup 0:3ec7fc598e48 206 }
Freescale_cup 0:3ec7fc598e48 207 else led3= 0;
Freescale_cup 0:3ec7fc598e48 208 }
Freescale_cup 0:3ec7fc598e48 209
Freescale_cup 0:3ec7fc598e48 210 void fin_course()
Freescale_cup 0:3ec7fc598e48 211 {
Freescale_cup 0:3ec7fc598e48 212 static int arr = 0;
Freescale_cup 0:3ec7fc598e48 213 if(somme_derivee >= (Moyenne2(last_five, 5) + (SEUIL_NB_DERRIVEE+5*seuil_der)) || arr != 0)
Freescale_cup 0:3ec7fc598e48 214 {
Freescale_cup 0:3ec7fc598e48 215 if(t_debut.read() > 3 && S1 == 1 && arr == 0)
Freescale_cup 0:3ec7fc598e48 216 {
Freescale_cup 0:3ec7fc598e48 217 arr = t_debut.read_ms();
Freescale_cup 0:3ec7fc598e48 218 }
Freescale_cup 0:3ec7fc598e48 219 else if(arr != 0 && t_debut.read_ms() > arr+100)
Freescale_cup 0:3ec7fc598e48 220 {
Freescale_cup 0:3ec7fc598e48 221 VIT = 0;
Freescale_cup 0:3ec7fc598e48 222 }
Freescale_cup 0:3ec7fc598e48 223 }
Freescale_cup 0:3ec7fc598e48 224 for(int j = 4; j > 0; j--)
Freescale_cup 0:3ec7fc598e48 225 {
Freescale_cup 0:3ec7fc598e48 226 last_five[j] = last_five[j-1];
Freescale_cup 0:3ec7fc598e48 227 // pc.printf("%d\n", last_five[j]);
Freescale_cup 0:3ec7fc598e48 228 }
Freescale_cup 0:3ec7fc598e48 229 // pc.printf("%d | %d\n", (somme_derivee), (Moyenne2(last_five, 5)));
Freescale_cup 0:3ec7fc598e48 230 last_five[0] = somme_derivee;
Freescale_cup 0:3ec7fc598e48 231 }
Freescale_cup 0:3ec7fc598e48 232
Freescale_cup 0:3ec7fc598e48 233
Freescale_cup 0:3ec7fc598e48 234
Freescale_cup 0:3ec7fc598e48 235
Freescale_cup 0:3ec7fc598e48 236
Freescale_cup 0:3ec7fc598e48 237 //void F_BalanceBlancs()
Freescale_cup 0:3ec7fc598e48 238 //{
Freescale_cup 0:3ec7fc598e48 239 // unsigned char moy = 0;
Freescale_cup 0:3ec7fc598e48 240 // moy = Moyenne(cam_data);
Freescale_cup 0:3ec7fc598e48 241 // if(moy > LUMI_MOYENNE && tempsInte >= MIN_INTE) tempsInte-=INCREM_BALANCE;
Freescale_cup 0:3ec7fc598e48 242 // else if(tempsInte <= MAX_INTE) tempsInte+=INCREM_BALANCE;
Freescale_cup 0:3ec7fc598e48 243 //}
Freescale_cup 0:3ec7fc598e48 244
Freescale_cup 0:3ec7fc598e48 245
Freescale_cup 0:3ec7fc598e48 246