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