programme course avec menu amélioré
Fork of Programme_course_2017_virage_ameliore by
main.cpp@3:c0aae5aa230b, 2017-03-18 (annotated)
- Committer:
- leandre
- Date:
- Sat Mar 18 13:21:28 2017 +0000
- Revision:
- 3:c0aae5aa230b
- Parent:
- 2:a37de5eb8bf3
virage am?lior? 2
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; |
Freescale_cup | 0:3ec7fc598e48 | 57 | |
Freescale_cup | 0:3ec7fc598e48 | 58 | |
Freescale_cup | 0:3ec7fc598e48 | 59 | DigitalOut BP1(PTC13);//boutton A |
Freescale_cup | 0:3ec7fc598e48 | 60 | DigitalOut BP2(PTC17);//boutton B |
Freescale_cup | 0:3ec7fc598e48 | 61 | DigitalOut SI(PTD7); |
Freescale_cup | 0:3ec7fc598e48 | 62 | DigitalIn CLK_IN(PTE31); |
Freescale_cup | 0:3ec7fc598e48 | 63 | DigitalOut CLK(PTE1); |
Freescale_cup | 0:3ec7fc598e48 | 64 | AnalogIn AIN(PTD5); |
Freescale_cup | 0:3ec7fc598e48 | 65 | |
Freescale_cup | 0:3ec7fc598e48 | 66 | Ticker t_cyc; |
Freescale_cup | 0:3ec7fc598e48 | 67 | Ticker t_clk; |
Freescale_cup | 0:3ec7fc598e48 | 68 | Ticker t_finInte; |
Freescale_cup | 0:3ec7fc598e48 | 69 | |
Freescale_cup | 0:3ec7fc598e48 | 70 | Serial pc(USBTX, USBRX); |
Freescale_cup | 0:3ec7fc598e48 | 71 | |
Freescale_cup | 0:3ec7fc598e48 | 72 | |
Freescale_cup | 0:3ec7fc598e48 | 73 | void cycle() |
Freescale_cup | 0:3ec7fc598e48 | 74 | { |
Freescale_cup | 0:3ec7fc598e48 | 75 | flag = 1; |
Freescale_cup | 0:3ec7fc598e48 | 76 | } |
Freescale_cup | 0:3ec7fc598e48 | 77 | |
leandre | 1:000a03402c6e | 78 | |
Freescale_cup | 0:3ec7fc598e48 | 79 | |
Freescale_cup | 0:3ec7fc598e48 | 80 | |
Freescale_cup | 0:3ec7fc598e48 | 81 | |
Freescale_cup | 0:3ec7fc598e48 | 82 | |
Freescale_cup | 0:3ec7fc598e48 | 83 | void Init_car() |
Freescale_cup | 0:3ec7fc598e48 | 84 | { |
Freescale_cup | 0:3ec7fc598e48 | 85 | motor_init(); |
Freescale_cup | 0:3ec7fc598e48 | 86 | |
Freescale_cup | 0:3ec7fc598e48 | 87 | init_bary(); |
Freescale_cup | 0:3ec7fc598e48 | 88 | |
Freescale_cup | 0:3ec7fc598e48 | 89 | Get_pot_value(); |
Freescale_cup | 0:3ec7fc598e48 | 90 | |
Freescale_cup | 0:3ec7fc598e48 | 91 | t_cyc.attach_us(&cycle, FRQ_CYC);//interruption cycle |
Freescale_cup | 0:3ec7fc598e48 | 92 | |
Freescale_cup | 0:3ec7fc598e48 | 93 | clk_active = 0;//L'horloge est désactivée |
Freescale_cup | 0:3ec7fc598e48 | 94 | t_clk.attach(&F_CLK, 1/(2.0*FRQ_CLK));//interruption horloge |
Freescale_cup | 0:3ec7fc598e48 | 95 | |
leandre | 1:000a03402c6e | 96 | |
leandre | 1:000a03402c6e | 97 | |
Freescale_cup | 0:3ec7fc598e48 | 98 | timer.start(); |
Freescale_cup | 0:3ec7fc598e48 | 99 | |
leandre | 1:000a03402c6e | 100 | angle_servo_moteur(0);//on met les roues droite pour commencer |
leandre | 1:000a03402c6e | 101 | } |
leandre | 1:000a03402c6e | 102 | |
leandre | 1:000a03402c6e | 103 | void arret() |
leandre | 1:000a03402c6e | 104 | { |
leandre | 1:000a03402c6e | 105 | PWM_motor(MOTEUR_A, 0);//arret des moteurs |
leandre | 1:000a03402c6e | 106 | PWM_motor(MOTEUR_B, 0); |
leandre | 1:000a03402c6e | 107 | angle_servo_moteur(0);//roues droites //ici |
leandre | 1:000a03402c6e | 108 | while(BP1); |
leandre | 1:000a03402c6e | 109 | while(!BP1){ //ici |
leandre | 1:000a03402c6e | 110 | menu(); |
leandre | 1:000a03402c6e | 111 | } |
leandre | 1:000a03402c6e | 112 | while(BP1); |
leandre | 1:000a03402c6e | 113 | Init_car(); //permet de changer la vitesse avec le pot //ici |
leandre | 1:000a03402c6e | 114 | t_debut.reset(); |
Freescale_cup | 0:3ec7fc598e48 | 115 | } |
Freescale_cup | 0:3ec7fc598e48 | 116 | |
Freescale_cup | 0:3ec7fc598e48 | 117 | int main() { |
leandre | 1:000a03402c6e | 118 | Init_car(); |
Freescale_cup | 0:3ec7fc598e48 | 119 | |
Freescale_cup | 0:3ec7fc598e48 | 120 | |
Freescale_cup | 0:3ec7fc598e48 | 121 | while(!BP1)//tant que l'on appuie pas sur BP1 |
Freescale_cup | 0:3ec7fc598e48 | 122 | { |
Freescale_cup | 0:3ec7fc598e48 | 123 | menu(); |
Freescale_cup | 0:3ec7fc598e48 | 124 | } |
Freescale_cup | 0:3ec7fc598e48 | 125 | while(BP1);//on attends le relachement de BP1 |
leandre | 1:000a03402c6e | 126 | |
leandre | 1:000a03402c6e | 127 | |
Freescale_cup | 0:3ec7fc598e48 | 128 | /***************Début de la course***************/ |
Freescale_cup | 0:3ec7fc598e48 | 129 | |
Freescale_cup | 0:3ec7fc598e48 | 130 | t_debut.start();//Timer du début de la course |
Freescale_cup | 0:3ec7fc598e48 | 131 | t_ligne.start(); |
Freescale_cup | 0:3ec7fc598e48 | 132 | |
leandre | 1:000a03402c6e | 133 | |
Freescale_cup | 0:3ec7fc598e48 | 134 | |
Freescale_cup | 0:3ec7fc598e48 | 135 | /************************************************/ |
Freescale_cup | 0:3ec7fc598e48 | 136 | |
Freescale_cup | 0:3ec7fc598e48 | 137 | /**********On demarre les moteurs****************/ |
Freescale_cup | 0:3ec7fc598e48 | 138 | PWM_motor(MOTEUR_A, VIT); |
Freescale_cup | 0:3ec7fc598e48 | 139 | PWM_motor(MOTEUR_B, VIT); |
Freescale_cup | 0:3ec7fc598e48 | 140 | |
Freescale_cup | 0:3ec7fc598e48 | 141 | while(1) {//boucle principale |
Freescale_cup | 0:3ec7fc598e48 | 142 | if(BP1) |
Freescale_cup | 0:3ec7fc598e48 | 143 | { |
Freescale_cup | 0:3ec7fc598e48 | 144 | arret(); |
Freescale_cup | 0:3ec7fc598e48 | 145 | } |
Freescale_cup | 0:3ec7fc598e48 | 146 | if(flag == 1)//début du cycle |
Freescale_cup | 0:3ec7fc598e48 | 147 | { |
Freescale_cup | 0:3ec7fc598e48 | 148 | flag = 0; |
Freescale_cup | 0:3ec7fc598e48 | 149 | |
Freescale_cup | 0:3ec7fc598e48 | 150 | /***************Récupération données*****************/ |
Freescale_cup | 0:3ec7fc598e48 | 151 | |
Freescale_cup | 0:3ec7fc598e48 | 152 | F_GetData(); |
Freescale_cup | 0:3ec7fc598e48 | 153 | |
Freescale_cup | 0:3ec7fc598e48 | 154 | /*****************Traitement Image*******************/ |
Freescale_cup | 0:3ec7fc598e48 | 155 | |
Freescale_cup | 0:3ec7fc598e48 | 156 | T_image(); |
Freescale_cup | 0:3ec7fc598e48 | 157 | |
Freescale_cup | 0:3ec7fc598e48 | 158 | /****************Gestion des Moteurs*****************/ |
Freescale_cup | 0:3ec7fc598e48 | 159 | |
Freescale_cup | 0:3ec7fc598e48 | 160 | angle_servo_moteur(new_bari); |
Freescale_cup | 0:3ec7fc598e48 | 161 | |
Freescale_cup | 0:3ec7fc598e48 | 162 | moteurs_arriere(); |
Freescale_cup | 0:3ec7fc598e48 | 163 | |
Freescale_cup | 0:3ec7fc598e48 | 164 | /****************Balance des blancs******************/ |
Freescale_cup | 0:3ec7fc598e48 | 165 | |
Freescale_cup | 0:3ec7fc598e48 | 166 | F_BalanceBlancs(); |
Freescale_cup | 0:3ec7fc598e48 | 167 | |
Freescale_cup | 0:3ec7fc598e48 | 168 | /******************Gestion_bosse*********************/ |
Freescale_cup | 0:3ec7fc598e48 | 169 | |
Freescale_cup | 0:3ec7fc598e48 | 170 | Gestion_bosse(); |
Freescale_cup | 0:3ec7fc598e48 | 171 | |
Freescale_cup | 0:3ec7fc598e48 | 172 | /****************Detection_arrivee*******************/ |
Freescale_cup | 0:3ec7fc598e48 | 173 | |
Freescale_cup | 0:3ec7fc598e48 | 174 | fin_course(); |
leandre | 2:a37de5eb8bf3 | 175 | if(VIT==0) arret(); |
leandre | 1:000a03402c6e | 176 | |
Freescale_cup | 0:3ec7fc598e48 | 177 | |
Freescale_cup | 0:3ec7fc598e48 | 178 | } |
Freescale_cup | 0:3ec7fc598e48 | 179 | |
Freescale_cup | 0:3ec7fc598e48 | 180 | } |
Freescale_cup | 0:3ec7fc598e48 | 181 | } |
Freescale_cup | 0:3ec7fc598e48 | 182 | |
Freescale_cup | 0:3ec7fc598e48 | 183 | |
Freescale_cup | 0:3ec7fc598e48 | 184 | |
Freescale_cup | 0:3ec7fc598e48 | 185 | |
Freescale_cup | 0:3ec7fc598e48 | 186 |