programme course avec menu amélioré
Fork of Programme_course_vir_am_2 by
main.cpp@4:8b0215ec788f, 2017-03-22 (annotated)
- Committer:
- leandre
- Date:
- Wed Mar 22 14:41:20 2017 +0000
- Revision:
- 4:8b0215ec788f
- Parent:
- 2:a37de5eb8bf3
30 tours
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leandre | 2:a37de5eb8bf3 | 1 | |
leandre | 2:a37de5eb8bf3 | 2 | |
Freescale_cup | 0:3ec7fc598e48 | 3 | #include "Mlib.h" |
Freescale_cup | 0:3ec7fc598e48 | 4 | |
Freescale_cup | 0:3ec7fc598e48 | 5 | |
Freescale_cup | 0:3ec7fc598e48 | 6 | |
Freescale_cup | 0:3ec7fc598e48 | 7 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADRESS); |
Freescale_cup | 0:3ec7fc598e48 | 8 | DigitalOut activate_motor (PTE21); |
Freescale_cup | 0:3ec7fc598e48 | 9 | DigitalOut led1(PTB8); |
Freescale_cup | 0:3ec7fc598e48 | 10 | DigitalOut led2(PTB9); |
Freescale_cup | 0:3ec7fc598e48 | 11 | DigitalOut led3(PTB10); |
Freescale_cup | 0:3ec7fc598e48 | 12 | DigitalOut led4(PTB11); |
Freescale_cup | 0:3ec7fc598e48 | 13 | |
leandre | 2:a37de5eb8bf3 | 14 | |
Freescale_cup | 0:3ec7fc598e48 | 15 | AnalogIn pot1 (PTB3); |
Freescale_cup | 0:3ec7fc598e48 | 16 | AnalogIn pot2 (PTB2); |
Freescale_cup | 0:3ec7fc598e48 | 17 | |
Freescale_cup | 0:3ec7fc598e48 | 18 | DigitalIn S1(PTE2); |
Freescale_cup | 0:3ec7fc598e48 | 19 | DigitalIn S2(PTE3); |
Freescale_cup | 0:3ec7fc598e48 | 20 | DigitalIn S3(PTE4); |
Freescale_cup | 0:3ec7fc598e48 | 21 | DigitalIn S4(PTE5); |
Freescale_cup | 0:3ec7fc598e48 | 22 | Timer t_ligne; |
Freescale_cup | 0:3ec7fc598e48 | 23 | Timer timer; |
Freescale_cup | 0:3ec7fc598e48 | 24 | int ralentire = 0; |
Freescale_cup | 0:3ec7fc598e48 | 25 | |
Freescale_cup | 0:3ec7fc598e48 | 26 | /* |
Freescale_cup | 0:3ec7fc598e48 | 27 | AnalogIn pot1 (PTB3); |
Freescale_cup | 0:3ec7fc598e48 | 28 | AnalogIn pot2 (PTB2); |
Freescale_cup | 0:3ec7fc598e48 | 29 | |
Freescale_cup | 0:3ec7fc598e48 | 30 | printf("%f", pot1.read()); |
Freescale_cup | 0:3ec7fc598e48 | 31 | */ |
Freescale_cup | 0:3ec7fc598e48 | 32 | |
Freescale_cup | 0:3ec7fc598e48 | 33 | int tempsInte = MAX_INTE; |
Freescale_cup | 0:3ec7fc598e48 | 34 | unsigned char cam_data[128]; |
Freescale_cup | 0:3ec7fc598e48 | 35 | int baricentre = 0; |
Freescale_cup | 0:3ec7fc598e48 | 36 | int begin = 0; |
Freescale_cup | 0:3ec7fc598e48 | 37 | char flag = 0; |
Freescale_cup | 0:3ec7fc598e48 | 38 | char clk_active = 0; |
Freescale_cup | 0:3ec7fc598e48 | 39 | char bosse = 0; |
Freescale_cup | 0:3ec7fc598e48 | 40 | int bary_tab[3]; |
Freescale_cup | 0:3ec7fc598e48 | 41 | int bary_tab_bis[3]; |
Freescale_cup | 0:3ec7fc598e48 | 42 | char last_five[5]; |
Freescale_cup | 0:3ec7fc598e48 | 43 | float last_three[3]; |
Freescale_cup | 0:3ec7fc598e48 | 44 | Timer t_debut; |
Freescale_cup | 0:3ec7fc598e48 | 45 | int somme_derivee = 0; |
Freescale_cup | 0:3ec7fc598e48 | 46 | int VIT = 0; |
Freescale_cup | 0:3ec7fc598e48 | 47 | int KP = 80; |
Freescale_cup | 0:3ec7fc598e48 | 48 | int seuil_der = 0; |
Freescale_cup | 0:3ec7fc598e48 | 49 | int ajust_vitesse = 0; |
Freescale_cup | 0:3ec7fc598e48 | 50 | int new_bari = 0; |
Freescale_cup | 0:3ec7fc598e48 | 51 | int vitesse_virage = 0; |
Freescale_cup | 0:3ec7fc598e48 | 52 | int ligne_droite = 0; |
Freescale_cup | 0:3ec7fc598e48 | 53 | int integral; |
leandre | 2:a37de5eb8bf3 | 54 | char Interval[TAILLE_TAB_INT]; |
leandre | 2:a37de5eb8bf3 | 55 | char mem_a; |
leandre | 2:a37de5eb8bf3 | 56 | char mem_b; |
leandre | 4:8b0215ec788f | 57 | int ajust_vit_bosse; |
leandre | 4:8b0215ec788f | 58 | int ajust_vit_vir; |
Freescale_cup | 0:3ec7fc598e48 | 59 | |
Freescale_cup | 0:3ec7fc598e48 | 60 | |
Freescale_cup | 0:3ec7fc598e48 | 61 | DigitalOut BP1(PTC13);//boutton A |
Freescale_cup | 0:3ec7fc598e48 | 62 | DigitalOut BP2(PTC17);//boutton B |
Freescale_cup | 0:3ec7fc598e48 | 63 | DigitalOut SI(PTD7); |
Freescale_cup | 0:3ec7fc598e48 | 64 | DigitalIn CLK_IN(PTE31); |
Freescale_cup | 0:3ec7fc598e48 | 65 | DigitalOut CLK(PTE1); |
Freescale_cup | 0:3ec7fc598e48 | 66 | AnalogIn AIN(PTD5); |
Freescale_cup | 0:3ec7fc598e48 | 67 | |
Freescale_cup | 0:3ec7fc598e48 | 68 | Ticker t_cyc; |
Freescale_cup | 0:3ec7fc598e48 | 69 | Ticker t_clk; |
Freescale_cup | 0:3ec7fc598e48 | 70 | Ticker t_finInte; |
Freescale_cup | 0:3ec7fc598e48 | 71 | |
Freescale_cup | 0:3ec7fc598e48 | 72 | Serial pc(USBTX, USBRX); |
Freescale_cup | 0:3ec7fc598e48 | 73 | |
Freescale_cup | 0:3ec7fc598e48 | 74 | |
Freescale_cup | 0:3ec7fc598e48 | 75 | void cycle() |
Freescale_cup | 0:3ec7fc598e48 | 76 | { |
Freescale_cup | 0:3ec7fc598e48 | 77 | flag = 1; |
Freescale_cup | 0:3ec7fc598e48 | 78 | } |
Freescale_cup | 0:3ec7fc598e48 | 79 | |
leandre | 1:000a03402c6e | 80 | |
Freescale_cup | 0:3ec7fc598e48 | 81 | |
Freescale_cup | 0:3ec7fc598e48 | 82 | |
Freescale_cup | 0:3ec7fc598e48 | 83 | |
Freescale_cup | 0:3ec7fc598e48 | 84 | |
Freescale_cup | 0:3ec7fc598e48 | 85 | void Init_car() |
Freescale_cup | 0:3ec7fc598e48 | 86 | { |
Freescale_cup | 0:3ec7fc598e48 | 87 | motor_init(); |
Freescale_cup | 0:3ec7fc598e48 | 88 | |
Freescale_cup | 0:3ec7fc598e48 | 89 | init_bary(); |
Freescale_cup | 0:3ec7fc598e48 | 90 | |
Freescale_cup | 0:3ec7fc598e48 | 91 | Get_pot_value(); |
Freescale_cup | 0:3ec7fc598e48 | 92 | |
Freescale_cup | 0:3ec7fc598e48 | 93 | t_cyc.attach_us(&cycle, FRQ_CYC);//interruption cycle |
Freescale_cup | 0:3ec7fc598e48 | 94 | |
Freescale_cup | 0:3ec7fc598e48 | 95 | clk_active = 0;//L'horloge est désactivée |
Freescale_cup | 0:3ec7fc598e48 | 96 | t_clk.attach(&F_CLK, 1/(2.0*FRQ_CLK));//interruption horloge |
Freescale_cup | 0:3ec7fc598e48 | 97 | |
leandre | 1:000a03402c6e | 98 | |
leandre | 1:000a03402c6e | 99 | |
Freescale_cup | 0:3ec7fc598e48 | 100 | timer.start(); |
Freescale_cup | 0:3ec7fc598e48 | 101 | |
leandre | 1:000a03402c6e | 102 | angle_servo_moteur(0);//on met les roues droite pour commencer |
leandre | 1:000a03402c6e | 103 | } |
leandre | 1:000a03402c6e | 104 | |
leandre | 1:000a03402c6e | 105 | void arret() |
leandre | 1:000a03402c6e | 106 | { |
leandre | 4:8b0215ec788f | 107 | led1=0; |
leandre | 4:8b0215ec788f | 108 | led2=0; |
leandre | 4:8b0215ec788f | 109 | led3=0; |
leandre | 4:8b0215ec788f | 110 | led4=0; |
leandre | 1:000a03402c6e | 111 | PWM_motor(MOTEUR_A, 0);//arret des moteurs |
leandre | 1:000a03402c6e | 112 | PWM_motor(MOTEUR_B, 0); |
leandre | 1:000a03402c6e | 113 | angle_servo_moteur(0);//roues droites //ici |
leandre | 1:000a03402c6e | 114 | while(BP1); |
leandre | 1:000a03402c6e | 115 | while(!BP1){ //ici |
leandre | 1:000a03402c6e | 116 | menu(); |
leandre | 1:000a03402c6e | 117 | } |
leandre | 1:000a03402c6e | 118 | while(BP1); |
leandre | 1:000a03402c6e | 119 | Init_car(); //permet de changer la vitesse avec le pot //ici |
leandre | 4:8b0215ec788f | 120 | led1=0; |
leandre | 4:8b0215ec788f | 121 | led2=0; |
leandre | 4:8b0215ec788f | 122 | led3=0; |
leandre | 4:8b0215ec788f | 123 | led4=0; |
leandre | 1:000a03402c6e | 124 | t_debut.reset(); |
Freescale_cup | 0:3ec7fc598e48 | 125 | } |
Freescale_cup | 0:3ec7fc598e48 | 126 | |
Freescale_cup | 0:3ec7fc598e48 | 127 | int main() { |
leandre | 1:000a03402c6e | 128 | Init_car(); |
Freescale_cup | 0:3ec7fc598e48 | 129 | |
Freescale_cup | 0:3ec7fc598e48 | 130 | |
Freescale_cup | 0:3ec7fc598e48 | 131 | while(!BP1)//tant que l'on appuie pas sur BP1 |
Freescale_cup | 0:3ec7fc598e48 | 132 | { |
Freescale_cup | 0:3ec7fc598e48 | 133 | menu(); |
Freescale_cup | 0:3ec7fc598e48 | 134 | } |
Freescale_cup | 0:3ec7fc598e48 | 135 | while(BP1);//on attends le relachement de BP1 |
leandre | 4:8b0215ec788f | 136 | led1=0; |
leandre | 4:8b0215ec788f | 137 | led2=0; |
leandre | 4:8b0215ec788f | 138 | led3=0; |
leandre | 4:8b0215ec788f | 139 | led4=0; |
leandre | 1:000a03402c6e | 140 | |
Freescale_cup | 0:3ec7fc598e48 | 141 | /***************Début de la course***************/ |
Freescale_cup | 0:3ec7fc598e48 | 142 | |
Freescale_cup | 0:3ec7fc598e48 | 143 | t_debut.start();//Timer du début de la course |
Freescale_cup | 0:3ec7fc598e48 | 144 | t_ligne.start(); |
Freescale_cup | 0:3ec7fc598e48 | 145 | |
leandre | 1:000a03402c6e | 146 | |
Freescale_cup | 0:3ec7fc598e48 | 147 | |
Freescale_cup | 0:3ec7fc598e48 | 148 | /************************************************/ |
Freescale_cup | 0:3ec7fc598e48 | 149 | |
Freescale_cup | 0:3ec7fc598e48 | 150 | /**********On demarre les moteurs****************/ |
Freescale_cup | 0:3ec7fc598e48 | 151 | PWM_motor(MOTEUR_A, VIT); |
Freescale_cup | 0:3ec7fc598e48 | 152 | PWM_motor(MOTEUR_B, VIT); |
Freescale_cup | 0:3ec7fc598e48 | 153 | |
Freescale_cup | 0:3ec7fc598e48 | 154 | while(1) {//boucle principale |
Freescale_cup | 0:3ec7fc598e48 | 155 | if(BP1) |
Freescale_cup | 0:3ec7fc598e48 | 156 | { |
Freescale_cup | 0:3ec7fc598e48 | 157 | arret(); |
Freescale_cup | 0:3ec7fc598e48 | 158 | } |
Freescale_cup | 0:3ec7fc598e48 | 159 | if(flag == 1)//début du cycle |
Freescale_cup | 0:3ec7fc598e48 | 160 | { |
Freescale_cup | 0:3ec7fc598e48 | 161 | flag = 0; |
Freescale_cup | 0:3ec7fc598e48 | 162 | |
Freescale_cup | 0:3ec7fc598e48 | 163 | /***************Récupération données*****************/ |
Freescale_cup | 0:3ec7fc598e48 | 164 | |
Freescale_cup | 0:3ec7fc598e48 | 165 | F_GetData(); |
Freescale_cup | 0:3ec7fc598e48 | 166 | |
Freescale_cup | 0:3ec7fc598e48 | 167 | /*****************Traitement Image*******************/ |
Freescale_cup | 0:3ec7fc598e48 | 168 | |
Freescale_cup | 0:3ec7fc598e48 | 169 | T_image(); |
Freescale_cup | 0:3ec7fc598e48 | 170 | |
Freescale_cup | 0:3ec7fc598e48 | 171 | /****************Gestion des Moteurs*****************/ |
Freescale_cup | 0:3ec7fc598e48 | 172 | |
Freescale_cup | 0:3ec7fc598e48 | 173 | angle_servo_moteur(new_bari); |
Freescale_cup | 0:3ec7fc598e48 | 174 | |
Freescale_cup | 0:3ec7fc598e48 | 175 | moteurs_arriere(); |
Freescale_cup | 0:3ec7fc598e48 | 176 | |
Freescale_cup | 0:3ec7fc598e48 | 177 | /****************Balance des blancs******************/ |
Freescale_cup | 0:3ec7fc598e48 | 178 | |
Freescale_cup | 0:3ec7fc598e48 | 179 | F_BalanceBlancs(); |
Freescale_cup | 0:3ec7fc598e48 | 180 | |
Freescale_cup | 0:3ec7fc598e48 | 181 | /******************Gestion_bosse*********************/ |
Freescale_cup | 0:3ec7fc598e48 | 182 | |
Freescale_cup | 0:3ec7fc598e48 | 183 | Gestion_bosse(); |
Freescale_cup | 0:3ec7fc598e48 | 184 | |
Freescale_cup | 0:3ec7fc598e48 | 185 | /****************Detection_arrivee*******************/ |
Freescale_cup | 0:3ec7fc598e48 | 186 | |
Freescale_cup | 0:3ec7fc598e48 | 187 | fin_course(); |
leandre | 2:a37de5eb8bf3 | 188 | if(VIT==0) arret(); |
leandre | 1:000a03402c6e | 189 | |
Freescale_cup | 0:3ec7fc598e48 | 190 | |
Freescale_cup | 0:3ec7fc598e48 | 191 | } |
Freescale_cup | 0:3ec7fc598e48 | 192 | |
Freescale_cup | 0:3ec7fc598e48 | 193 | } |
Freescale_cup | 0:3ec7fc598e48 | 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 |