Programme course fonctionnel Jour J Croisement non pris en charge (tourne en rond)
Fork of Programme_course_30Tr by
Mlib.cpp@2:a37de5eb8bf3, 2017-03-17 (annotated)
- Committer:
- leandre
- Date:
- Fri Mar 17 14:18:04 2017 +0000
- Revision:
- 2:a37de5eb8bf3
- Parent:
- 0:3ec7fc598e48
- Child:
- 3:c0aae5aa230b
programme avec gestion des virage plus fluide
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Freescale_cup | 0:3ec7fc598e48 | 1 | #include "Mlib.h" |
Freescale_cup | 0:3ec7fc598e48 | 2 | |
Freescale_cup | 0:3ec7fc598e48 | 3 | /***********AUTRES_FCT***************/ |
Freescale_cup | 0:3ec7fc598e48 | 4 | |
Freescale_cup | 0:3ec7fc598e48 | 5 | char middle_3(char *tab) |
Freescale_cup | 0:3ec7fc598e48 | 6 | { |
Freescale_cup | 0:3ec7fc598e48 | 7 | tri_a_bulle(tab, 3); |
Freescale_cup | 0:3ec7fc598e48 | 8 | return tab[1]; |
Freescale_cup | 0:3ec7fc598e48 | 9 | } |
Freescale_cup | 0:3ec7fc598e48 | 10 | |
Freescale_cup | 0:3ec7fc598e48 | 11 | int middle_3U(int *tab) |
Freescale_cup | 0:3ec7fc598e48 | 12 | { |
Freescale_cup | 0:3ec7fc598e48 | 13 | tri_a_bulleU(tab, 3); |
Freescale_cup | 0:3ec7fc598e48 | 14 | return tab[1]; |
Freescale_cup | 0:3ec7fc598e48 | 15 | } |
Freescale_cup | 0:3ec7fc598e48 | 16 | |
Freescale_cup | 0:3ec7fc598e48 | 17 | float middle_3F(float *tab) |
Freescale_cup | 0:3ec7fc598e48 | 18 | { |
Freescale_cup | 0:3ec7fc598e48 | 19 | |
Freescale_cup | 0:3ec7fc598e48 | 20 | return tri_a_bulleF(tab, 3); |
Freescale_cup | 0:3ec7fc598e48 | 21 | } |
Freescale_cup | 0:3ec7fc598e48 | 22 | |
Freescale_cup | 0:3ec7fc598e48 | 23 | |
Freescale_cup | 0:3ec7fc598e48 | 24 | void tri_a_bulle(char* t, int const size) |
Freescale_cup | 0:3ec7fc598e48 | 25 | { |
Freescale_cup | 0:3ec7fc598e48 | 26 | int en_desordre = 1; |
Freescale_cup | 0:3ec7fc598e48 | 27 | int i,j; |
Freescale_cup | 0:3ec7fc598e48 | 28 | |
Freescale_cup | 0:3ec7fc598e48 | 29 | for (i = 0; (i < size) && en_desordre; ++i) |
Freescale_cup | 0:3ec7fc598e48 | 30 | { |
Freescale_cup | 0:3ec7fc598e48 | 31 | en_desordre = 0; |
Freescale_cup | 0:3ec7fc598e48 | 32 | for (j = 1; j < (size - i); ++j) |
Freescale_cup | 0:3ec7fc598e48 | 33 | { |
Freescale_cup | 0:3ec7fc598e48 | 34 | if (t[j-1] > t[j]) |
Freescale_cup | 0:3ec7fc598e48 | 35 | { |
Freescale_cup | 0:3ec7fc598e48 | 36 | int temp = t[j-1]; |
Freescale_cup | 0:3ec7fc598e48 | 37 | t[j-1] = t[j]; |
Freescale_cup | 0:3ec7fc598e48 | 38 | t[j] = temp; |
Freescale_cup | 0:3ec7fc598e48 | 39 | en_desordre = 1; |
Freescale_cup | 0:3ec7fc598e48 | 40 | } |
Freescale_cup | 0:3ec7fc598e48 | 41 | } |
Freescale_cup | 0:3ec7fc598e48 | 42 | } |
Freescale_cup | 0:3ec7fc598e48 | 43 | } |
Freescale_cup | 0:3ec7fc598e48 | 44 | void tri_a_bulleU(int* t, int const size) |
Freescale_cup | 0:3ec7fc598e48 | 45 | { |
Freescale_cup | 0:3ec7fc598e48 | 46 | int en_desordre = 1; |
Freescale_cup | 0:3ec7fc598e48 | 47 | int i,j; |
Freescale_cup | 0:3ec7fc598e48 | 48 | |
Freescale_cup | 0:3ec7fc598e48 | 49 | for (i = 0; (i < size) && en_desordre; ++i) |
Freescale_cup | 0:3ec7fc598e48 | 50 | { |
Freescale_cup | 0:3ec7fc598e48 | 51 | en_desordre = 0; |
Freescale_cup | 0:3ec7fc598e48 | 52 | for (j = 1; j < (size - i); ++j) |
Freescale_cup | 0:3ec7fc598e48 | 53 | { |
Freescale_cup | 0:3ec7fc598e48 | 54 | if (t[j-1] > t[j]) |
Freescale_cup | 0:3ec7fc598e48 | 55 | { |
Freescale_cup | 0:3ec7fc598e48 | 56 | int temp = t[j-1]; |
Freescale_cup | 0:3ec7fc598e48 | 57 | t[j-1] = t[j]; |
Freescale_cup | 0:3ec7fc598e48 | 58 | t[j] = temp; |
Freescale_cup | 0:3ec7fc598e48 | 59 | en_desordre = 1; |
Freescale_cup | 0:3ec7fc598e48 | 60 | } |
Freescale_cup | 0:3ec7fc598e48 | 61 | } |
Freescale_cup | 0:3ec7fc598e48 | 62 | } |
Freescale_cup | 0:3ec7fc598e48 | 63 | } |
Freescale_cup | 0:3ec7fc598e48 | 64 | float tri_a_bulleF(float* t2, int const size) |
Freescale_cup | 0:3ec7fc598e48 | 65 | { |
Freescale_cup | 0:3ec7fc598e48 | 66 | float t[3]; |
Freescale_cup | 0:3ec7fc598e48 | 67 | t[0] = t2[0]; |
Freescale_cup | 0:3ec7fc598e48 | 68 | t[1] = t2[1]; |
Freescale_cup | 0:3ec7fc598e48 | 69 | t[2] = t2[2]; |
Freescale_cup | 0:3ec7fc598e48 | 70 | |
Freescale_cup | 0:3ec7fc598e48 | 71 | |
Freescale_cup | 0:3ec7fc598e48 | 72 | int en_desordre = 1; |
Freescale_cup | 0:3ec7fc598e48 | 73 | int i,j; |
Freescale_cup | 0:3ec7fc598e48 | 74 | |
Freescale_cup | 0:3ec7fc598e48 | 75 | for (i = 0; (i < size) && en_desordre; ++i) |
Freescale_cup | 0:3ec7fc598e48 | 76 | { |
Freescale_cup | 0:3ec7fc598e48 | 77 | en_desordre = 0; |
Freescale_cup | 0:3ec7fc598e48 | 78 | for (j = 1; j < (size - i); ++j) |
Freescale_cup | 0:3ec7fc598e48 | 79 | { |
Freescale_cup | 0:3ec7fc598e48 | 80 | if (t[j-1] > t[j]) |
Freescale_cup | 0:3ec7fc598e48 | 81 | { |
Freescale_cup | 0:3ec7fc598e48 | 82 | float temp = t[j-1]; |
Freescale_cup | 0:3ec7fc598e48 | 83 | t[j-1] = t[j]; |
Freescale_cup | 0:3ec7fc598e48 | 84 | t[j] = temp; |
Freescale_cup | 0:3ec7fc598e48 | 85 | en_desordre = 1; |
Freescale_cup | 0:3ec7fc598e48 | 86 | } |
Freescale_cup | 0:3ec7fc598e48 | 87 | } |
Freescale_cup | 0:3ec7fc598e48 | 88 | } |
Freescale_cup | 0:3ec7fc598e48 | 89 | return t[1]; |
Freescale_cup | 0:3ec7fc598e48 | 90 | } |
Freescale_cup | 0:3ec7fc598e48 | 91 | |
Freescale_cup | 0:3ec7fc598e48 | 92 | unsigned char Moyenne(unsigned char *tab) |
Freescale_cup | 0:3ec7fc598e48 | 93 | { |
Freescale_cup | 0:3ec7fc598e48 | 94 | int i = 0; |
Freescale_cup | 0:3ec7fc598e48 | 95 | int somme = 0; |
Freescale_cup | 0:3ec7fc598e48 | 96 | for(i = 0; i < 128;i++) |
Freescale_cup | 0:3ec7fc598e48 | 97 | { |
Freescale_cup | 0:3ec7fc598e48 | 98 | somme+=tab[i]; |
Freescale_cup | 0:3ec7fc598e48 | 99 | } |
Freescale_cup | 0:3ec7fc598e48 | 100 | return somme/128.0; |
Freescale_cup | 0:3ec7fc598e48 | 101 | } |
Freescale_cup | 0:3ec7fc598e48 | 102 | char Moyenne2(char *tab, int nb) |
Freescale_cup | 0:3ec7fc598e48 | 103 | { |
Freescale_cup | 0:3ec7fc598e48 | 104 | int i = 0; |
Freescale_cup | 0:3ec7fc598e48 | 105 | int somme = 0; |
Freescale_cup | 0:3ec7fc598e48 | 106 | for(i = 0; i < nb;i++) |
Freescale_cup | 0:3ec7fc598e48 | 107 | { |
Freescale_cup | 0:3ec7fc598e48 | 108 | somme+=tab[i]; |
Freescale_cup | 0:3ec7fc598e48 | 109 | } |
Freescale_cup | 0:3ec7fc598e48 | 110 | return float(somme/nb); |
Freescale_cup | 0:3ec7fc598e48 | 111 | } |
Freescale_cup | 0:3ec7fc598e48 | 112 | |
Freescale_cup | 0:3ec7fc598e48 | 113 | void menu() |
Freescale_cup | 0:3ec7fc598e48 | 114 | { |
Freescale_cup | 0:3ec7fc598e48 | 115 | static int p = 0; |
Freescale_cup | 0:3ec7fc598e48 | 116 | p++; |
Freescale_cup | 0:3ec7fc598e48 | 117 | wait(0.1); |
Freescale_cup | 0:3ec7fc598e48 | 118 | if(BP2) |
Freescale_cup | 0:3ec7fc598e48 | 119 | { |
Freescale_cup | 0:3ec7fc598e48 | 120 | seuil_der++; |
Freescale_cup | 0:3ec7fc598e48 | 121 | if(seuil_der == 2) seuil_der = -1; |
Freescale_cup | 0:3ec7fc598e48 | 122 | led1 = 0; |
Freescale_cup | 0:3ec7fc598e48 | 123 | wait(0.5); |
Freescale_cup | 0:3ec7fc598e48 | 124 | } |
Freescale_cup | 0:3ec7fc598e48 | 125 | if(seuil_der == 0) |
Freescale_cup | 0:3ec7fc598e48 | 126 | { |
Freescale_cup | 0:3ec7fc598e48 | 127 | led1 = p%2; |
Freescale_cup | 0:3ec7fc598e48 | 128 | } |
Freescale_cup | 0:3ec7fc598e48 | 129 | else if(seuil_der == 1) |
Freescale_cup | 0:3ec7fc598e48 | 130 | { |
Freescale_cup | 0:3ec7fc598e48 | 131 | led1 = 1; |
Freescale_cup | 0:3ec7fc598e48 | 132 | } |
Freescale_cup | 0:3ec7fc598e48 | 133 | else |
Freescale_cup | 0:3ec7fc598e48 | 134 | { |
Freescale_cup | 0:3ec7fc598e48 | 135 | led1 = 0; |
Freescale_cup | 0:3ec7fc598e48 | 136 | } |
Freescale_cup | 0:3ec7fc598e48 | 137 | if(S1 == 1) |
Freescale_cup | 0:3ec7fc598e48 | 138 | { |
Freescale_cup | 0:3ec7fc598e48 | 139 | led2 = 1; |
Freescale_cup | 0:3ec7fc598e48 | 140 | } |
Freescale_cup | 0:3ec7fc598e48 | 141 | else led2 = 0; |
Freescale_cup | 0:3ec7fc598e48 | 142 | if(S2 == 1) |
Freescale_cup | 0:3ec7fc598e48 | 143 | { |
Freescale_cup | 0:3ec7fc598e48 | 144 | led3 = 1; |
Freescale_cup | 0:3ec7fc598e48 | 145 | } |
Freescale_cup | 0:3ec7fc598e48 | 146 | else led3= 0; |
Freescale_cup | 0:3ec7fc598e48 | 147 | } |
Freescale_cup | 0:3ec7fc598e48 | 148 | |
Freescale_cup | 0:3ec7fc598e48 | 149 | void fin_course() |
Freescale_cup | 0:3ec7fc598e48 | 150 | { |
Freescale_cup | 0:3ec7fc598e48 | 151 | static int arr = 0; |
leandre | 2:a37de5eb8bf3 | 152 | static char moy_inter; |
leandre | 2:a37de5eb8bf3 | 153 | |
leandre | 2:a37de5eb8bf3 | 154 | /*if((somme_derivee >= (Moyenne2(last_five, 5) + (SEUIL_NB_DERRIVEE+seuil_der))) || arr != 0) |
Freescale_cup | 0:3ec7fc598e48 | 155 | { |
leandre | 2:a37de5eb8bf3 | 156 | if(t_debut.read_ms() > 500 && S1 == 1 && arr == 0) |
Freescale_cup | 0:3ec7fc598e48 | 157 | { |
leandre | 2:a37de5eb8bf3 | 158 | arr = t_debut.read_ms(); |
Freescale_cup | 0:3ec7fc598e48 | 159 | } |
Freescale_cup | 0:3ec7fc598e48 | 160 | else if(arr != 0 && t_debut.read_ms() > arr+100) |
Freescale_cup | 0:3ec7fc598e48 | 161 | { |
Freescale_cup | 0:3ec7fc598e48 | 162 | VIT = 0; |
leandre | 2:a37de5eb8bf3 | 163 | pc.printf("arret\ndelai:%d ms\n",(t_debut.read_ms()-arr)); |
Freescale_cup | 0:3ec7fc598e48 | 164 | } |
leandre | 2:a37de5eb8bf3 | 165 | |
leandre | 2:a37de5eb8bf3 | 166 | |
Freescale_cup | 0:3ec7fc598e48 | 167 | } |
leandre | 2:a37de5eb8bf3 | 168 | |
Freescale_cup | 0:3ec7fc598e48 | 169 | for(int j = 4; j > 0; j--) |
Freescale_cup | 0:3ec7fc598e48 | 170 | { |
Freescale_cup | 0:3ec7fc598e48 | 171 | last_five[j] = last_five[j-1]; |
leandre | 2:a37de5eb8bf3 | 172 | }*/ |
leandre | 2:a37de5eb8bf3 | 173 | |
leandre | 2:a37de5eb8bf3 | 174 | if (t_debut.read_ms()>500){ |
leandre | 2:a37de5eb8bf3 | 175 | moy_inter=Moyenne2(Interval, TAILLE_TAB_INT); |
leandre | 2:a37de5eb8bf3 | 176 | //pc.printf("%d\n",moy_inter); |
leandre | 2:a37de5eb8bf3 | 177 | |
leandre | 2:a37de5eb8bf3 | 178 | if((mem_a>6)&&(mem_b>6)){ // si la voiture n'est pas trop sur l'exterieur de la piste |
leandre | 2:a37de5eb8bf3 | 179 | if(S1 && (moy_inter<70) && (moy_inter>40)){ //si l'espace entre les deux lignes est plus petit que la normale (arret) |
leandre | 2:a37de5eb8bf3 | 180 | |
leandre | 2:a37de5eb8bf3 | 181 | //for(int i=0;i<5;i++) pc.printf("%d ",Interval[i]); |
leandre | 2:a37de5eb8bf3 | 182 | //pc.printf("\n"); |
leandre | 2:a37de5eb8bf3 | 183 | VIT=0; |
leandre | 2:a37de5eb8bf3 | 184 | pc.printf("\narret "); |
leandre | 2:a37de5eb8bf3 | 185 | pc.printf("\n%d ",moy_inter); |
leandre | 2:a37de5eb8bf3 | 186 | |
leandre | 2:a37de5eb8bf3 | 187 | } |
leandre | 2:a37de5eb8bf3 | 188 | } |
Freescale_cup | 0:3ec7fc598e48 | 189 | } |
leandre | 2:a37de5eb8bf3 | 190 | |
leandre | 2:a37de5eb8bf3 | 191 | for(int j = TAILLE_TAB_INT-1; j > 0; j--) |
leandre | 2:a37de5eb8bf3 | 192 | { |
leandre | 2:a37de5eb8bf3 | 193 | Interval[j] = Interval[j-1]; |
leandre | 2:a37de5eb8bf3 | 194 | } |
Freescale_cup | 0:3ec7fc598e48 | 195 | } |
Freescale_cup | 0:3ec7fc598e48 | 196 | |
Freescale_cup | 0:3ec7fc598e48 | 197 | |
Freescale_cup | 0:3ec7fc598e48 | 198 | |
Freescale_cup | 0:3ec7fc598e48 | 199 | |
Freescale_cup | 0:3ec7fc598e48 | 200 | |
Freescale_cup | 0:3ec7fc598e48 | 201 | //void F_BalanceBlancs() |
Freescale_cup | 0:3ec7fc598e48 | 202 | //{ |
Freescale_cup | 0:3ec7fc598e48 | 203 | // unsigned char moy = 0; |
Freescale_cup | 0:3ec7fc598e48 | 204 | // moy = Moyenne(cam_data); |
Freescale_cup | 0:3ec7fc598e48 | 205 | // if(moy > LUMI_MOYENNE && tempsInte >= MIN_INTE) tempsInte-=INCREM_BALANCE; |
Freescale_cup | 0:3ec7fc598e48 | 206 | // else if(tempsInte <= MAX_INTE) tempsInte+=INCREM_BALANCE; |
Freescale_cup | 0:3ec7fc598e48 | 207 | //} |
Freescale_cup | 0:3ec7fc598e48 | 208 | |
Freescale_cup | 0:3ec7fc598e48 | 209 | |
Freescale_cup | 0:3ec7fc598e48 | 210 |