programme ines avce xbee
Dependencies: MMA8451Q mbed xbee_lib
Fork of Programme_course by
main.cpp@0:3ec7fc598e48, 2017-01-26 (annotated)
- Committer:
- Freescale_cup
- Date:
- Thu Jan 26 07:37:45 2017 +0000
- Revision:
- 0:3ec7fc598e48
- Child:
- 1:4a9196bcf97a
Programme de base
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 | |
Freescale_cup | 0:3ec7fc598e48 | 72 | void arret() |
Freescale_cup | 0:3ec7fc598e48 | 73 | { |
Freescale_cup | 0:3ec7fc598e48 | 74 | PWM_motor(MOTEUR_A, 0); |
Freescale_cup | 0:3ec7fc598e48 | 75 | PWM_motor(MOTEUR_B, 0); |
Freescale_cup | 0:3ec7fc598e48 | 76 | while(BP1); |
Freescale_cup | 0:3ec7fc598e48 | 77 | while(!BP1); |
Freescale_cup | 0:3ec7fc598e48 | 78 | while(BP1); |
Freescale_cup | 0:3ec7fc598e48 | 79 | t_debut.reset(); |
Freescale_cup | 0:3ec7fc598e48 | 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 | |
Freescale_cup | 0:3ec7fc598e48 | 98 | timer.start(); |
Freescale_cup | 0:3ec7fc598e48 | 99 | |
Freescale_cup | 0:3ec7fc598e48 | 100 | angle_servo_moteur(0);//on met les roues droite pour commencer |
Freescale_cup | 0:3ec7fc598e48 | 101 | } |
Freescale_cup | 0:3ec7fc598e48 | 102 | |
Freescale_cup | 0:3ec7fc598e48 | 103 | int main() { |
Freescale_cup | 0:3ec7fc598e48 | 104 | |
Freescale_cup | 0:3ec7fc598e48 | 105 | Init_car(); |
Freescale_cup | 0:3ec7fc598e48 | 106 | |
Freescale_cup | 0:3ec7fc598e48 | 107 | while(!BP1)//tant que l'on appuie pas sur BP1 |
Freescale_cup | 0:3ec7fc598e48 | 108 | { |
Freescale_cup | 0:3ec7fc598e48 | 109 | menu(); |
Freescale_cup | 0:3ec7fc598e48 | 110 | } |
Freescale_cup | 0:3ec7fc598e48 | 111 | while(BP1);//on attends le relachement de BP1 |
Freescale_cup | 0:3ec7fc598e48 | 112 | |
Freescale_cup | 0:3ec7fc598e48 | 113 | /***************Début de la course***************/ |
Freescale_cup | 0:3ec7fc598e48 | 114 | |
Freescale_cup | 0:3ec7fc598e48 | 115 | t_debut.start();//Timer du début de la course |
Freescale_cup | 0:3ec7fc598e48 | 116 | t_ligne.start(); |
Freescale_cup | 0:3ec7fc598e48 | 117 | |
Freescale_cup | 0:3ec7fc598e48 | 118 | |
Freescale_cup | 0:3ec7fc598e48 | 119 | /************************************************/ |
Freescale_cup | 0:3ec7fc598e48 | 120 | |
Freescale_cup | 0:3ec7fc598e48 | 121 | /**********On demarre les moteurs****************/ |
Freescale_cup | 0:3ec7fc598e48 | 122 | PWM_motor(MOTEUR_A, VIT); |
Freescale_cup | 0:3ec7fc598e48 | 123 | PWM_motor(MOTEUR_B, VIT); |
Freescale_cup | 0:3ec7fc598e48 | 124 | |
Freescale_cup | 0:3ec7fc598e48 | 125 | while(1) {//boucle principale |
Freescale_cup | 0:3ec7fc598e48 | 126 | if(BP1) |
Freescale_cup | 0:3ec7fc598e48 | 127 | { |
Freescale_cup | 0:3ec7fc598e48 | 128 | arret(); |
Freescale_cup | 0:3ec7fc598e48 | 129 | } |
Freescale_cup | 0:3ec7fc598e48 | 130 | if(flag == 1)//début du cycle |
Freescale_cup | 0:3ec7fc598e48 | 131 | { |
Freescale_cup | 0:3ec7fc598e48 | 132 | flag = 0; |
Freescale_cup | 0:3ec7fc598e48 | 133 | |
Freescale_cup | 0:3ec7fc598e48 | 134 | /***************Récupération données*****************/ |
Freescale_cup | 0:3ec7fc598e48 | 135 | |
Freescale_cup | 0:3ec7fc598e48 | 136 | F_GetData(); |
Freescale_cup | 0:3ec7fc598e48 | 137 | |
Freescale_cup | 0:3ec7fc598e48 | 138 | /*****************Traitement Image*******************/ |
Freescale_cup | 0:3ec7fc598e48 | 139 | |
Freescale_cup | 0:3ec7fc598e48 | 140 | T_image(); |
Freescale_cup | 0:3ec7fc598e48 | 141 | |
Freescale_cup | 0:3ec7fc598e48 | 142 | /****************Gestion des Moteurs*****************/ |
Freescale_cup | 0:3ec7fc598e48 | 143 | |
Freescale_cup | 0:3ec7fc598e48 | 144 | angle_servo_moteur(new_bari); |
Freescale_cup | 0:3ec7fc598e48 | 145 | |
Freescale_cup | 0:3ec7fc598e48 | 146 | moteurs_arriere(); |
Freescale_cup | 0:3ec7fc598e48 | 147 | |
Freescale_cup | 0:3ec7fc598e48 | 148 | /****************Balance des blancs******************/ |
Freescale_cup | 0:3ec7fc598e48 | 149 | |
Freescale_cup | 0:3ec7fc598e48 | 150 | F_BalanceBlancs(); |
Freescale_cup | 0:3ec7fc598e48 | 151 | |
Freescale_cup | 0:3ec7fc598e48 | 152 | /******************Gestion_bosse*********************/ |
Freescale_cup | 0:3ec7fc598e48 | 153 | |
Freescale_cup | 0:3ec7fc598e48 | 154 | Gestion_bosse(); |
Freescale_cup | 0:3ec7fc598e48 | 155 | |
Freescale_cup | 0:3ec7fc598e48 | 156 | /****************Detection_arrivee*******************/ |
Freescale_cup | 0:3ec7fc598e48 | 157 | |
Freescale_cup | 0:3ec7fc598e48 | 158 | fin_course(); |
Freescale_cup | 0:3ec7fc598e48 | 159 | |
Freescale_cup | 0:3ec7fc598e48 | 160 | } |
Freescale_cup | 0:3ec7fc598e48 | 161 | |
Freescale_cup | 0:3ec7fc598e48 | 162 | } |
Freescale_cup | 0:3ec7fc598e48 | 163 | } |
Freescale_cup | 0:3ec7fc598e48 | 164 | |
Freescale_cup | 0:3ec7fc598e48 | 165 | |
Freescale_cup | 0:3ec7fc598e48 | 166 | |
Freescale_cup | 0:3ec7fc598e48 | 167 | |
Freescale_cup | 0:3ec7fc598e48 | 168 |