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