Programme carte strategie (disco)

Dependencies:   mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac

Committer:
Sitkah
Date:
Wed May 09 19:36:20 2018 +0000
Revision:
38:76f886a1c8e6
Parent:
37:fca332b64b42
Child:
40:21bb685b553b
test avant match

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sitkah 35:742dc6b200b0 1 #include "global.h"
Sitkah 31:833fc481b002 2 #include <string.h>
Sitkah 31:833fc481b002 3 #include <sstream>
Sitkah 29:41e02746041d 4 //#include "StrategieManager.h"
Sitkah 29:41e02746041d 5
Sitkah 29:41e02746041d 6
Sitkah 29:41e02746041d 7
Sitkah 29:41e02746041d 8 #define M_PI 3.14159265358979323846
Sitkah 35:742dc6b200b0 9 #define VERT 0xFF00FF00
Sitkah 29:41e02746041d 10 #define ROUGE 0xFFFF0000
Sitkah 35:742dc6b200b0 11 #define BLEU 0xFF0000FF
Sitkah 29:41e02746041d 12 #define JAUNE 0xFFFEFE00
Sitkah 29:41e02746041d 13 #define BLANC 0xFF000000
Sitkah 31:833fc481b002 14 #define ORANGE 0xFFFFA500
Sitkah 31:833fc481b002 15 #define NOIR 0xFF000000
Sitkah 29:41e02746041d 16 #define DIY_GREY 0xFFDFDFDF
antbig 0:ad97421fb1fb 17
Sitkah 29:41e02746041d 18 char tableau_aff[10][50];
Sitkah 29:41e02746041d 19 char tableau_etat[22][50]=
Sitkah 29:41e02746041d 20 {
Sitkah 29:41e02746041d 21 "Check_carte_screen",
Sitkah 29:41e02746041d 22 "Check_carte_screen_wait_ack",
Sitkah 29:41e02746041d 23 "Check_cartes",
Sitkah 29:41e02746041d 24 "Check_cartes_wait_ack",
Sitkah 29:41e02746041d 25 "Wait_force",
Sitkah 29:41e02746041d 26 "Config",
Sitkah 29:41e02746041d 27 "Game_init",
Sitkah 29:41e02746041d 28 "Game_wait_for_jack",
Sitkah 29:41e02746041d 29 "Game_start",
Sitkah 29:41e02746041d 30 "Game_next_instruction",
Sitkah 29:41e02746041d 31 "Game_instruction",
Sitkah 29:41e02746041d 32 "Game_wait_ack",
Sitkah 29:41e02746041d 33 "Game_jump_time",
Sitkah 29:41e02746041d 34 "Game_jump_config",
Sitkah 29:41e02746041d 35 "Game_jump_position",
Sitkah 29:41e02746041d 36 "Game_wait_end_instruction",
Sitkah 29:41e02746041d 37 "Warning_timeout",
Sitkah 29:41e02746041d 38 "Waring_end_balise_wait",
Sitkah 29:41e02746041d 39 "Warning_end_last_instruction",
Sitkah 29:41e02746041d 40 "Warning_switch_strategie",
Sitkah 29:41e02746041d 41 "End",
Sitkah 29:41e02746041d 42 "End_loop",
Sitkah 29:41e02746041d 43 };
Sitkah 29:41e02746041d 44
Sitkah 34:6aa4b46b102e 45 int waitingAckID_FIN;
Sitkah 34:6aa4b46b102e 46 int waitingAckFrom_FIN;
Sitkah 29:41e02746041d 47
Sitkah 29:41e02746041d 48 Ticker ticker;
Sitkah 29:41e02746041d 49 TS_DISCO_F469NI ts;
Sitkah 29:41e02746041d 50 LCD_DISCO_F469NI lcd;
Sitkah 29:41e02746041d 51
Sitkah 29:41e02746041d 52 TS_StateTypeDef TS_State;
Sitkah 29:41e02746041d 53
Sitkah 29:41e02746041d 54 Ticker chrono;
Sitkah 29:41e02746041d 55 Timeout AffTime;
Sitkah 29:41e02746041d 56 Timer timer;
antbig 0:ad97421fb1fb 57 Timer cartesCheker;//Le timer pour le timeout de la vérification des cartes
antbig 0:ad97421fb1fb 58 Timer gameTimer;
antbig 0:ad97421fb1fb 59 Timer debugetatTimer;
antbig 5:dcd817534b57 60 Timer timeoutWarning;
antbig 5:dcd817534b57 61 Timer timeoutWarningWaitEnd;
antbig 0:ad97421fb1fb 62 Timeout chronoEnd;//permet d'envoyer la trame CAN pour la fin
antbig 0:ad97421fb1fb 63
Sitkah 29:41e02746041d 64 unsigned char screenChecktry = 0;
Sitkah 29:41e02746041d 65 unsigned char test[32] = {32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32};
Sitkah 29:41e02746041d 66
Sitkah 29:41e02746041d 67 char counter = 0;
Sitkah 29:41e02746041d 68 char check;
Sitkah 29:41e02746041d 69 char Jack = 1;
Sitkah 38:76f886a1c8e6 70 short SCORE_GLOBAL=10;
Sitkah 38:76f886a1c8e6 71 short SCORE_GR=0;
Sitkah 38:76f886a1c8e6 72 short SCORE_PR=0;
Sitkah 29:41e02746041d 73
Sitkah 29:41e02746041d 74 int flag = 0, flag_strat = 0, flag_timer;
Sitkah 29:41e02746041d 75 char Ack_strat = 0;
Sitkah 29:41e02746041d 76 signed char Strat = 0;
antbig 0:ad97421fb1fb 77 signed char FIFO_lecture=0;//Position du fifo de lecture des messages CAN
antbig 0:ad97421fb1fb 78
antbig 0:ad97421fb1fb 79 signed short x_robot,y_robot,theta_robot;//La position du robot
ClementBreteau 25:f140c93a8666 80 signed short target_x_robot, target_y_robot, target_theta_robot;
ClementBreteau 25:f140c93a8666 81 E_InstructionType actionPrecedente;
antbig 12:14729d584500 82 signed short start_move_x,start_move_y,start_move_theta;//La position du robot lors du début d'un mouvement, utilisé pour reprendre le mouvement apres stop balise
Sitkah 29:41e02746041d 83 //unsigned char FIFO_ecriture=0; //Position du fifo pour la reception CAN
Sitkah 29:41e02746041d 84 int flagSendCan=1;
Sitkah 34:6aa4b46b102e 85 unsigned char Cote = 0; //0 -> VERT | 1 -> jaune
Sitkah 35:742dc6b200b0 86 unsigned short angleRecalage = 0;
antbig 0:ad97421fb1fb 87 unsigned char checkCurrent = 0;
antbig 0:ad97421fb1fb 88 unsigned char countAliveCard = 0;
Sitkah 35:742dc6b200b0 89 unsigned char ligne=0;
antbig 0:ad97421fb1fb 90
Sitkah 37:fca332b64b42 91 float angle_moyen_balise_IR = 0.0;
Sitkah 37:fca332b64b42 92
Sitkah 37:fca332b64b42 93
Sitkah 29:41e02746041d 94 signed char Strategie = 0; //N° de la strategie (1-10)
antbig 1:116040d14164 95
ClementBreteau 14:c8fc06c4887f 96 unsigned char ModeDemo = 0; // Si à 1, indique que l'on est dans le mode demo
ClementBreteau 14:c8fc06c4887f 97
antbig 5:dcd817534b57 98 unsigned char countRobotNear = 0;//Le nombre de robot à proximité
antbig 5:dcd817534b57 99
antbig 12:14729d584500 100 unsigned char ingnorBaliseOnce = 0;
antbig 12:14729d584500 101
antbig 28:acd18776ed2d 102 unsigned char ingnorInversionOnce = 0;//Pour ignorer l'inversion des instruction une fois
antbig 28:acd18776ed2d 103
antbig 28:acd18776ed2d 104 struct S_Instruction instruction;
antbig 28:acd18776ed2d 105
Sitkah 30:a1e37af4bbde 106 char couleur1, couleur2, couleur3;
Sitkah 29:41e02746041d 107 float cptf;
Sitkah 29:41e02746041d 108 int cpt,cpt1;
Sitkah 29:41e02746041d 109
Sitkah 32:1c9ab15c740e 110 typedef enum {INIT, ATT, CHOIX, DEMO, TEST_TELEMETRE, TEST_CAPTEURS, TEST_SERVO, TEST_TIR, DEMO_IMMEUBLE,DEMO_TRIEUR, SELECT_SIDE, TACTIQUE, DETAILS,LECTURE, LAUNCH, AFF_WAIT_JACK, WAIT_JACK, COMPTEUR, FIN} T_etat;
Sitkah 29:41e02746041d 111 T_etat etat = INIT;
Sitkah 29:41e02746041d 112 E_stratGameEtat gameEtat = ETAT_CHECK_CARTES;
Sitkah 29:41e02746041d 113 E_stratGameEtat lastEtat = ETAT_CHECK_CARTES;
Sitkah 38:76f886a1c8e6 114 E_Stratposdebut etat_pos=RECALAGE_1;
Sitkah 29:41e02746041d 115
Sitkah 29:41e02746041d 116 /////////////////DEFINITION DES BOUTONS////////////////////
Sitkah 34:6aa4b46b102e 117 Button COTE_VERT(0, 25, 400, 300, "VERT");
Sitkah 34:6aa4b46b102e 118 Button COTE_ORANGE(0, 350, 400, 300, "ORANGE");
Sitkah 29:41e02746041d 119 Button RETOUR (0, 680, 400, 110, "--Precedent--");
Sitkah 29:41e02746041d 120 Button LANCER (0, 200, 400, 200, "--LANCER--");
Sitkah 29:41e02746041d 121 Button CHECK (0, 420, 400, 200, "Valider");
Sitkah 29:41e02746041d 122 Button MATCH (0, 50, 400, 320, "Match");
Sitkah 29:41e02746041d 123 Button DEMONSTRATION (0, 400, 400, 320, "Demo");
Sitkah 31:833fc481b002 124 Button TEST_HERKULEX(0, 25, 400, 100, "Test servos");
Sitkah 32:1c9ab15c740e 125 Button TEST_LASER(0, 135, 400, 100, "Test telemetre");
Sitkah 32:1c9ab15c740e 126 Button TEST_COULEURS(0,245,400,100,"Test capteurs");
Sitkah 32:1c9ab15c740e 127 Button TEST_TIR_BALLE(0,355,400,100,"Test Lanceur");
Sitkah 32:1c9ab15c740e 128 Button TEST_IMMEUBLE(0,465,400,100,"Test immeuble");
Sitkah 32:1c9ab15c740e 129 Button TEST_TRIEUR(0,575,400,100,"Test aiguilleur");
Sitkah 31:833fc481b002 130 Button TIR_CHATEAU(0, 25, 400, 100, "Tir chateau");
Sitkah 31:833fc481b002 131 Button EPURATION(0, 150, 400, 100, "epuration");
Sitkah 31:833fc481b002 132 Button LANCEUR_ON(0,275,400,100,"allumer le lanceur");
Sitkah 31:833fc481b002 133 Button LANCEUR_OFF(0,400,400,100,"eteindre le lanceur");
Sitkah 31:833fc481b002 134 Button ABAISSE_BLOC(0, 25, 400, 100, "Ramasser blocs");
Sitkah 31:833fc481b002 135 Button RELEVE_BLOC(0, 135, 400, 100, "lacher blocs");
Sitkah 31:833fc481b002 136 Button BRAS_ABEILLE_ON(0,245,400,100,"bras abeille");
Sitkah 32:1c9ab15c740e 137 Button BRAS_ABEILLE_OFF(0,355,400,100,"baisser bras abeille");
Sitkah 31:833fc481b002 138 Button INTERRUPTEUR_ON(0,465,400,100,"baisser bras interrupt");
Sitkah 31:833fc481b002 139 Button INTERRUPTEUR_OFF(0,575,400,100,"baisser bras interrupt");
Sitkah 29:41e02746041d 140 Button FORCE_LAUNCH(0, 50, 400, 320, "Force Launch");
Sitkah 32:1c9ab15c740e 141 Button TRI(0, 25, 400, 100, "Test tri");
Sitkah 32:1c9ab15c740e 142 Button AIGUILLEUR_D(0, 150, 400, 100, "aiguilleur droite");
Sitkah 32:1c9ab15c740e 143 Button AIGUILLEUR_G(0,275,400,100,"aiguilleur gauche");
Sitkah 32:1c9ab15c740e 144 Button AIGUILLEUR_CTRE(0,400,400,100,"aiguilleur centre");
Sitkah 29:41e02746041d 145 Button SUIVANT(0,380,200,100,"Suivant");
Sitkah 31:833fc481b002 146 Button COLOR_ORANGE (0, 230, 190, 110,"");
Sitkah 31:833fc481b002 147 Button COLOR_JAUNE (210, 230, 190, 110,"");
Sitkah 34:6aa4b46b102e 148 Button COLOR_VERT (0, 350, 190, 110,"");
Sitkah 34:6aa4b46b102e 149 Button COLOR_BLEU (210, 350, 190, 110,"");
Sitkah 31:833fc481b002 150 Button COLOR_NOIR (105, 470, 190, 110,"");
Sitkah 29:41e02746041d 151 ////////////////////////////////////////////////////////////
Sitkah 29:41e02746041d 152
Sitkah 29:41e02746041d 153 void SendRawId (unsigned short id);
Sitkah 29:41e02746041d 154 void SelectionStrat (unsigned char numeroStrat);
Sitkah 29:41e02746041d 155 void Setflag(void);
Sitkah 29:41e02746041d 156 void can2Rx_ISR(void);
Sitkah 29:41e02746041d 157 signed char Bouton_Strat (void);
Sitkah 29:41e02746041d 158
Sitkah 29:41e02746041d 159 void print_segment(int nombre, int decalage);
Sitkah 29:41e02746041d 160 void affichage_compteur (int nombre);
Sitkah 29:41e02746041d 161 void effacer_segment(long couleur);
Sitkah 29:41e02746041d 162
Sitkah 30:a1e37af4bbde 163 unsigned short telemetreDistance=0;
Sitkah 34:6aa4b46b102e 164 unsigned short telemetreDistance_avant_gauche=0;
Sitkah 34:6aa4b46b102e 165 unsigned short telemetreDistance_avant_droite=0;
Sitkah 34:6aa4b46b102e 166 unsigned short telemetreDistance_arriere_gauche=0;
Sitkah 34:6aa4b46b102e 167 unsigned short telemetreDistance_arriere_droite=0;
Sitkah 29:41e02746041d 168
Sitkah 29:41e02746041d 169 #ifdef ROBOT_BIG
Sitkah 29:41e02746041d 170
Sitkah 29:41e02746041d 171
Sitkah 38:76f886a1c8e6 172 unsigned short id_check[NOMBRE_CARTES]= {CHECK_MOTEUR,CHECK_BALISE};
Sitkah 38:76f886a1c8e6 173 unsigned short id_alive[NOMBRE_CARTES]= {ALIVE_MOTEUR,ALIVE_BALISE};
Sitkah 29:41e02746041d 174
Sitkah 31:833fc481b002 175 InterruptIn jack(PG_11); // entrée analogique en interruption pour le jack
Sitkah 29:41e02746041d 176 #else
Sitkah 29:41e02746041d 177
Sitkah 29:41e02746041d 178
Sitkah 38:76f886a1c8e6 179 unsigned short id_check[NOMBRE_CARTES]= {CHECK_MOTEUR,CHECK_BALISE};
Sitkah 38:76f886a1c8e6 180 unsigned short id_alive[NOMBRE_CARTES]= {ALIVE_MOTEUR,ALIVE_BALISE};
Sitkah 31:833fc481b002 181 InterruptIn jack(PG_11); // entrée analogique en interruption pour le jack
Sitkah 29:41e02746041d 182
Sitkah 29:41e02746041d 183
Sitkah 29:41e02746041d 184 #endif
Sitkah 29:41e02746041d 185
Sitkah 29:41e02746041d 186
Sitkah 29:41e02746041d 187
Sitkah 29:41e02746041d 188
Sitkah 29:41e02746041d 189
ClementBreteau 14:c8fc06c4887f 190
antbig 4:88431b537477 191 /****************************************************************************************/
antbig 4:88431b537477 192 /* FUNCTION NAME: chronometre_ISR */
antbig 4:88431b537477 193 /* DESCRIPTION : Interruption à la fin des 90s du match */
antbig 4:88431b537477 194 /****************************************************************************************/
antbig 0:ad97421fb1fb 195 void chronometre_ISR (void)
antbig 0:ad97421fb1fb 196 {
antbig 0:ad97421fb1fb 197 SendRawId(ASSERVISSEMENT_STOP);//On stope les moteurs
antbig 0:ad97421fb1fb 198 SendRawId(GLOBAL_GAME_END);//Indication fin de match
Sitkah 29:41e02746041d 199 etat=FIN;
antbig 0:ad97421fb1fb 200 gameTimer.stop();//Arret du timer
antbig 0:ad97421fb1fb 201
antbig 1:116040d14164 202 #ifdef ROBOT_BIG
antbig 12:14729d584500 203 wait_ms(2000);
antbig 0:ad97421fb1fb 204 doFunnyAction();
antbig 0:ad97421fb1fb 205 #endif
antbig 0:ad97421fb1fb 206
antbig 1:116040d14164 207 while(1);//On bloque la programme dans l'interruption
antbig 0:ad97421fb1fb 208 }
antbig 0:ad97421fb1fb 209
Sitkah 29:41e02746041d 210
Sitkah 29:41e02746041d 211
antbig 4:88431b537477 212 /****************************************************************************************/
antbig 8:0edc7dfb7f7e 213 /* FUNCTION NAME: jack_ISR */
antbig 8:0edc7dfb7f7e 214 /* DESCRIPTION : Interruption en changement d'état sur le Jack */
antbig 8:0edc7dfb7f7e 215 /****************************************************************************************/
antbig 8:0edc7dfb7f7e 216 void jack_ISR (void)
antbig 8:0edc7dfb7f7e 217 {
antbig 8:0edc7dfb7f7e 218 if(gameEtat == ETAT_GAME_WAIT_FOR_JACK) {
antbig 8:0edc7dfb7f7e 219 gameEtat = ETAT_GAME_START;//On débute le match
Sitkah 29:41e02746041d 220 etat=COMPTEUR;
antbig 8:0edc7dfb7f7e 221 }
antbig 8:0edc7dfb7f7e 222 }
antbig 8:0edc7dfb7f7e 223
antbig 8:0edc7dfb7f7e 224 /****************************************************************************************/
Sitkah 29:41e02746041d 225 /* FUNCTION NAME: SelectionStrat */
Sitkah 29:41e02746041d 226 /* DESCRIPTION : Affiche la Stratégie sélectionnée sur l'ihm */
Sitkah 29:41e02746041d 227 /****************************************************************************************/
Sitkah 29:41e02746041d 228
Sitkah 29:41e02746041d 229
Sitkah 29:41e02746041d 230 void SelectionStrat (unsigned char Strategie)
Sitkah 29:41e02746041d 231 {
Sitkah 29:41e02746041d 232 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 233 lcd.SetTextColor(LCD_COLOR_BLACK);
Sitkah 29:41e02746041d 234
Sitkah 29:41e02746041d 235 switch (Strategie+1)
Sitkah 29:41e02746041d 236 {
Sitkah 29:41e02746041d 237 case 0x1 :
Sitkah 29:41e02746041d 238 //description de Strategie n°1
Sitkah 29:41e02746041d 239 lcd.DisplayStringAt(150, 0, (uint8_t *)strat_sd[Strategie], LEFT_MODE);
Sitkah 29:41e02746041d 240 break;
Sitkah 29:41e02746041d 241
Sitkah 29:41e02746041d 242 case 0x2 :
Sitkah 29:41e02746041d 243 //description de Strategie n°2
Sitkah 29:41e02746041d 244 lcd.DisplayStringAt(150,0, (uint8_t *)strat_sd[Strategie], LEFT_MODE);
Sitkah 29:41e02746041d 245 break;
Sitkah 29:41e02746041d 246
Sitkah 29:41e02746041d 247 case 0x3 :
Sitkah 29:41e02746041d 248 //description de Strategie n°3
Sitkah 29:41e02746041d 249 lcd.DisplayStringAt(150,0, (uint8_t *)strat_sd[Strategie], LEFT_MODE);
Sitkah 29:41e02746041d 250 break;
Sitkah 29:41e02746041d 251
Sitkah 29:41e02746041d 252 case 0x4 :
Sitkah 29:41e02746041d 253 //description de Strategie n°4
Sitkah 29:41e02746041d 254 lcd.DisplayStringAt(150,0, (uint8_t *)strat_sd[Strategie], LEFT_MODE);
Sitkah 29:41e02746041d 255 break;
Sitkah 29:41e02746041d 256
Sitkah 29:41e02746041d 257 case 0x5 :
Sitkah 29:41e02746041d 258 //description de Strategie n°5
Sitkah 29:41e02746041d 259 lcd.DisplayStringAt(150,0, (uint8_t *)strat_sd[Strategie], LEFT_MODE);
Sitkah 29:41e02746041d 260 break;
Sitkah 29:41e02746041d 261
Sitkah 29:41e02746041d 262 case 0x6 :
Sitkah 29:41e02746041d 263 //description de Strategie n°5
Sitkah 29:41e02746041d 264 lcd.DisplayStringAt(150,0, (uint8_t *)strat_sd[Strategie], LEFT_MODE);
Sitkah 29:41e02746041d 265 break;
Sitkah 29:41e02746041d 266
Sitkah 29:41e02746041d 267 case 0x7 :
Sitkah 29:41e02746041d 268 //description de Strategie n°5
Sitkah 29:41e02746041d 269 lcd.DisplayStringAt(150,0, (uint8_t *)strat_sd[Strategie], LEFT_MODE);
Sitkah 29:41e02746041d 270 break;
Sitkah 29:41e02746041d 271
Sitkah 29:41e02746041d 272 case 0x8 :
Sitkah 29:41e02746041d 273 //description de Strategie n°5
Sitkah 29:41e02746041d 274 lcd.DisplayStringAt(150,0, (uint8_t *)strat_sd[Strategie], LEFT_MODE);
Sitkah 29:41e02746041d 275 break;
Sitkah 29:41e02746041d 276
Sitkah 29:41e02746041d 277 case 0x9 :
Sitkah 29:41e02746041d 278 //description de Strategie n°5
Sitkah 29:41e02746041d 279 lcd.DisplayStringAt(150,0, (uint8_t *)strat_sd[Strategie], LEFT_MODE);
Sitkah 29:41e02746041d 280 break;
Sitkah 29:41e02746041d 281
Sitkah 29:41e02746041d 282 case 0xA :
Sitkah 29:41e02746041d 283 //description de Strategie n°5
Sitkah 29:41e02746041d 284 lcd.DisplayStringAt(150,0, (uint8_t *)strat_sd[Strategie], LEFT_MODE);
Sitkah 29:41e02746041d 285 break;
Sitkah 29:41e02746041d 286 }
Sitkah 29:41e02746041d 287 }
Sitkah 29:41e02746041d 288
Sitkah 29:41e02746041d 289 void Setflag(void)
Sitkah 29:41e02746041d 290 {
Sitkah 29:41e02746041d 291 flagSendCan = 1;
Sitkah 29:41e02746041d 292 }
Sitkah 29:41e02746041d 293
Sitkah 35:742dc6b200b0 294 void affichage_var(double Var){
Sitkah 35:742dc6b200b0 295 if(ligne==7)
Sitkah 35:742dc6b200b0 296 ligne=0;
Sitkah 35:742dc6b200b0 297 char aff[10]="toto";
Sitkah 35:742dc6b200b0 298 sprintf(aff,"%lf ",Var);
Sitkah 38:76f886a1c8e6 299 lcd.DisplayStringAt(120, LINE(15+(ligne)), (uint8_t *)aff, LEFT_MODE);
Sitkah 38:76f886a1c8e6 300 //ligne++;
Sitkah 35:742dc6b200b0 301
Sitkah 35:742dc6b200b0 302 }
Sitkah 35:742dc6b200b0 303
Sitkah 30:a1e37af4bbde 304 void affichage_debug(int Var){
Sitkah 29:41e02746041d 305 int i;
Sitkah 29:41e02746041d 306 int conv=(int)Var;
Sitkah 29:41e02746041d 307 SUIVANT.Draw(ROUGE, 0);
Sitkah 29:41e02746041d 308 for(i=0;i<9;i++){
Sitkah 29:41e02746041d 309 strcpy(tableau_aff[i],"");
Sitkah 29:41e02746041d 310 strcpy(tableau_aff[i],tableau_aff[i+1]);
Sitkah 29:41e02746041d 311 }
Sitkah 29:41e02746041d 312 strcpy(tableau_aff[9],tableau_etat[conv]);
Sitkah 29:41e02746041d 313 for(i=0;i<10;i++){
Sitkah 34:6aa4b46b102e 314 lcd.SetBackColor(VERT);
Sitkah 29:41e02746041d 315 lcd.DisplayStringAt(0, LINE(20+i), (uint8_t *)tableau_aff[i], LEFT_MODE);
Sitkah 29:41e02746041d 316 }
Sitkah 30:a1e37af4bbde 317 /*while(!ack_bluetooth){
Sitkah 30:a1e37af4bbde 318 //liaison_bluetooth();
Sitkah 29:41e02746041d 319 }
Sitkah 30:a1e37af4bbde 320 ack_bluetooth=0;*/
Sitkah 30:a1e37af4bbde 321 /*while(SUIVANT.Touched()==0);
Sitkah 30:a1e37af4bbde 322 while(SUIVANT.Touched());*/
Sitkah 29:41e02746041d 323 }
Sitkah 29:41e02746041d 324
Sitkah 29:41e02746041d 325
Sitkah 29:41e02746041d 326 void automate_etat_ihm(void)
Sitkah 29:41e02746041d 327 {
Sitkah 29:41e02746041d 328 int j;
Sitkah 29:41e02746041d 329 if (j==0){
Sitkah 29:41e02746041d 330 ts.Init(lcd.GetXSize(), lcd.GetYSize());
Sitkah 29:41e02746041d 331 j++;
Sitkah 29:41e02746041d 332 }
Sitkah 29:41e02746041d 333 ts.GetState(&TS_State);
Sitkah 29:41e02746041d 334 switch (etat)
Sitkah 29:41e02746041d 335 {
Sitkah 29:41e02746041d 336 case INIT :
Sitkah 29:41e02746041d 337 ts.GetState(&TS_State);
Sitkah 29:41e02746041d 338 canProcessRx();
Sitkah 30:a1e37af4bbde 339
Sitkah 32:1c9ab15c740e 340
Sitkah 30:a1e37af4bbde 341
Sitkah 30:a1e37af4bbde 342
Sitkah 29:41e02746041d 343 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 344 lcd.SetTextColor(LCD_COLOR_BLACK);
Sitkah 29:41e02746041d 345 lcd.Clear (LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 346 wait(0.15);
Sitkah 29:41e02746041d 347 lcd.DisplayStringAt(0, 10, (uint8_t *)"Verification des cartes", LEFT_MODE);
Sitkah 29:41e02746041d 348 //cartes non verifiées////////////////
Sitkah 29:41e02746041d 349 lcd.SetTextColor(DIY_GREY);
Sitkah 29:41e02746041d 350 lcd.FillRect(0,400,400,150); //carte moteur
Sitkah 29:41e02746041d 351 lcd.FillRect(0,600,400,150); //Balise
Sitkah 29:41e02746041d 352
Sitkah 29:41e02746041d 353 lcd.SetTextColor(LCD_COLOR_BLACK);
Sitkah 29:41e02746041d 354 lcd.SetBackColor(DIY_GREY);
Sitkah 29:41e02746041d 355 lcd.DisplayStringAt(80, 450, (uint8_t *)"Carte Moteur", LEFT_MODE);
Sitkah 29:41e02746041d 356 lcd.DisplayStringAt(110,650 , (uint8_t *)"Balise", LEFT_MODE);
Sitkah 29:41e02746041d 357 ////////////////////////////////////////
Sitkah 29:41e02746041d 358
Sitkah 38:76f886a1c8e6 359 FORCE_LAUNCH.Draw(0xFFFF0000, 0);
Sitkah 29:41e02746041d 360
Sitkah 29:41e02746041d 361 etat=ATT;
Sitkah 29:41e02746041d 362 break;
Sitkah 29:41e02746041d 363
Sitkah 29:41e02746041d 364 case ATT :
Sitkah 29:41e02746041d 365 if (flag==1){
Sitkah 29:41e02746041d 366 etat = CHOIX;
Sitkah 29:41e02746041d 367 gameEtat = ETAT_CONFIG;
Sitkah 29:41e02746041d 368 }
Sitkah 29:41e02746041d 369 else if (FORCE_LAUNCH.Touched()){
Sitkah 29:41e02746041d 370 etat = CHOIX;
Sitkah 29:41e02746041d 371 gameEtat = ETAT_CONFIG;
Sitkah 30:a1e37af4bbde 372 while(FORCE_LAUNCH.Touched());
Sitkah 29:41e02746041d 373 }
Sitkah 29:41e02746041d 374
Sitkah 29:41e02746041d 375 break;
Sitkah 29:41e02746041d 376
Sitkah 29:41e02746041d 377
Sitkah 29:41e02746041d 378 case CHOIX :
Sitkah 29:41e02746041d 379 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 380 lcd.SetTextColor(LCD_COLOR_BLACK);
Sitkah 29:41e02746041d 381 lcd.Clear (LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 382 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)"Match ou demonstration ?", LEFT_MODE);
Sitkah 29:41e02746041d 383 DEMONSTRATION.Draw(LCD_COLOR_LIGHTGREEN, 0);
Sitkah 29:41e02746041d 384 MATCH.Draw(0xFFF01010, 0);
Sitkah 29:41e02746041d 385 while(etat == CHOIX)
Sitkah 29:41e02746041d 386 {
Sitkah 29:41e02746041d 387 canProcessRx();
Sitkah 29:41e02746041d 388 if(DEMONSTRATION.Touched())
Sitkah 29:41e02746041d 389 {
Sitkah 29:41e02746041d 390 etat = DEMO;
Sitkah 29:41e02746041d 391 while(DEMONSTRATION.Touched());
Sitkah 29:41e02746041d 392 }
Sitkah 29:41e02746041d 393
Sitkah 29:41e02746041d 394 if(MATCH.Touched())
Sitkah 29:41e02746041d 395 {
Sitkah 29:41e02746041d 396 etat = SELECT_SIDE;
Sitkah 29:41e02746041d 397 while(MATCH.Touched());
Sitkah 29:41e02746041d 398 }
Sitkah 29:41e02746041d 399
Sitkah 29:41e02746041d 400 }
Sitkah 29:41e02746041d 401 break;
Sitkah 29:41e02746041d 402
Sitkah 29:41e02746041d 403 case DEMO :
Sitkah 29:41e02746041d 404 lcd.Clear(LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 405 RETOUR.Draw(0xFFFF0000, 0);
Sitkah 34:6aa4b46b102e 406 TEST_HERKULEX.Draw(VERT, 0);
Sitkah 34:6aa4b46b102e 407 TEST_LASER.Draw(VERT, 0);
Sitkah 34:6aa4b46b102e 408 TEST_COULEURS.Draw(VERT, 0);
Sitkah 34:6aa4b46b102e 409 TEST_TIR_BALLE.Draw(VERT, 0);
Sitkah 34:6aa4b46b102e 410 TEST_IMMEUBLE.Draw(VERT,0);
Sitkah 34:6aa4b46b102e 411 TEST_TRIEUR.Draw(VERT,0);
Sitkah 29:41e02746041d 412 if(gameEtat == ETAT_CONFIG) {//C'est bon on a le droit de modifier les config //
Sitkah 29:41e02746041d 413 InversStrat = 0;//Pas d'inversion de la couleur // A changer , discussion avec l'ihm
Sitkah 29:41e02746041d 414 }
Sitkah 29:41e02746041d 415 while (etat == DEMO)
Sitkah 29:41e02746041d 416 {
Sitkah 29:41e02746041d 417 canProcessRx();
Sitkah 31:833fc481b002 418 if(TEST_HERKULEX.Touched())
Sitkah 29:41e02746041d 419 {
Sitkah 30:a1e37af4bbde 420 //Strat = 0x10;
Sitkah 31:833fc481b002 421 while(TEST_HERKULEX.Touched());
Sitkah 32:1c9ab15c740e 422 CANMessage trame_Tx = CANMessage();
Sitkah 32:1c9ab15c740e 423 trame_Tx.len = 1;
Sitkah 32:1c9ab15c740e 424 trame_Tx.format = CANStandard;
Sitkah 32:1c9ab15c740e 425 trame_Tx.type = CANData;
Sitkah 31:833fc481b002 426 trame_Tx.id=CHOICE_COLOR;
Sitkah 32:1c9ab15c740e 427 trame_Tx.data[0]=0x2;
Sitkah 31:833fc481b002 428 can2.write(trame_Tx);
Sitkah 31:833fc481b002 429 TEST_HERKULEX.Draw(0xFFF0F0F0, 0);
Sitkah 31:833fc481b002 430 etat = TEST_SERVO;
Sitkah 31:833fc481b002 431 lcd.Clear(LCD_COLOR_WHITE);
Sitkah 30:a1e37af4bbde 432 ModeDemo=1;
Sitkah 29:41e02746041d 433 }
Sitkah 29:41e02746041d 434
Sitkah 31:833fc481b002 435 else if(TEST_LASER.Touched())
Sitkah 31:833fc481b002 436 {
Sitkah 31:833fc481b002 437 //Strat = 0x11;
Sitkah 31:833fc481b002 438 while(TEST_LASER.Touched());
Sitkah 31:833fc481b002 439 TEST_LASER.Draw(0xFFF0F0F0, 0);
Sitkah 31:833fc481b002 440 etat = TEST_TELEMETRE;
Sitkah 31:833fc481b002 441 }
Sitkah 31:833fc481b002 442 else if (TEST_COULEURS.Touched()){
Sitkah 31:833fc481b002 443 while(TEST_COULEURS.Touched());
Sitkah 31:833fc481b002 444 TEST_LASER.Draw(0xFFF0F0F0, 0);
Sitkah 31:833fc481b002 445 etat =TEST_CAPTEURS ;
Sitkah 31:833fc481b002 446 }
Sitkah 31:833fc481b002 447 else if (TEST_TIR_BALLE.Touched()){
Sitkah 31:833fc481b002 448 while(TEST_TIR_BALLE.Touched());
Sitkah 31:833fc481b002 449 TEST_TIR_BALLE.Draw(0xFFF0F0F0, 0);
Sitkah 31:833fc481b002 450 etat =TEST_TIR ;
Sitkah 31:833fc481b002 451 lcd.Clear(LCD_COLOR_WHITE);
Sitkah 32:1c9ab15c740e 452 CANMessage trame_Tx = CANMessage();
Sitkah 32:1c9ab15c740e 453 trame_Tx.len = 1;
Sitkah 32:1c9ab15c740e 454 trame_Tx.format = CANStandard;
Sitkah 32:1c9ab15c740e 455 trame_Tx.type = CANData;
Sitkah 31:833fc481b002 456 trame_Tx.id=CHOICE_COLOR;
Sitkah 32:1c9ab15c740e 457 trame_Tx.data[0]=0x2;
Sitkah 31:833fc481b002 458 can2.write(trame_Tx);
Sitkah 31:833fc481b002 459 ModeDemo=1;
Sitkah 31:833fc481b002 460 }
Sitkah 31:833fc481b002 461 else if(TEST_IMMEUBLE.Touched()){
Sitkah 31:833fc481b002 462 while(TEST_IMMEUBLE.Touched());
Sitkah 31:833fc481b002 463 TEST_IMMEUBLE.Draw(0xFFF0F0F0, 0);
Sitkah 31:833fc481b002 464 etat =DEMO_IMMEUBLE;
Sitkah 31:833fc481b002 465 lcd.Clear(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 466 }
Sitkah 32:1c9ab15c740e 467 else if(TEST_TRIEUR.Touched()){
Sitkah 32:1c9ab15c740e 468 while(TEST_TRIEUR.Touched());
Sitkah 32:1c9ab15c740e 469 etat=DEMO_TRIEUR;
Sitkah 32:1c9ab15c740e 470 lcd.Clear(LCD_COLOR_WHITE);
Sitkah 32:1c9ab15c740e 471 }
Sitkah 32:1c9ab15c740e 472
Sitkah 32:1c9ab15c740e 473
Sitkah 29:41e02746041d 474 if(RETOUR.Touched())
Sitkah 29:41e02746041d 475 {
Sitkah 29:41e02746041d 476 etat = CHOIX;
Sitkah 29:41e02746041d 477 while(RETOUR.Touched());
Sitkah 31:833fc481b002 478
Sitkah 29:41e02746041d 479 }
Sitkah 29:41e02746041d 480 if(gameEtat == ETAT_CONFIG) {//C'est bon on a le droit de modifier les config
Sitkah 30:a1e37af4bbde 481 /*if (Strat< 0x10){ // Si la strat est une strat de match, on desactive le mode demo
Sitkah 29:41e02746041d 482 ModeDemo = 0;
Sitkah 29:41e02746041d 483 }
Sitkah 29:41e02746041d 484 else { // sinon, on active le mode demo, utile pour la fin de la demo
Sitkah 29:41e02746041d 485 ModeDemo = 1;
Sitkah 30:a1e37af4bbde 486 }*/
Sitkah 29:41e02746041d 487 Ack_strat = 1;
Sitkah 29:41e02746041d 488 wait_ms(10);
Sitkah 30:a1e37af4bbde 489 //tactile_printf("Strat %d, Asser desactive",Strat);
Sitkah 29:41e02746041d 490 }
Sitkah 30:a1e37af4bbde 491 //SelectionStrat(Strategie);
Sitkah 29:41e02746041d 492 }
Sitkah 29:41e02746041d 493 break;
Sitkah 32:1c9ab15c740e 494 case DEMO_TRIEUR:
Sitkah 32:1c9ab15c740e 495 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 32:1c9ab15c740e 496 lcd.DisplayStringAt(20, LINE(2), (uint8_t *)"DEMONSTRATION COURS", LEFT_MODE);
Sitkah 32:1c9ab15c740e 497 TRI.Draw(VERT, 0);
Sitkah 32:1c9ab15c740e 498 AIGUILLEUR_D.Draw(VERT, 0);
Sitkah 32:1c9ab15c740e 499 AIGUILLEUR_G.Draw(VERT, 0);
Sitkah 32:1c9ab15c740e 500 AIGUILLEUR_CTRE.Draw(VERT, 0);
Sitkah 32:1c9ab15c740e 501 while(etat==DEMO_TRIEUR){
Sitkah 32:1c9ab15c740e 502 if(RETOUR.Touched()){
Sitkah 32:1c9ab15c740e 503 while (RETOUR.Touched());
Sitkah 32:1c9ab15c740e 504 etat=DEMO;
Sitkah 32:1c9ab15c740e 505 }
Sitkah 32:1c9ab15c740e 506 else if(TRI.Touched()){
Sitkah 32:1c9ab15c740e 507 while (TRI.Touched());
Sitkah 32:1c9ab15c740e 508 SendRawId(AIGUILLEUR_CENTRE);
Sitkah 32:1c9ab15c740e 509 wait(0.5);
Sitkah 32:1c9ab15c740e 510 SendRawId(AIGUILLEUR_DROITE);
Sitkah 32:1c9ab15c740e 511 wait(0.5);
Sitkah 32:1c9ab15c740e 512 SendRawId(AIGUILLEUR_GAUCHE);
Sitkah 32:1c9ab15c740e 513 wait(0.5);
Sitkah 32:1c9ab15c740e 514 SendRawId(AIGUILLEUR_CENTRE);
Sitkah 32:1c9ab15c740e 515
Sitkah 32:1c9ab15c740e 516 break;
Sitkah 32:1c9ab15c740e 517 }
Sitkah 32:1c9ab15c740e 518 else if(AIGUILLEUR_D.Touched()){
Sitkah 32:1c9ab15c740e 519 while (AIGUILLEUR_D.Touched());
Sitkah 32:1c9ab15c740e 520 SendRawId(AIGUILLEUR_DROITE);
Sitkah 32:1c9ab15c740e 521 break;
Sitkah 32:1c9ab15c740e 522 }
Sitkah 32:1c9ab15c740e 523 else if(AIGUILLEUR_G.Touched()){
Sitkah 32:1c9ab15c740e 524 while (AIGUILLEUR_G.Touched());
Sitkah 32:1c9ab15c740e 525 SendRawId(AIGUILLEUR_GAUCHE);
Sitkah 32:1c9ab15c740e 526 break;
Sitkah 32:1c9ab15c740e 527
Sitkah 32:1c9ab15c740e 528 }
Sitkah 32:1c9ab15c740e 529 else if(BRAS_ABEILLE_OFF.Touched()){
Sitkah 32:1c9ab15c740e 530 while (BRAS_ABEILLE_OFF.Touched());
Sitkah 32:1c9ab15c740e 531 SendRawId(BRAS_ABEILLE_DOWN);
Sitkah 32:1c9ab15c740e 532 break;
Sitkah 32:1c9ab15c740e 533 }
Sitkah 32:1c9ab15c740e 534 else if(AIGUILLEUR_CTRE.Touched()){
Sitkah 32:1c9ab15c740e 535 while (AIGUILLEUR_CTRE.Touched());
Sitkah 32:1c9ab15c740e 536 SendRawId(AIGUILLEUR_CENTRE);
Sitkah 32:1c9ab15c740e 537 break;
Sitkah 32:1c9ab15c740e 538 }
Sitkah 32:1c9ab15c740e 539
Sitkah 32:1c9ab15c740e 540 }
Sitkah 32:1c9ab15c740e 541 break;
Sitkah 31:833fc481b002 542 case DEMO_IMMEUBLE:
Sitkah 31:833fc481b002 543 int color=0;
Sitkah 31:833fc481b002 544 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 545 lcd.DisplayStringAt(20, LINE(2), (uint8_t *)"Choix du code couleur", LEFT_MODE);
Sitkah 29:41e02746041d 546
Sitkah 31:833fc481b002 547 CANMessage msgTx=CANMessage();
Sitkah 31:833fc481b002 548 msgTx.id=MONTER_IMMEUBLE; // Monter immeuble
Sitkah 31:833fc481b002 549 msgTx.len=3;
Sitkah 31:833fc481b002 550 msgTx.format=CANStandard;
Sitkah 31:833fc481b002 551 msgTx.type=CANData;
Sitkah 29:41e02746041d 552
Sitkah 29:41e02746041d 553
Sitkah 31:833fc481b002 554 while(etat==DEMO_IMMEUBLE){
Sitkah 31:833fc481b002 555 switch(color){
Sitkah 31:833fc481b002 556 case 0:
Sitkah 31:833fc481b002 557
Sitkah 31:833fc481b002 558 RETOUR.Draw(ROUGE,0);
Sitkah 31:833fc481b002 559 COLOR_NOIR.Draw(NOIR,1);
Sitkah 31:833fc481b002 560 COLOR_ORANGE.Draw(ORANGE,0);
Sitkah 31:833fc481b002 561 COLOR_JAUNE.Draw(JAUNE,0);
Sitkah 31:833fc481b002 562 COLOR_VERT.Draw(VERT,0);
Sitkah 38:76f886a1c8e6 563 COLOR_BLEU.Draw(BLEU,0);
Sitkah 31:833fc481b002 564
Sitkah 31:833fc481b002 565 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 566 lcd.SetTextColor(NOIR);
Sitkah 31:833fc481b002 567 lcd.DisplayStringAt(100, LINE(4), (uint8_t *)"COULEUR 1", LEFT_MODE);
Sitkah 31:833fc481b002 568 while(color==0){
Sitkah 31:833fc481b002 569 if(COLOR_ORANGE.Touched()){
Sitkah 31:833fc481b002 570 while(COLOR_ORANGE.Touched());
Sitkah 31:833fc481b002 571 COLOR_ORANGE.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 572 msgTx.data[color]=1;
Sitkah 31:833fc481b002 573 color++;
Sitkah 31:833fc481b002 574 }
Sitkah 31:833fc481b002 575 else if (COLOR_NOIR.Touched()){
Sitkah 31:833fc481b002 576 while(COLOR_NOIR.Touched());
Sitkah 31:833fc481b002 577 COLOR_NOIR.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 578 msgTx.data[color]=2;
Sitkah 31:833fc481b002 579 color++;
Sitkah 31:833fc481b002 580 }
Sitkah 31:833fc481b002 581 else if (COLOR_VERT.Touched()){
Sitkah 31:833fc481b002 582 while(COLOR_VERT.Touched());
Sitkah 31:833fc481b002 583 COLOR_VERT.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 584
Sitkah 31:833fc481b002 585 msgTx.data[color]=3;
Sitkah 31:833fc481b002 586 color++;
Sitkah 31:833fc481b002 587 }
Sitkah 31:833fc481b002 588 else if (COLOR_JAUNE.Touched()){
Sitkah 31:833fc481b002 589 while(COLOR_JAUNE.Touched());
Sitkah 31:833fc481b002 590 COLOR_JAUNE.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 591 msgTx.data[color]=4;
Sitkah 31:833fc481b002 592 color++;
Sitkah 31:833fc481b002 593 }
Sitkah 31:833fc481b002 594 else if (COLOR_BLEU.Touched()){
Sitkah 31:833fc481b002 595 while(COLOR_BLEU.Touched());
Sitkah 31:833fc481b002 596 COLOR_ORANGE.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 597 msgTx.data[color]=5;
Sitkah 31:833fc481b002 598 color++;
Sitkah 31:833fc481b002 599 }
Sitkah 31:833fc481b002 600 }
Sitkah 31:833fc481b002 601 break;
Sitkah 31:833fc481b002 602
Sitkah 31:833fc481b002 603 case 1:
Sitkah 31:833fc481b002 604 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 605 lcd.SetTextColor(NOIR);
Sitkah 31:833fc481b002 606 lcd.DisplayStringAt(100, LINE(4), (uint8_t *)"COULEUR 2", LEFT_MODE);
Sitkah 31:833fc481b002 607 if(COLOR_ORANGE.Touched()){
Sitkah 31:833fc481b002 608 while(COLOR_ORANGE.Touched());
Sitkah 31:833fc481b002 609 COLOR_ORANGE.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 610 msgTx.data[color]=1;
Sitkah 31:833fc481b002 611 color++;
Sitkah 31:833fc481b002 612 }
Sitkah 31:833fc481b002 613 else if (COLOR_NOIR.Touched()){
Sitkah 31:833fc481b002 614 while(COLOR_NOIR.Touched());
Sitkah 31:833fc481b002 615 COLOR_NOIR.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 616 msgTx.data[color]=2;
Sitkah 31:833fc481b002 617 color++;
Sitkah 31:833fc481b002 618 }
Sitkah 31:833fc481b002 619 else if (COLOR_VERT.Touched()){
Sitkah 31:833fc481b002 620 while(COLOR_VERT.Touched());
Sitkah 31:833fc481b002 621 COLOR_VERT.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 622
Sitkah 31:833fc481b002 623 msgTx.data[color]=3;
Sitkah 31:833fc481b002 624 color++;
Sitkah 31:833fc481b002 625 }
Sitkah 31:833fc481b002 626 else if (COLOR_JAUNE.Touched()){
Sitkah 31:833fc481b002 627 while(COLOR_JAUNE.Touched());
Sitkah 31:833fc481b002 628 COLOR_JAUNE.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 629 msgTx.data[color]=4;
Sitkah 31:833fc481b002 630 color++;
Sitkah 31:833fc481b002 631 }
Sitkah 31:833fc481b002 632 else if (COLOR_BLEU.Touched()){
Sitkah 31:833fc481b002 633 while(COLOR_BLEU.Touched());
Sitkah 31:833fc481b002 634 COLOR_ORANGE.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 635 msgTx.data[color]=5;
Sitkah 31:833fc481b002 636 color++;
Sitkah 31:833fc481b002 637 }
Sitkah 31:833fc481b002 638 break;
Sitkah 31:833fc481b002 639
Sitkah 31:833fc481b002 640 case 2:
Sitkah 31:833fc481b002 641 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 642 lcd.SetTextColor(NOIR);
Sitkah 31:833fc481b002 643 lcd.DisplayStringAt(100, LINE(4), (uint8_t *)"COULEUR 3", LEFT_MODE);
Sitkah 31:833fc481b002 644 if(COLOR_ORANGE.Touched()){
Sitkah 31:833fc481b002 645 while(COLOR_ORANGE.Touched());
Sitkah 31:833fc481b002 646 COLOR_ORANGE.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 647 msgTx.data[color]=1;
Sitkah 31:833fc481b002 648 color++;
Sitkah 31:833fc481b002 649 }
Sitkah 31:833fc481b002 650 else if (COLOR_NOIR.Touched()){
Sitkah 31:833fc481b002 651 while(COLOR_NOIR.Touched());
Sitkah 31:833fc481b002 652 COLOR_NOIR.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 653 msgTx.data[color]=2;
Sitkah 31:833fc481b002 654 color++;
Sitkah 31:833fc481b002 655 }
Sitkah 31:833fc481b002 656 else if (COLOR_VERT.Touched()){
Sitkah 31:833fc481b002 657 while(COLOR_VERT.Touched());
Sitkah 31:833fc481b002 658 COLOR_VERT.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 659
Sitkah 31:833fc481b002 660 msgTx.data[color]=3;
Sitkah 31:833fc481b002 661 color++;
Sitkah 31:833fc481b002 662 }
Sitkah 31:833fc481b002 663 else if (COLOR_JAUNE.Touched()){
Sitkah 31:833fc481b002 664 while(COLOR_JAUNE.Touched());
Sitkah 31:833fc481b002 665 COLOR_JAUNE.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 666 msgTx.data[color]=4;
Sitkah 31:833fc481b002 667 color++;
Sitkah 31:833fc481b002 668 }
Sitkah 31:833fc481b002 669 else if (COLOR_BLEU.Touched()){
Sitkah 31:833fc481b002 670 while(COLOR_BLEU.Touched());
Sitkah 31:833fc481b002 671 COLOR_ORANGE.Draw(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 672 msgTx.data[color]=5;
Sitkah 31:833fc481b002 673 color++;
Sitkah 31:833fc481b002 674 }
Sitkah 31:833fc481b002 675 break;
Sitkah 31:833fc481b002 676 case 3:
Sitkah 31:833fc481b002 677 lcd.Clear(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 678 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 679 lcd.SetTextColor(NOIR);
Sitkah 31:833fc481b002 680
Sitkah 31:833fc481b002 681 lcd.DisplayStringAt(0, LINE(4), (uint8_t *)"Immeuble en construction", LEFT_MODE);
Sitkah 31:833fc481b002 682 RETOUR.Draw(ROUGE,0);
Sitkah 31:833fc481b002 683 can2.write(msgTx);
Sitkah 31:833fc481b002 684 color++;
Sitkah 31:833fc481b002 685 break;
Sitkah 31:833fc481b002 686
Sitkah 31:833fc481b002 687 case 4:
Sitkah 31:833fc481b002 688 if(RETOUR.Touched()){
Sitkah 31:833fc481b002 689 while(RETOUR.Touched());
Sitkah 31:833fc481b002 690 etat=DEMO;
Sitkah 31:833fc481b002 691 }
Sitkah 31:833fc481b002 692 break;
Sitkah 29:41e02746041d 693 }
Sitkah 31:833fc481b002 694 if(RETOUR.Touched()){
Sitkah 31:833fc481b002 695 while(RETOUR.Touched());
Sitkah 30:a1e37af4bbde 696 etat=DEMO;
Sitkah 30:a1e37af4bbde 697 }
Sitkah 31:833fc481b002 698 }
Sitkah 31:833fc481b002 699 break;
Sitkah 31:833fc481b002 700
Sitkah 31:833fc481b002 701
Sitkah 31:833fc481b002 702
Sitkah 31:833fc481b002 703
Sitkah 31:833fc481b002 704
Sitkah 31:833fc481b002 705 case TEST_SERVO:
Sitkah 31:833fc481b002 706 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 707 lcd.DisplayStringAt(20, LINE(2), (uint8_t *)"DEMONSTRATION COURS", LEFT_MODE);
Sitkah 31:833fc481b002 708 ABAISSE_BLOC.Draw(VERT, 0);
Sitkah 31:833fc481b002 709 RELEVE_BLOC.Draw(VERT, 0);
Sitkah 31:833fc481b002 710 BRAS_ABEILLE_ON.Draw(VERT, 0);
Sitkah 31:833fc481b002 711 BRAS_ABEILLE_OFF.Draw(VERT, 0);
Sitkah 31:833fc481b002 712 INTERRUPTEUR_ON.Draw(VERT, 0);
Sitkah 31:833fc481b002 713 INTERRUPTEUR_OFF.Draw(VERT, 0);
Sitkah 31:833fc481b002 714 RETOUR.Draw(0xFFFF0000,0);
Sitkah 31:833fc481b002 715 while(etat==TEST_SERVO){
Sitkah 31:833fc481b002 716 if(RETOUR.Touched()){
Sitkah 31:833fc481b002 717 while (RETOUR.Touched());
Sitkah 31:833fc481b002 718 etat=DEMO;
Sitkah 31:833fc481b002 719 }
Sitkah 31:833fc481b002 720 else if(ABAISSE_BLOC.Touched()){
Sitkah 31:833fc481b002 721 while (ABAISSE_BLOC.Touched());
Sitkah 31:833fc481b002 722 SendRawId(BAISSER_ATTRAPE_BLOC);
Sitkah 31:833fc481b002 723 break;
Sitkah 31:833fc481b002 724 }
Sitkah 31:833fc481b002 725 else if(RELEVE_BLOC.Touched()){
Sitkah 31:833fc481b002 726 while (RELEVE_BLOC.Touched());
Sitkah 31:833fc481b002 727 SendRawId(RELEVER_ATTRAPE_BLOC);
Sitkah 31:833fc481b002 728 break;
Sitkah 31:833fc481b002 729 }
Sitkah 31:833fc481b002 730 else if(BRAS_ABEILLE_ON.Touched()){
Sitkah 31:833fc481b002 731 while (BRAS_ABEILLE_ON.Touched());
Sitkah 31:833fc481b002 732 SendRawId(BRAS_ABEILLE_UP);
Sitkah 31:833fc481b002 733 break;
Sitkah 31:833fc481b002 734
Sitkah 31:833fc481b002 735 }
Sitkah 31:833fc481b002 736 else if(BRAS_ABEILLE_OFF.Touched()){
Sitkah 31:833fc481b002 737 while (BRAS_ABEILLE_OFF.Touched());
Sitkah 31:833fc481b002 738 SendRawId(BRAS_ABEILLE_DOWN);
Sitkah 31:833fc481b002 739 break;
Sitkah 31:833fc481b002 740 }
Sitkah 31:833fc481b002 741 else if(INTERRUPTEUR_ON.Touched()){
Sitkah 31:833fc481b002 742 while (INTERRUPTEUR_ON.Touched());
Sitkah 31:833fc481b002 743 SendRawId(ALLUMER_PANNEAU_UP);
Sitkah 31:833fc481b002 744 break;
Sitkah 31:833fc481b002 745 }
Sitkah 31:833fc481b002 746 else if(INTERRUPTEUR_OFF.Touched()){
Sitkah 31:833fc481b002 747 while (INTERRUPTEUR_OFF.Touched());
Sitkah 31:833fc481b002 748 SendRawId(ALLUMER_PANNEAU_DOWN);
Sitkah 31:833fc481b002 749 break;
Sitkah 31:833fc481b002 750 }
Sitkah 31:833fc481b002 751 }
Sitkah 31:833fc481b002 752 break;
Sitkah 31:833fc481b002 753
Sitkah 31:833fc481b002 754 case TEST_TIR:
Sitkah 31:833fc481b002 755 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 756 lcd.DisplayStringAt(20, LINE(2), (uint8_t *)"DEMONSTRATION COURS", LEFT_MODE);
Sitkah 31:833fc481b002 757 TIR_CHATEAU.Draw(VERT, 0);
Sitkah 31:833fc481b002 758 EPURATION.Draw(VERT, 0);
Sitkah 31:833fc481b002 759 LANCEUR_ON.Draw(VERT, 0);
Sitkah 31:833fc481b002 760 LANCEUR_OFF.Draw(VERT, 0);
Sitkah 31:833fc481b002 761 RETOUR.Draw(ROUGE, 0);
Sitkah 31:833fc481b002 762 while(etat==TEST_TIR){
Sitkah 31:833fc481b002 763 if(TIR_CHATEAU.Touched()){
Sitkah 31:833fc481b002 764 while (TIR_CHATEAU.Touched());
Sitkah 31:833fc481b002 765 SendRawId(INCLINAISON_CHATEAU);
Sitkah 31:833fc481b002 766 break;
Sitkah 31:833fc481b002 767 }
Sitkah 31:833fc481b002 768 else if (EPURATION.Touched()){
Sitkah 31:833fc481b002 769 while (EPURATION.Touched());
Sitkah 31:833fc481b002 770 SendRawId(INCLINAISON_EPURATION);
Sitkah 31:833fc481b002 771 break;
Sitkah 31:833fc481b002 772 }
Sitkah 31:833fc481b002 773 else if(LANCEUR_ON.Touched()){
Sitkah 31:833fc481b002 774 while (LANCEUR_ON.Touched());
Sitkah 36:6dd30780bd8e 775 CANMessage msgTx=CANMessage();
Sitkah 36:6dd30780bd8e 776 msgTx.format=CANStandard;
Sitkah 36:6dd30780bd8e 777 msgTx.type=CANData;
Sitkah 36:6dd30780bd8e 778 msgTx.id=LANCEMENT_MOTEUR_TIR_ON;
Sitkah 36:6dd30780bd8e 779
Sitkah 36:6dd30780bd8e 780 msgTx.len=1;
Sitkah 36:6dd30780bd8e 781 msgTx.data[0]=0;
Sitkah 36:6dd30780bd8e 782 can2.write(msgTx);
Sitkah 31:833fc481b002 783 break;
Sitkah 31:833fc481b002 784 }
Sitkah 31:833fc481b002 785 else if(LANCEUR_OFF.Touched()){
Sitkah 31:833fc481b002 786 while (LANCEUR_OFF.Touched());
Sitkah 31:833fc481b002 787 SendRawId(LANCEMENT_MOTEUR_TIR_OFF);
Sitkah 31:833fc481b002 788 break;
Sitkah 31:833fc481b002 789 }
Sitkah 31:833fc481b002 790 else if (RETOUR.Touched()){
Sitkah 31:833fc481b002 791 while (RETOUR.Touched());
Sitkah 31:833fc481b002 792 etat=DEMO;
Sitkah 31:833fc481b002 793
Sitkah 31:833fc481b002 794 }
Sitkah 31:833fc481b002 795 }
Sitkah 31:833fc481b002 796 break;
Sitkah 30:a1e37af4bbde 797
Sitkah 30:a1e37af4bbde 798
Sitkah 31:833fc481b002 799
Sitkah 31:833fc481b002 800 case TEST_TELEMETRE:
Sitkah 31:833fc481b002 801 ModeDemo=1;
Sitkah 31:833fc481b002 802 lcd.Clear(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 803 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 804 lcd.DisplayStringAt(20, LINE(2), (uint8_t *)"DEMONSTRATION COURS", LEFT_MODE);
Sitkah 31:833fc481b002 805 RETOUR.Draw(0xFFFF0000, 0);
Sitkah 31:833fc481b002 806 while(etat==TEST_TELEMETRE){
Sitkah 31:833fc481b002 807 SendRawId(DATA_RECALAGE);
Sitkah 31:833fc481b002 808 wait(0.1);
Sitkah 31:833fc481b002 809 canProcessRx();
Sitkah 31:833fc481b002 810 if(RETOUR.Touched()){
Sitkah 31:833fc481b002 811 while( RETOUR.Touched());
Sitkah 31:833fc481b002 812 etat=DEMO;
Sitkah 32:1c9ab15c740e 813 lcd.Clear(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 814 }
Sitkah 29:41e02746041d 815 }
Sitkah 29:41e02746041d 816 break;
Sitkah 31:833fc481b002 817
Sitkah 31:833fc481b002 818
Sitkah 29:41e02746041d 819 case SELECT_SIDE :
Sitkah 29:41e02746041d 820 lcd.Clear(LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 821 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 822 lcd.SetTextColor(LCD_COLOR_BLACK);
Sitkah 29:41e02746041d 823
Sitkah 29:41e02746041d 824 lcd.DisplayStringAt(70, LINE(0), (uint8_t *)"Choisir le cote", LEFT_MODE);
Sitkah 34:6aa4b46b102e 825 COTE_VERT.Draw(VERT, 0);
Sitkah 34:6aa4b46b102e 826 COTE_ORANGE.Draw(ORANGE, 0);
Sitkah 29:41e02746041d 827 RETOUR.Draw(LCD_COLOR_RED, 0);
Sitkah 29:41e02746041d 828
Sitkah 29:41e02746041d 829
Sitkah 29:41e02746041d 830 while (etat == SELECT_SIDE)
Sitkah 29:41e02746041d 831 {
Sitkah 29:41e02746041d 832 canProcessRx();
Sitkah 34:6aa4b46b102e 833 if(COTE_VERT.Touched())
Sitkah 29:41e02746041d 834 {
Sitkah 29:41e02746041d 835 Cote = 0x0;
Sitkah 29:41e02746041d 836 InversStrat = Cote;
Sitkah 29:41e02746041d 837 etat = TACTIQUE;
Sitkah 32:1c9ab15c740e 838 CANMessage trame_Tx = CANMessage();
Sitkah 32:1c9ab15c740e 839 trame_Tx.len = 1;
Sitkah 32:1c9ab15c740e 840 trame_Tx.format = CANStandard;
Sitkah 32:1c9ab15c740e 841 trame_Tx.type = CANData;
Sitkah 30:a1e37af4bbde 842 trame_Tx.id=CHOICE_COLOR;
Sitkah 30:a1e37af4bbde 843 trame_Tx.data[0]=Cote;
Sitkah 30:a1e37af4bbde 844 can2.write(trame_Tx);
Sitkah 34:6aa4b46b102e 845 while(COTE_VERT.Touched());
Sitkah 30:a1e37af4bbde 846
Sitkah 29:41e02746041d 847 }
Sitkah 29:41e02746041d 848
Sitkah 34:6aa4b46b102e 849 if(COTE_ORANGE.Touched())
Sitkah 29:41e02746041d 850 {
Sitkah 29:41e02746041d 851 Cote = 0x1;
Sitkah 29:41e02746041d 852 InversStrat= Cote;
Sitkah 29:41e02746041d 853 etat = TACTIQUE;
Sitkah 32:1c9ab15c740e 854 CANMessage trame_Tx = CANMessage();
Sitkah 32:1c9ab15c740e 855 trame_Tx.len = 1;
Sitkah 32:1c9ab15c740e 856 trame_Tx.format = CANStandard;
Sitkah 32:1c9ab15c740e 857 trame_Tx.type = CANData;
Sitkah 30:a1e37af4bbde 858 trame_Tx.id=CHOICE_COLOR;
Sitkah 30:a1e37af4bbde 859 trame_Tx.data[0]=Cote;
Sitkah 30:a1e37af4bbde 860 can2.write(trame_Tx);
Sitkah 34:6aa4b46b102e 861 while(COTE_ORANGE.Touched());
Sitkah 29:41e02746041d 862 }
Sitkah 29:41e02746041d 863
Sitkah 29:41e02746041d 864 if(RETOUR.Touched())
Sitkah 29:41e02746041d 865 {
Sitkah 29:41e02746041d 866 etat = CHOIX;
Sitkah 29:41e02746041d 867 while(RETOUR.Touched());
Sitkah 29:41e02746041d 868 }
Sitkah 29:41e02746041d 869 }
Sitkah 29:41e02746041d 870
Sitkah 29:41e02746041d 871 break;
Sitkah 29:41e02746041d 872
Sitkah 29:41e02746041d 873 case TACTIQUE :
Sitkah 29:41e02746041d 874 if (Cote == 0){
Sitkah 34:6aa4b46b102e 875 lcd.Clear(VERT);
Sitkah 34:6aa4b46b102e 876 lcd.SetBackColor(VERT);
Sitkah 29:41e02746041d 877 }
Sitkah 29:41e02746041d 878 else if (Cote == 1){
Sitkah 38:76f886a1c8e6 879 lcd.Clear(ORANGE);
Sitkah 38:76f886a1c8e6 880 lcd.SetBackColor(ORANGE);
Sitkah 29:41e02746041d 881 }
Sitkah 29:41e02746041d 882 else {
Sitkah 38:76f886a1c8e6 883 lcd.Clear(BLEU);
Sitkah 38:76f886a1c8e6 884 lcd.SetBackColor(BLEU);
Sitkah 29:41e02746041d 885 }
Sitkah 29:41e02746041d 886
Sitkah 29:41e02746041d 887 lcd.SetTextColor(LCD_COLOR_BLACK);
Sitkah 29:41e02746041d 888
Sitkah 29:41e02746041d 889 lcd.DisplayStringAt(20, LINE(0), (uint8_t *)"Choisir une strategie", LEFT_MODE);
Sitkah 29:41e02746041d 890
Sitkah 29:41e02746041d 891 Strategie = Bouton_Strat(); // retourne valeur de Strategie si bouton strat renvoi -1 on reviens en arriere
Sitkah 29:41e02746041d 892 if (Strategie == -1)
Sitkah 29:41e02746041d 893 {
Sitkah 29:41e02746041d 894 etat = SELECT_SIDE;
Sitkah 29:41e02746041d 895 }
Sitkah 29:41e02746041d 896 else
Sitkah 29:41e02746041d 897 {
Sitkah 29:41e02746041d 898 etat = DETAILS;
Sitkah 29:41e02746041d 899 }
Sitkah 29:41e02746041d 900 wait(0.1);
Sitkah 29:41e02746041d 901 break;
Sitkah 29:41e02746041d 902
Sitkah 29:41e02746041d 903 case DETAILS :
Sitkah 29:41e02746041d 904 lcd.Clear(LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 905 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 906 lcd.SetTextColor(LCD_COLOR_BLACK);
Sitkah 29:41e02746041d 907 CHECK.Draw(VERT);
Sitkah 29:41e02746041d 908 RETOUR.Draw(LCD_COLOR_RED);
Sitkah 29:41e02746041d 909
Sitkah 29:41e02746041d 910 SelectionStrat(Strategie);
Sitkah 29:41e02746041d 911
Sitkah 29:41e02746041d 912 while (etat == DETAILS)
Sitkah 29:41e02746041d 913 {
Sitkah 29:41e02746041d 914 canProcessRx();
Sitkah 29:41e02746041d 915 if (CHECK.Touched())
Sitkah 29:41e02746041d 916 {
Sitkah 29:41e02746041d 917 if(gameEtat == ETAT_CONFIG) {
Sitkah 29:41e02746041d 918 gameEtat = ETAT_GAME_INIT;
Sitkah 29:41e02746041d 919 etat=LECTURE;
Sitkah 29:41e02746041d 920
Sitkah 29:41e02746041d 921 }
Sitkah 29:41e02746041d 922 while(CHECK.Touched());
Sitkah 29:41e02746041d 923 }
Sitkah 29:41e02746041d 924
Sitkah 29:41e02746041d 925 if(RETOUR.Touched())
Sitkah 29:41e02746041d 926 {
Sitkah 29:41e02746041d 927 etat = TACTIQUE;
Sitkah 29:41e02746041d 928 while(RETOUR.Touched());
Sitkah 29:41e02746041d 929 }
Sitkah 29:41e02746041d 930 }
Sitkah 29:41e02746041d 931 break;
Sitkah 29:41e02746041d 932
Sitkah 29:41e02746041d 933
Sitkah 29:41e02746041d 934 case LECTURE :
Sitkah 29:41e02746041d 935 break;
Sitkah 29:41e02746041d 936 case AFF_WAIT_JACK :
Sitkah 29:41e02746041d 937 lcd.Clear(BLANC);
Sitkah 29:41e02746041d 938 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 939 lcd.SetTextColor(LCD_COLOR_BLACK);
Sitkah 29:41e02746041d 940
Sitkah 29:41e02746041d 941 if (Cote == 0){
Sitkah 34:6aa4b46b102e 942 lcd.Clear(VERT);
Sitkah 34:6aa4b46b102e 943 lcd.SetBackColor(VERT);
Sitkah 29:41e02746041d 944 }
Sitkah 29:41e02746041d 945 else if (Cote == 1){
Sitkah 38:76f886a1c8e6 946 lcd.Clear(ORANGE);
Sitkah 38:76f886a1c8e6 947 lcd.SetBackColor(ORANGE);
Sitkah 29:41e02746041d 948 }
Sitkah 29:41e02746041d 949 else {
Sitkah 34:6aa4b46b102e 950 lcd.Clear(VERT);
Sitkah 34:6aa4b46b102e 951 lcd.SetBackColor(VERT);
Sitkah 29:41e02746041d 952 }
Sitkah 29:41e02746041d 953 canProcessRx();
Sitkah 29:41e02746041d 954 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)"En attente du Jack", CENTER_MODE);
Sitkah 29:41e02746041d 955 etat=WAIT_JACK;
Sitkah 29:41e02746041d 956 break;
Sitkah 29:41e02746041d 957
Sitkah 29:41e02746041d 958 case WAIT_JACK:
Sitkah 29:41e02746041d 959 break;
Sitkah 29:41e02746041d 960
Sitkah 29:41e02746041d 961 case COMPTEUR:
Sitkah 38:76f886a1c8e6 962 cptf=gameTimer.read();
Sitkah 29:41e02746041d 963 lcd.SetTextColor(LCD_COLOR_BLACK);
Sitkah 38:76f886a1c8e6 964 cpt=(int)cptf;
Sitkah 36:6dd30780bd8e 965 if(cpt != cpt1){
Sitkah 34:6aa4b46b102e 966 lcd.Clear(VERT);
Sitkah 38:76f886a1c8e6 967 // affichage_compteur(100-cpt);
Sitkah 38:76f886a1c8e6 968 affichage_compteur(SCORE_PR);
Sitkah 38:76f886a1c8e6 969 #ifdef ROBOT_BIG
Sitkah 38:76f886a1c8e6 970 affichage_var(SCORE_GR);
Sitkah 38:76f886a1c8e6 971 #else
Sitkah 38:76f886a1c8e6 972 affichage_var(SCORE_PR);
Sitkah 38:76f886a1c8e6 973 #endif
Sitkah 38:76f886a1c8e6 974 if(liaison_pr.paquet_en_attente()){
Sitkah 38:76f886a1c8e6 975 PaquetDomotique *paquet=liaison_pr.lire();
Sitkah 38:76f886a1c8e6 976 if(paquet->identifiant==PAQUET_IDENTIFIANT_AJOUTERSCORE){
Sitkah 38:76f886a1c8e6 977 SCORE_PR+=convertir_score(paquet);
Sitkah 38:76f886a1c8e6 978 }
Sitkah 38:76f886a1c8e6 979 delete paquet;
Sitkah 38:76f886a1c8e6 980 }
Sitkah 36:6dd30780bd8e 981 }
Sitkah 29:41e02746041d 982 cpt1=cpt;
Sitkah 29:41e02746041d 983 flag_timer=0;
Sitkah 29:41e02746041d 984
Sitkah 38:76f886a1c8e6 985 //affichage_debug(gameEtat);
Sitkah 34:6aa4b46b102e 986 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 38:76f886a1c8e6 987
Sitkah 29:41e02746041d 988 break;
Sitkah 29:41e02746041d 989
Sitkah 29:41e02746041d 990 case FIN :
Sitkah 29:41e02746041d 991 lcd.Clear (LCD_COLOR_WHITE);
Sitkah 29:41e02746041d 992 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 38:76f886a1c8e6 993 #ifdef ROBOT_BIG
Sitkah 38:76f886a1c8e6 994 affichage_compteur(SCORE_GR);
Sitkah 38:76f886a1c8e6 995 liaison_Tx.envoyer_short(PAQUET_IDENTIFIANT_FINMATCH,SCORE_GLOBAL);
Sitkah 38:76f886a1c8e6 996 #else
Sitkah 38:76f886a1c8e6 997 affichage_compteur(SCORE_PR);
Sitkah 38:76f886a1c8e6 998 #endif
Sitkah 29:41e02746041d 999 while(1); // force le redemarage du robot
Sitkah 29:41e02746041d 1000 //break;
Sitkah 29:41e02746041d 1001
Sitkah 29:41e02746041d 1002 }
Sitkah 29:41e02746041d 1003 }
Sitkah 29:41e02746041d 1004
Sitkah 29:41e02746041d 1005
Sitkah 29:41e02746041d 1006
Sitkah 29:41e02746041d 1007 /****************************************************************************************/
antbig 4:88431b537477 1008 /* FUNCTION NAME: automate_process */
antbig 4:88431b537477 1009 /* DESCRIPTION : Automate de gestion de la stratégie du robot */
antbig 4:88431b537477 1010 /****************************************************************************************/
Sitkah 29:41e02746041d 1011 void automate_process(void){
antbig 1:116040d14164 1012 static unsigned char AX12_enchainement = 0;
antbig 1:116040d14164 1013 static unsigned char MV_enchainement = 0;
antbig 0:ad97421fb1fb 1014 signed char localData1 = 0;
antbig 0:ad97421fb1fb 1015 signed short localData2 = 0;
antbig 0:ad97421fb1fb 1016 unsigned short localData3 = 0;
ClementBreteau 14:c8fc06c4887f 1017 //signed short localData4 = 0;
antbig 1:116040d14164 1018 unsigned char localData5 = 0;
antbig 0:ad97421fb1fb 1019
Sitkah 34:6aa4b46b102e 1020 if(gameTimer.read_ms() >= 99000) {//Fin du match (On autorise 2s pour déposer des éléments
antbig 0:ad97421fb1fb 1021 gameTimer.stop();
antbig 0:ad97421fb1fb 1022 gameTimer.reset();
antbig 0:ad97421fb1fb 1023 gameEtat = ETAT_END;//Fin du temps
Sitkah 29:41e02746041d 1024 etat=FIN;
antbig 0:ad97421fb1fb 1025 }
antbig 0:ad97421fb1fb 1026
antbig 0:ad97421fb1fb 1027 if(lastEtat != gameEtat || debugetatTimer.read_ms() >= 1000) {
antbig 0:ad97421fb1fb 1028 lastEtat = gameEtat;
antbig 0:ad97421fb1fb 1029 debugetatTimer.reset();
antbig 11:ed13a480ddca 1030 sendStratEtat((unsigned char)gameEtat, (unsigned char)actual_instruction);
antbig 0:ad97421fb1fb 1031 }
antbig 0:ad97421fb1fb 1032
antbig 0:ad97421fb1fb 1033 switch(gameEtat)
antbig 0:ad97421fb1fb 1034 {
Sitkah 30:a1e37af4bbde 1035
Sitkah 29:41e02746041d 1036 case ETAT_CHECK_CARTES:
antbig 0:ad97421fb1fb 1037 /*
antbig 0:ad97421fb1fb 1038 Il faut faire une boucle pour verifier toutes les cartes les une apres les autres
antbig 0:ad97421fb1fb 1039 */
antbig 0:ad97421fb1fb 1040 waitingAckFrom = id_alive[checkCurrent];//On indique que l'on attend un ack de la carte IHM
antbig 11:ed13a480ddca 1041 SendRawId(id_check[checkCurrent]);//On demande à la carte d'indiquer ça présence
antbig 0:ad97421fb1fb 1042
antbig 0:ad97421fb1fb 1043 screenChecktry++;//On incrèment le conteur de tentative de 1
antbig 0:ad97421fb1fb 1044 cartesCheker.reset();//On reset le timeOut
antbig 0:ad97421fb1fb 1045 cartesCheker.start();//On lance le timer pour le timeout
antbig 0:ad97421fb1fb 1046 gameEtat = ETAT_CHECK_CARTES_WAIT_ACK;
Sitkah 29:41e02746041d 1047 break;
ClementBreteau 14:c8fc06c4887f 1048
antbig 0:ad97421fb1fb 1049 case ETAT_CHECK_CARTES_WAIT_ACK:
antbig 0:ad97421fb1fb 1050 /*
antbig 0:ad97421fb1fb 1051 On attend l'ack de la carte en cours de vérification
antbig 0:ad97421fb1fb 1052 */
antbig 0:ad97421fb1fb 1053 //printf("cartesCheker = %d waitingAckFrom = %d\n",cartesCheker.read_ms(), waitingAckFrom);
antbig 0:ad97421fb1fb 1054 if(waitingAckFrom == 0) {//C'est bon la carte est en ligne
antbig 0:ad97421fb1fb 1055 cartesCheker.stop();
antbig 0:ad97421fb1fb 1056 screenChecktry = 0;
antbig 0:ad97421fb1fb 1057 countAliveCard++;
antbig 11:ed13a480ddca 1058 checkCurrent++;
antbig 0:ad97421fb1fb 1059 if(checkCurrent >= NOMBRE_CARTES) {
Sitkah 29:41e02746041d 1060 printf("all card check, missing %d cards\n",(NOMBRE_CARTES-countAliveCard));
antbig 0:ad97421fb1fb 1061 if(countAliveCard >= NOMBRE_CARTES) {
antbig 0:ad97421fb1fb 1062 gameEtat = ETAT_CONFIG;
Sitkah 38:76f886a1c8e6 1063 SendRawId(ECRAN_ALL_CHECK);
Sitkah 29:41e02746041d 1064 flag=1;
Sitkah 38:76f886a1c8e6 1065
Sitkah 30:a1e37af4bbde 1066 //tactile_printf("Selection couleur et strategie");
Sitkah 29:41e02746041d 1067 }
Sitkah 29:41e02746041d 1068 else {
antbig 0:ad97421fb1fb 1069 gameEtat = ETAT_WAIT_FORCE;//Passage en attente de forçage du lancement
antbig 0:ad97421fb1fb 1070 waitingAckFrom = ECRAN_ALL_CHECK;
antbig 0:ad97421fb1fb 1071 }
Sitkah 29:41e02746041d 1072 }
Sitkah 29:41e02746041d 1073 else
antbig 0:ad97421fb1fb 1074 gameEtat = ETAT_CHECK_CARTES;
Sitkah 29:41e02746041d 1075 }
Sitkah 29:41e02746041d 1076 else if(cartesCheker.read_ms () > 100) {
antbig 0:ad97421fb1fb 1077 cartesCheker.stop();
antbig 0:ad97421fb1fb 1078 if(screenChecktry >=3) {
antbig 12:14729d584500 1079 //printf("missing card %d\n",id_check[checkCurrent]);
antbig 0:ad97421fb1fb 1080 screenChecktry = 0;
antbig 11:ed13a480ddca 1081 checkCurrent++;
antbig 12:14729d584500 1082
Sitkah 29:41e02746041d 1083 if(checkCurrent >= NOMBRE_CARTES){
Sitkah 29:41e02746041d 1084 if(countAliveCard == NOMBRE_CARTES){
antbig 0:ad97421fb1fb 1085 gameEtat = ETAT_CONFIG;
Sitkah 29:41e02746041d 1086 flag=1;
Sitkah 29:41e02746041d 1087 }
Sitkah 29:41e02746041d 1088 else{
Sitkah 29:41e02746041d 1089 gameEtat = ETAT_WAIT_FORCE;
antbig 0:ad97421fb1fb 1090 waitingAckFrom = ECRAN_ALL_CHECK;
antbig 0:ad97421fb1fb 1091 }
Sitkah 29:41e02746041d 1092 }
Sitkah 29:41e02746041d 1093 else
antbig 0:ad97421fb1fb 1094 gameEtat = ETAT_CHECK_CARTES;
Sitkah 29:41e02746041d 1095
Sitkah 29:41e02746041d 1096 }
Sitkah 29:41e02746041d 1097 else
antbig 0:ad97421fb1fb 1098 gameEtat = ETAT_CHECK_CARTES;
Sitkah 29:41e02746041d 1099
antbig 0:ad97421fb1fb 1100 }
Sitkah 29:41e02746041d 1101 break;
antbig 0:ad97421fb1fb 1102 case ETAT_WAIT_FORCE:
antbig 0:ad97421fb1fb 1103 /*
antbig 0:ad97421fb1fb 1104 Attente du forçage de la part de la carte IHM
antbig 0:ad97421fb1fb 1105 */
antbig 0:ad97421fb1fb 1106 if(waitingAckFrom == 0) {
antbig 0:ad97421fb1fb 1107 gameEtat = ETAT_CONFIG;
antbig 0:ad97421fb1fb 1108 }
Sitkah 29:41e02746041d 1109 break;
antbig 0:ad97421fb1fb 1110 case ETAT_CONFIG:
antbig 0:ad97421fb1fb 1111 /*
antbig 0:ad97421fb1fb 1112 Attente de l'odre de choix de mode,
antbig 0:ad97421fb1fb 1113 Il est possible de modifier la couleur et l'id de la stratégie
antbig 0:ad97421fb1fb 1114 Il est aussi possible d'envoyer les ordres de debug
antbig 0:ad97421fb1fb 1115 */
ClementBreteau 14:c8fc06c4887f 1116 modeTelemetre = 0;
Sitkah 29:41e02746041d 1117 break;
antbig 1:116040d14164 1118 case ETAT_GAME_INIT:
antbig 0:ad97421fb1fb 1119 //On charge la liste des instructions
Sitkah 29:41e02746041d 1120
Sitkah 29:41e02746041d 1121 loadAllInstruction(Strategie);//Mise en cache de toute les instructions
Sitkah 29:41e02746041d 1122 led3=1;
ClementBreteau 14:c8fc06c4887f 1123
Sitkah 37:fca332b64b42 1124 SendRawId(GLOBAL_START);
Sitkah 37:fca332b64b42 1125
antbig 0:ad97421fb1fb 1126 gameEtat = ETAT_GAME_WAIT_FOR_JACK;
Sitkah 31:833fc481b002 1127 if (etat == TEST_TELEMETRE|| etat ==TEST_CAPTEURS || etat == TEST_SERVO || etat ==TEST_TIR || etat == DEMO_IMMEUBLE)
Sitkah 29:41e02746041d 1128 {
Sitkah 29:41e02746041d 1129 SendRawId(DEBUG_FAKE_JAKE);
Sitkah 29:41e02746041d 1130 }
Sitkah 29:41e02746041d 1131 else
Sitkah 29:41e02746041d 1132 {
Sitkah 29:41e02746041d 1133 etat = AFF_WAIT_JACK;
Sitkah 29:41e02746041d 1134 }
Sitkah 30:a1e37af4bbde 1135 //tactile_printf("Attente du JACK.");
antbig 12:14729d584500 1136 setAsservissementEtat(1);//On réactive l'asservissement
antbig 12:14729d584500 1137 jack.mode(PullDown); // désactivation de la résistance interne du jack
antbig 8:0edc7dfb7f7e 1138 jack.fall(&jack_ISR); // création de l'interrupt attachée au changement d'état (front descendant) sur le jack
antbig 12:14729d584500 1139
clementlignie 22:a466d08ac42b 1140 localData2 = POSITION_DEBUT_T;
clementlignie 22:a466d08ac42b 1141 localData3 = POSITION_DEBUT_Y;
clementlignie 22:a466d08ac42b 1142 if(InversStrat == 1) {
clementlignie 22:a466d08ac42b 1143 localData2 = -localData2;//Inversion theta
clementlignie 22:a466d08ac42b 1144 localData3 = 3000 - POSITION_DEBUT_Y;//Inversion du Y
clementlignie 22:a466d08ac42b 1145 }
Sitkah 38:76f886a1c8e6 1146 SetOdometrie(ODOMETRIE_SMALL_POSITION, POSITION_DEBUT_X,1800,localData2);
Sitkah 38:76f886a1c8e6 1147
Sitkah 38:76f886a1c8e6 1148 instruction = strat_instructions[actual_instruction];
Sitkah 38:76f886a1c8e6 1149 //On effectue le traitement de l'instruction
Sitkah 38:76f886a1c8e6 1150
antbig 0:ad97421fb1fb 1151 break;
antbig 0:ad97421fb1fb 1152 case ETAT_GAME_WAIT_FOR_JACK:
Sitkah 38:76f886a1c8e6 1153 if(instruction.order==POSITION_DEBUT){
Sitkah 38:76f886a1c8e6 1154 switch(etat_pos){
Sitkah 38:76f886a1c8e6 1155 case RECALAGE_1:
Sitkah 38:76f886a1c8e6 1156 waitingAckID = ASSERVISSEMENT_RECALAGE;
Sitkah 38:76f886a1c8e6 1157 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
Sitkah 38:76f886a1c8e6 1158 #ifdef ROBOT_SMALL
Sitkah 38:76f886a1c8e6 1159 GoStraight(3000, 1,MOITIEE_ROBOT-5, 0); //on se recale contre le mur donc il faut donner la valeur du centre du robot
Sitkah 38:76f886a1c8e6 1160 #else
Sitkah 38:76f886a1c8e6 1161 GoStraight(-3000, 1,MOITIEE_ROBOT, 0);
Sitkah 38:76f886a1c8e6 1162 #endif
Sitkah 38:76f886a1c8e6 1163 while(waitingAckID !=0 && waitingAckFrom !=0)
Sitkah 38:76f886a1c8e6 1164 canProcessRx();
Sitkah 38:76f886a1c8e6 1165 waitingAckID_FIN=ASSERVISSEMENT_RECALAGE;
Sitkah 38:76f886a1c8e6 1166 waitingAckFrom_FIN= INSTRUCTION_END_MOTEUR;
Sitkah 38:76f886a1c8e6 1167 while(waitingAckID_FIN!=0 && waitingAckFrom_FIN !=0)
Sitkah 38:76f886a1c8e6 1168 canProcessRx();
Sitkah 38:76f886a1c8e6 1169 etat_pos=RECULER_1;
Sitkah 38:76f886a1c8e6 1170 break;
Sitkah 38:76f886a1c8e6 1171
Sitkah 38:76f886a1c8e6 1172 case RECULER_1:
Sitkah 38:76f886a1c8e6 1173 waitingAckID = ASSERVISSEMENT_RECALAGE;
Sitkah 38:76f886a1c8e6 1174 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
Sitkah 38:76f886a1c8e6 1175 #ifdef ROBOT_SMALL
Sitkah 38:76f886a1c8e6 1176 GoStraight(-450, 0, 0, 0);
Sitkah 38:76f886a1c8e6 1177 #else
Sitkah 38:76f886a1c8e6 1178 GoStraight(75, 0, 0, 0);
Sitkah 38:76f886a1c8e6 1179 #endif
Sitkah 38:76f886a1c8e6 1180 while(waitingAckID !=0 && waitingAckFrom !=0)
Sitkah 38:76f886a1c8e6 1181 canProcessRx();
Sitkah 38:76f886a1c8e6 1182 waitingAckID_FIN=ASSERVISSEMENT_RECALAGE;
Sitkah 38:76f886a1c8e6 1183 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
Sitkah 38:76f886a1c8e6 1184 while(waitingAckID_FIN!=0 && waitingAckFrom_FIN !=0)
Sitkah 38:76f886a1c8e6 1185 canProcessRx();
Sitkah 38:76f886a1c8e6 1186 etat_pos=TOURNER;
Sitkah 38:76f886a1c8e6 1187 break;
Sitkah 38:76f886a1c8e6 1188
Sitkah 38:76f886a1c8e6 1189 case TOURNER:
Sitkah 38:76f886a1c8e6 1190 waitingAckID = ASSERVISSEMENT_ROTATION;
Sitkah 38:76f886a1c8e6 1191 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
Sitkah 38:76f886a1c8e6 1192 if(Cote==0){
Sitkah 38:76f886a1c8e6 1193 localData2 = 900;
Sitkah 38:76f886a1c8e6 1194 }
Sitkah 38:76f886a1c8e6 1195 else{
Sitkah 38:76f886a1c8e6 1196 localData2=-900;
Sitkah 38:76f886a1c8e6 1197 }
Sitkah 38:76f886a1c8e6 1198 Rotate(localData2);
Sitkah 38:76f886a1c8e6 1199 while(waitingAckID !=0 && waitingAckFrom !=0)
Sitkah 38:76f886a1c8e6 1200 canProcessRx();
Sitkah 38:76f886a1c8e6 1201 waitingAckID_FIN=ASSERVISSEMENT_ROTATION;
Sitkah 38:76f886a1c8e6 1202 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
Sitkah 38:76f886a1c8e6 1203 while(waitingAckID_FIN!=0 && waitingAckFrom_FIN !=0)
Sitkah 38:76f886a1c8e6 1204 canProcessRx();
Sitkah 38:76f886a1c8e6 1205 etat_pos=RECALAGE_2;
Sitkah 38:76f886a1c8e6 1206 break;
Sitkah 38:76f886a1c8e6 1207
Sitkah 38:76f886a1c8e6 1208 case RECALAGE_2:
Sitkah 38:76f886a1c8e6 1209 waitingAckID = ASSERVISSEMENT_RECALAGE;
Sitkah 38:76f886a1c8e6 1210 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
Sitkah 38:76f886a1c8e6 1211 if(Cote==1)
Sitkah 38:76f886a1c8e6 1212 localData3=3000-MOITIEE_ROBOT;
Sitkah 38:76f886a1c8e6 1213 else
Sitkah 38:76f886a1c8e6 1214 localData3=MOITIEE_ROBOT;
Sitkah 38:76f886a1c8e6 1215 #ifdef ROBOT_SMALL
Sitkah 38:76f886a1c8e6 1216 GoStraight(3000, 2,localData3, 0); //on se recale contre le mur donc il faut donner la valeur du centre du robot
Sitkah 38:76f886a1c8e6 1217 #else
Sitkah 38:76f886a1c8e6 1218 GoStraight(-3000, 2,localData3, 0);
Sitkah 38:76f886a1c8e6 1219 #endif
Sitkah 38:76f886a1c8e6 1220 while(waitingAckID !=0 && waitingAckFrom !=0)
Sitkah 38:76f886a1c8e6 1221 canProcessRx();
Sitkah 38:76f886a1c8e6 1222 waitingAckID_FIN=ASSERVISSEMENT_RECALAGE;
Sitkah 38:76f886a1c8e6 1223 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
Sitkah 38:76f886a1c8e6 1224 while(waitingAckID_FIN!=0 && waitingAckFrom_FIN !=0)
Sitkah 38:76f886a1c8e6 1225 canProcessRx();
Sitkah 38:76f886a1c8e6 1226 etat_pos=RECULER_2;
Sitkah 38:76f886a1c8e6 1227 break;
Sitkah 38:76f886a1c8e6 1228
Sitkah 38:76f886a1c8e6 1229 case RECULER_2:
Sitkah 38:76f886a1c8e6 1230 waitingAckID = ASSERVISSEMENT_RECALAGE;
Sitkah 38:76f886a1c8e6 1231 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
Sitkah 38:76f886a1c8e6 1232 #ifdef ROBOT_SMALL
Sitkah 38:76f886a1c8e6 1233 GoStraight(-200, 0, 0, 0);
Sitkah 38:76f886a1c8e6 1234 #else
Sitkah 38:76f886a1c8e6 1235 GoStraight(200, 0, 0, 0);
Sitkah 38:76f886a1c8e6 1236 #endif
Sitkah 38:76f886a1c8e6 1237 while(waitingAckID !=0 && waitingAckFrom !=0)
Sitkah 38:76f886a1c8e6 1238 canProcessRx();
Sitkah 38:76f886a1c8e6 1239 waitingAckID_FIN=ASSERVISSEMENT_RECALAGE;
Sitkah 38:76f886a1c8e6 1240 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
Sitkah 38:76f886a1c8e6 1241 while(waitingAckID_FIN!=0 && waitingAckFrom_FIN !=0)
Sitkah 38:76f886a1c8e6 1242 canProcessRx();
Sitkah 38:76f886a1c8e6 1243 etat_pos=GOTOPOS;
Sitkah 38:76f886a1c8e6 1244 break;
Sitkah 38:76f886a1c8e6 1245
Sitkah 38:76f886a1c8e6 1246 case GOTOPOS:
Sitkah 38:76f886a1c8e6 1247 localData1 = -1;
Sitkah 38:76f886a1c8e6 1248
Sitkah 38:76f886a1c8e6 1249 if(InversStrat == 1 && ingnorInversionOnce == 0) {
Sitkah 38:76f886a1c8e6 1250 localData2 = -instruction.arg3;
Sitkah 38:76f886a1c8e6 1251 localData3 = 3000 - instruction.arg2;//Inversion du Y
Sitkah 38:76f886a1c8e6 1252 } else {
Sitkah 38:76f886a1c8e6 1253 localData3 = instruction.arg2;
Sitkah 38:76f886a1c8e6 1254 localData2 = instruction.arg3;
Sitkah 38:76f886a1c8e6 1255 }
Sitkah 38:76f886a1c8e6 1256
Sitkah 38:76f886a1c8e6 1257 GoToPosition(instruction.arg1,localData3,localData2,localData1);
Sitkah 38:76f886a1c8e6 1258 waitingAckID = ASSERVISSEMENT_XYT;
Sitkah 38:76f886a1c8e6 1259 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
Sitkah 38:76f886a1c8e6 1260
Sitkah 38:76f886a1c8e6 1261 while(waitingAckID !=0 && waitingAckFrom !=0)
Sitkah 38:76f886a1c8e6 1262 canProcessRx();
Sitkah 38:76f886a1c8e6 1263 waitingAckID_FIN=ASSERVISSEMENT_XYT;
Sitkah 38:76f886a1c8e6 1264 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
Sitkah 38:76f886a1c8e6 1265 while(waitingAckID_FIN!=0 && waitingAckFrom_FIN !=0)
Sitkah 38:76f886a1c8e6 1266 canProcessRx();
Sitkah 38:76f886a1c8e6 1267 etat_pos=FIN_POS;
Sitkah 38:76f886a1c8e6 1268 break;
Sitkah 38:76f886a1c8e6 1269 case FIN_POS:
Sitkah 38:76f886a1c8e6 1270 actual_instruction = instruction.nextLineOK;
Sitkah 38:76f886a1c8e6 1271 break;
Sitkah 38:76f886a1c8e6 1272 }
Sitkah 38:76f886a1c8e6 1273 }
Sitkah 38:76f886a1c8e6 1274
Sitkah 38:76f886a1c8e6 1275
antbig 1:116040d14164 1276 break;
antbig 1:116040d14164 1277 case ETAT_GAME_START:
Sitkah 29:41e02746041d 1278
antbig 1:116040d14164 1279 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
ClementBreteau 14:c8fc06c4887f 1280
ClementBreteau 14:c8fc06c4887f 1281 if (ModeDemo == 0){
Sitkah 34:6aa4b46b102e 1282 chronoEnd.attach(&chronometre_ISR,100);//On lance le chrono de 90s
ClementBreteau 14:c8fc06c4887f 1283 gameTimer.start();
ClementBreteau 14:c8fc06c4887f 1284 }
antbig 1:116040d14164 1285 gameTimer.reset();
antbig 12:14729d584500 1286 jack.fall(NULL);//On désactive l'interruption du jack
Sitkah 34:6aa4b46b102e 1287 //SendRawId(GLOBAL_START);
Sitkah 29:41e02746041d 1288 Jack=0; //à envoyer sur le CAN et en direct pour l'automate de l'ihm ou sur CANV
Sitkah 30:a1e37af4bbde 1289 //tactile_printf("Start");//Pas vraiment utile mais bon
antbig 0:ad97421fb1fb 1290 break;
antbig 0:ad97421fb1fb 1291 case ETAT_GAME_LOAD_NEXT_INSTRUCTION:
antbig 0:ad97421fb1fb 1292 /*
antbig 0:ad97421fb1fb 1293 Chargement de l'instruction suivante ou arret du robot si il n'y a plus d'instruction
antbig 0:ad97421fb1fb 1294 */
antbig 0:ad97421fb1fb 1295 //printf("load next instruction\n");
ClementBreteau 14:c8fc06c4887f 1296
antbig 0:ad97421fb1fb 1297 if(actual_instruction >= nb_instructions || actual_instruction == 255) {
antbig 0:ad97421fb1fb 1298 gameEtat = ETAT_END;
antbig 0:ad97421fb1fb 1299 //Il n'y a plus d'instruction, fin du jeu
antbig 0:ad97421fb1fb 1300 } else {
antbig 0:ad97421fb1fb 1301 instruction = strat_instructions[actual_instruction];
antbig 0:ad97421fb1fb 1302 //On effectue le traitement de l'instruction
antbig 0:ad97421fb1fb 1303 gameEtat = ETAT_GAME_PROCESS_INSTRUCTION;
antbig 0:ad97421fb1fb 1304 }
antbig 0:ad97421fb1fb 1305 screenChecktry = 0;
antbig 28:acd18776ed2d 1306 ingnorInversionOnce = 0;
antbig 0:ad97421fb1fb 1307 break;
antbig 0:ad97421fb1fb 1308 case ETAT_GAME_PROCESS_INSTRUCTION:
antbig 0:ad97421fb1fb 1309 /*
antbig 0:ad97421fb1fb 1310 Traitement de l'instruction, envoie de la trame CAN
antbig 0:ad97421fb1fb 1311 */
antbig 0:ad97421fb1fb 1312 //debug_Instruction(instruction);
Sitkah 38:76f886a1c8e6 1313 //affichage_debug(gameEtat);
ClementBreteau 25:f140c93a8666 1314 actionPrecedente = instruction.order;
antbig 0:ad97421fb1fb 1315 switch(instruction.order)
antbig 0:ad97421fb1fb 1316 {
antbig 12:14729d584500 1317 case MV_COURBURE://C'est un rayon de courbure
ClementBreteau 26:2f4fcc2354f3 1318 actionPrecedente = MV_COURBURE;
antbig 6:eddfa414fd11 1319 waitingAckID = ASSERVISSEMENT_COURBURE;
antbig 6:eddfa414fd11 1320 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
Sitkah 30:a1e37af4bbde 1321 if(instruction.nextActionType == ENCHAINEMENT){
antbig 6:eddfa414fd11 1322 MV_enchainement++;
antbig 6:eddfa414fd11 1323 localData5 = 1;
antbig 6:eddfa414fd11 1324 } else {
antbig 6:eddfa414fd11 1325 if(MV_enchainement > 0) {
antbig 6:eddfa414fd11 1326 localData5 = 2;
antbig 6:eddfa414fd11 1327 MV_enchainement = 0;
antbig 6:eddfa414fd11 1328 } else {
antbig 6:eddfa414fd11 1329 localData5 = 0;
antbig 6:eddfa414fd11 1330 }
antbig 0:ad97421fb1fb 1331 }
antbig 11:ed13a480ddca 1332 localData1 = ((instruction.direction == LEFT)?1:-1);
ClementBreteau 23:ab87d308eaf9 1333 localData2 = instruction.arg3;
antbig 28:acd18776ed2d 1334 if(InversStrat == 1 && ingnorInversionOnce == 0)
antbig 12:14729d584500 1335 {
antbig 12:14729d584500 1336 localData1 = -localData1;//Inversion de la direction
antbig 12:14729d584500 1337 }
ClementBreteau 25:f140c93a8666 1338 BendRadius(instruction.arg1, localData2, localData1, localData5);
ClementBreteau 18:cc5fec34ed9c 1339
antbig 28:acd18776ed2d 1340
antbig 28:acd18776ed2d 1341 target_theta_robot = localData2 - theta_robot;
antbig 28:acd18776ed2d 1342 /*
ClementBreteau 26:2f4fcc2354f3 1343 if(instruction.direction == LEFT){
antbig 28:acd18776ed2d 1344
ClementBreteau 26:2f4fcc2354f3 1345 }else{
antbig 28:acd18776ed2d 1346 target_theta_robot = theta_robot + localData2;
antbig 28:acd18776ed2d 1347 }*/
ClementBreteau 26:2f4fcc2354f3 1348
antbig 0:ad97421fb1fb 1349 break;
antbig 12:14729d584500 1350 case MV_LINE://Ligne droite
antbig 0:ad97421fb1fb 1351 waitingAckID = ASSERVISSEMENT_RECALAGE;
antbig 0:ad97421fb1fb 1352 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
antbig 0:ad97421fb1fb 1353 if(instruction.nextActionType == ENCHAINEMENT) {
antbig 1:116040d14164 1354 MV_enchainement++;
antbig 1:116040d14164 1355 localData5 = 1;
antbig 1:116040d14164 1356 } else {
antbig 12:14729d584500 1357 if(MV_enchainement > 0) {//Utilisé en cas d'enchainement,
antbig 1:116040d14164 1358 localData5 = 2;
antbig 1:116040d14164 1359 MV_enchainement = 0;
antbig 1:116040d14164 1360 } else {
antbig 1:116040d14164 1361 localData5 = 0;
antbig 1:116040d14164 1362 }
Sitkah 38:76f886a1c8e6 1363 }
antbig 1:116040d14164 1364 localData2 = (((instruction.direction == FORWARD)?1:-1)*instruction.arg1);
antbig 1:116040d14164 1365 GoStraight(localData2, 0, 0, localData5);
ClementBreteau 14:c8fc06c4887f 1366
ClementBreteau 26:2f4fcc2354f3 1367 target_x_robot = x_robot + localData2*cos((double)theta_robot*M_PI/1800);
ClementBreteau 26:2f4fcc2354f3 1368 target_y_robot = y_robot + localData2*sin((double)theta_robot*M_PI/1800);
ClementBreteau 25:f140c93a8666 1369 target_theta_robot = theta_robot;
ClementBreteau 25:f140c93a8666 1370
antbig 0:ad97421fb1fb 1371 break;
antbig 12:14729d584500 1372 case MV_TURN: //Rotation sur place
antbig 0:ad97421fb1fb 1373 if(instruction.direction == RELATIVE) {
antbig 0:ad97421fb1fb 1374 localData2 = instruction.arg3;
antbig 12:14729d584500 1375 } else {//C'est un rotation absolu, il faut la convertir en relative
antbig 12:14729d584500 1376 localData2 = instruction.arg3;
antbig 12:14729d584500 1377
antbig 12:14729d584500 1378 localData2 = (localData2 - theta_robot)%3600;
antbig 12:14729d584500 1379 if(localData2 > 1800) {
antbig 12:14729d584500 1380 localData2 = localData2-3600;
antbig 12:14729d584500 1381 }
antbig 12:14729d584500 1382
antbig 0:ad97421fb1fb 1383 }
antbig 28:acd18776ed2d 1384 if(InversStrat == 1 && ingnorInversionOnce == 0) {
clementlignie 22:a466d08ac42b 1385 localData2 = -localData2;
Sitkah 38:76f886a1c8e6 1386 }
antbig 0:ad97421fb1fb 1387 waitingAckID = ASSERVISSEMENT_ROTATION;
antbig 0:ad97421fb1fb 1388 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
Sitkah 34:6aa4b46b102e 1389 Rotate(localData2);
Sitkah 34:6aa4b46b102e 1390
antbig 28:acd18776ed2d 1391
antbig 0:ad97421fb1fb 1392 break;
antbig 0:ad97421fb1fb 1393 case MV_XYT:
antbig 0:ad97421fb1fb 1394 if(instruction.direction == BACKWARD) {
antbig 0:ad97421fb1fb 1395 localData1 = -1;
antbig 0:ad97421fb1fb 1396 } else {
antbig 0:ad97421fb1fb 1397 localData1 = 1;
antbig 0:ad97421fb1fb 1398 }
antbig 2:8d8e2cf798a3 1399
antbig 28:acd18776ed2d 1400 if(InversStrat == 1 && ingnorInversionOnce == 0) {
antbig 12:14729d584500 1401 localData2 = -instruction.arg3;
antbig 2:8d8e2cf798a3 1402 localData3 = 3000 - instruction.arg2;//Inversion du Y
antbig 2:8d8e2cf798a3 1403 } else {
antbig 2:8d8e2cf798a3 1404 localData3 = instruction.arg2;
antbig 12:14729d584500 1405 localData2 = instruction.arg3;
antbig 2:8d8e2cf798a3 1406 }
ClementBreteau 23:ab87d308eaf9 1407
antbig 12:14729d584500 1408 GoToPosition(instruction.arg1,localData3,localData2,localData1);
antbig 0:ad97421fb1fb 1409 waitingAckID = ASSERVISSEMENT_XYT;
antbig 0:ad97421fb1fb 1410 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
ClementBreteau 25:f140c93a8666 1411
ClementBreteau 25:f140c93a8666 1412 target_x_robot = instruction.arg1;
ClementBreteau 25:f140c93a8666 1413 target_y_robot = localData3;
ClementBreteau 25:f140c93a8666 1414 target_theta_robot = localData2;
ClementBreteau 25:f140c93a8666 1415
antbig 0:ad97421fb1fb 1416 break;
antbig 0:ad97421fb1fb 1417 case MV_RECALAGE:
Sitkah 34:6aa4b46b102e 1418 if(instruction.nextActionType == MECANIQUE)
Sitkah 34:6aa4b46b102e 1419 {
Sitkah 34:6aa4b46b102e 1420 instruction.nextActionType = WAIT;
Sitkah 34:6aa4b46b102e 1421
Sitkah 34:6aa4b46b102e 1422 waitingAckID = ASSERVISSEMENT_RECALAGE;
Sitkah 34:6aa4b46b102e 1423 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
Sitkah 34:6aa4b46b102e 1424
Sitkah 34:6aa4b46b102e 1425 localData2 = (((instruction.direction == FORWARD)?1:-1)*3000);//On indique une distance de 3000 pour etre sur que le robot va ce recaler
Sitkah 34:6aa4b46b102e 1426
Sitkah 34:6aa4b46b102e 1427 if(instruction.precision == RECALAGE_Y) {
Sitkah 34:6aa4b46b102e 1428 localData5 = 2;
Sitkah 34:6aa4b46b102e 1429 if(InversStrat == 1 && ingnorInversionOnce == 0) {
Sitkah 34:6aa4b46b102e 1430 localData3 = 3000 - instruction.arg1;//Inversion du Y
Sitkah 34:6aa4b46b102e 1431 } else {
Sitkah 34:6aa4b46b102e 1432 localData3 = instruction.arg1;
Sitkah 34:6aa4b46b102e 1433 }
antbig 11:ed13a480ddca 1434 } else {
Sitkah 34:6aa4b46b102e 1435 localData5 = 1;
antbig 11:ed13a480ddca 1436 localData3 = instruction.arg1;
antbig 11:ed13a480ddca 1437 }
Sitkah 34:6aa4b46b102e 1438 GoStraight(localData2, localData5, localData3, 0);
antbig 11:ed13a480ddca 1439 }
Sitkah 34:6aa4b46b102e 1440 else //CAPTEUR
Sitkah 36:6dd30780bd8e 1441 {
Sitkah 34:6aa4b46b102e 1442 SendRawId(DATA_RECALAGE);
Sitkah 34:6aa4b46b102e 1443 waitingAckID = RECEPTION_RECALAGE;
Sitkah 34:6aa4b46b102e 1444 waitingAckFrom = ACKNOWLEDGE_TELEMETRE;
Sitkah 34:6aa4b46b102e 1445
Sitkah 34:6aa4b46b102e 1446 // On attend que les variables soient actualisé
Sitkah 34:6aa4b46b102e 1447 while(!(waitingAckID == 0 && waitingAckFrom == 0))
Sitkah 34:6aa4b46b102e 1448 canProcessRx();
Sitkah 35:742dc6b200b0 1449 while(!(waitingAckID_FIN==0 && waitingAckFrom_FIN==0))
Sitkah 35:742dc6b200b0 1450 canProcessRx();
Sitkah 36:6dd30780bd8e 1451
Sitkah 34:6aa4b46b102e 1452 if(instruction.precision == RECALAGE_Y) // ((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600)) (theta_robot < 900 && theta_robot > -900)
Sitkah 34:6aa4b46b102e 1453 {
Sitkah 36:6dd30780bd8e 1454 SetOdometrie(ODOMETRIE_SMALL_POSITION, x_robot, recalageDistanceY(), theta_robot);
Sitkah 34:6aa4b46b102e 1455 }
Sitkah 34:6aa4b46b102e 1456 else if(instruction.precision == RECALAGE_X)
Sitkah 34:6aa4b46b102e 1457 {
Sitkah 36:6dd30780bd8e 1458 SetOdometrie(ODOMETRIE_SMALL_POSITION, recalageDistanceX(), y_robot, theta_robot);
Sitkah 34:6aa4b46b102e 1459 }
Sitkah 35:742dc6b200b0 1460 else if(instruction.precision == RECALAGE_T)
Sitkah 34:6aa4b46b102e 1461 {
Sitkah 36:6dd30780bd8e 1462 SetOdometrie(ODOMETRIE_SMALL_POSITION, x_robot, y_robot, recalageAngulaireCapteur() );
Sitkah 35:742dc6b200b0 1463 }
Sitkah 34:6aa4b46b102e 1464 }
antbig 0:ad97421fb1fb 1465 break;
Sitkah 34:6aa4b46b102e 1466
antbig 0:ad97421fb1fb 1467 case ACTION:
ClementBreteau 18:cc5fec34ed9c 1468 int tempo = 0;
Sitkah 30:a1e37af4bbde 1469 waitingAckID= ACK_ACTION; //On veut un ack de type action
Sitkah 30:a1e37af4bbde 1470 waitingAckFrom = ACKNOWLEDGE_HERKULEX; //de la part des herkulex
ClementBreteau 18:cc5fec34ed9c 1471 tempo = doAction(instruction.arg1,instruction.arg2,instruction.arg3);
ClementBreteau 18:cc5fec34ed9c 1472 if(tempo == 1){
antbig 0:ad97421fb1fb 1473 //L'action est spécifique
Sitkah 34:6aa4b46b102e 1474 if((waitingAckFrom == 0 && waitingAckID == 0) && instruction.nextActionType == ENCHAINEMENT) {
antbig 11:ed13a480ddca 1475 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 11:ed13a480ddca 1476 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
Sitkah 30:a1e37af4bbde 1477 }
Sitkah 30:a1e37af4bbde 1478 else {
ClementBreteau 15:c2fc239e85df 1479 gameEtat = ETAT_GAME_WAIT_ACK;
antbig 11:ed13a480ddca 1480 }
ClementBreteau 18:cc5fec34ed9c 1481 #ifdef ROBOT_SMALL
Sitkah 34:6aa4b46b102e 1482 /*actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
Sitkah 34:6aa4b46b102e 1483 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;*/
ClementBreteau 18:cc5fec34ed9c 1484 #endif
antbig 11:ed13a480ddca 1485 return;
ClementBreteau 18:cc5fec34ed9c 1486 #ifdef ROBOT_SMALL
ClementBreteau 18:cc5fec34ed9c 1487 } else if (tempo == 2) {
ClementBreteau 18:cc5fec34ed9c 1488 // on est dans le cas de l'avance selon le telemetre
ClementBreteau 18:cc5fec34ed9c 1489 waitingAckID = ASSERVISSEMENT_RECALAGE;
ClementBreteau 18:cc5fec34ed9c 1490 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
ClementBreteau 18:cc5fec34ed9c 1491
ClementBreteau 18:cc5fec34ed9c 1492 localData2 = (((instruction.direction == FORWARD)?1:-1)*instruction.arg1);
ClementBreteau 18:cc5fec34ed9c 1493 GoStraight(telemetreDistance, 0, 0, 0);
ClementBreteau 18:cc5fec34ed9c 1494 // on reset la distance du telemetre à 0
ClementBreteau 18:cc5fec34ed9c 1495 telemetreDistance = 5000;
ClementBreteau 18:cc5fec34ed9c 1496 #endif
ClementBreteau 18:cc5fec34ed9c 1497 }else{
antbig 0:ad97421fb1fb 1498 //C'est un AX12 qu'il faut bouger
ClementBreteau 15:c2fc239e85df 1499 //AX12_setGoal(instruction.arg1,instruction.arg3/10,instruction.arg2);
ClementBreteau 15:c2fc239e85df 1500 //AX12_enchainement++;
ClementBreteau 14:c8fc06c4887f 1501
antbig 0:ad97421fb1fb 1502 }
antbig 0:ad97421fb1fb 1503 break;
antbig 0:ad97421fb1fb 1504 default:
antbig 0:ad97421fb1fb 1505 //Instruction inconnue, on l'ignore
antbig 0:ad97421fb1fb 1506 break;
antbig 0:ad97421fb1fb 1507 }
antbig 0:ad97421fb1fb 1508
antbig 0:ad97421fb1fb 1509
antbig 0:ad97421fb1fb 1510
antbig 0:ad97421fb1fb 1511 if(instruction.nextActionType == JUMP || instruction.nextActionType == WAIT) {
antbig 0:ad97421fb1fb 1512 gameEtat = ETAT_GAME_WAIT_ACK;//Il faut attendre que la carte est bien reçu l'acknowledge
antbig 0:ad97421fb1fb 1513 screenChecktry++;//On incrèment le conteur de tentative de 1
antbig 0:ad97421fb1fb 1514 cartesCheker.reset();//On reset le timeOut
antbig 0:ad97421fb1fb 1515 cartesCheker.start();
antbig 1:116040d14164 1516 if(AX12_enchainement > 0) {
ClementBreteau 15:c2fc239e85df 1517 //AX12_processChange();//Il faut lancer le déplacement des AX12
ClementBreteau 15:c2fc239e85df 1518 //AX12_enchainement = 0;
antbig 1:116040d14164 1519 }
Sitkah 36:6dd30780bd8e 1520 }
Sitkah 36:6dd30780bd8e 1521 else {//C'est un enchainement
ClementBreteau 15:c2fc239e85df 1522 if(instruction.order == MV_LINE){
Sitkah 30:a1e37af4bbde 1523 gameEtat = ETAT_GAME_WAIT_ACK;
Sitkah 30:a1e37af4bbde 1524 }
Sitkah 30:a1e37af4bbde 1525 else{
ClementBreteau 15:c2fc239e85df 1526 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
ClementBreteau 15:c2fc239e85df 1527 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//C'est un enchainement, on charge directement l'instruction suivante
ClementBreteau 15:c2fc239e85df 1528 }
antbig 0:ad97421fb1fb 1529 }
antbig 0:ad97421fb1fb 1530
antbig 0:ad97421fb1fb 1531 break;
antbig 0:ad97421fb1fb 1532 case ETAT_GAME_WAIT_ACK:
Sitkah 36:6dd30780bd8e 1533 canProcessRx();
Sitkah 34:6aa4b46b102e 1534
Sitkah 30:a1e37af4bbde 1535 if(waitingAckID == 0 && waitingAckFrom == 0) {//Les ack ont été reset, c'est bon on continue
antbig 0:ad97421fb1fb 1536 //if(true) {
antbig 0:ad97421fb1fb 1537 cartesCheker.stop();
antbig 0:ad97421fb1fb 1538 if(instruction.nextActionType == JUMP) {
antbig 11:ed13a480ddca 1539 if(instruction.jumpAction == JUMP_POSITION) {
antbig 11:ed13a480ddca 1540 gameEtat = ETAT_GAME_JUMP_POSITION;
Sitkah 30:a1e37af4bbde 1541 }
Sitkah 30:a1e37af4bbde 1542 else {//Pour eviter les erreurs, on dit que c'est par défaut un jump time
antbig 0:ad97421fb1fb 1543 gameEtat = ETAT_GAME_JUMP_TIME;
antbig 0:ad97421fb1fb 1544 cartesCheker.reset();//On reset le timeOut
antbig 11:ed13a480ddca 1545 cartesCheker.start();
antbig 0:ad97421fb1fb 1546 }
Sitkah 30:a1e37af4bbde 1547 }
Sitkah 30:a1e37af4bbde 1548 else if(instruction.nextActionType == WAIT) { ///Actualisation des waiting ack afin d'attendre la fin des actions
Sitkah 38:76f886a1c8e6 1549 SetOdometrie(0x28, x_robot, y_robot, theta_robot);
Sitkah 34:6aa4b46b102e 1550 gameEtat = ETAT_GAME_WAIT_END_INSTRUCTION;
antbig 0:ad97421fb1fb 1551 switch(instruction.order)
antbig 0:ad97421fb1fb 1552 {
antbig 0:ad97421fb1fb 1553 case MV_COURBURE:
Sitkah 34:6aa4b46b102e 1554 waitingAckID_FIN = ASSERVISSEMENT_COURBURE;
Sitkah 34:6aa4b46b102e 1555 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 1556 break;
antbig 0:ad97421fb1fb 1557 case MV_LINE:
Sitkah 34:6aa4b46b102e 1558 waitingAckID_FIN = ASSERVISSEMENT_RECALAGE;
Sitkah 34:6aa4b46b102e 1559 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 1560 break;
antbig 0:ad97421fb1fb 1561 case MV_TURN:
Sitkah 34:6aa4b46b102e 1562 waitingAckID_FIN = ASSERVISSEMENT_ROTATION;
Sitkah 34:6aa4b46b102e 1563 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 1564 break;
antbig 0:ad97421fb1fb 1565 case MV_XYT:
Sitkah 34:6aa4b46b102e 1566 waitingAckID_FIN = ASSERVISSEMENT_XYT;
Sitkah 34:6aa4b46b102e 1567 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 1568 break;
antbig 0:ad97421fb1fb 1569 case MV_RECALAGE:
Sitkah 34:6aa4b46b102e 1570 waitingAckID_FIN = ASSERVISSEMENT_RECALAGE;
Sitkah 34:6aa4b46b102e 1571 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 1572 break;
antbig 0:ad97421fb1fb 1573 case ACTION:
ClementBreteau 15:c2fc239e85df 1574
ClementBreteau 15:c2fc239e85df 1575 if (modeTelemetre == 0){
ClementBreteau 18:cc5fec34ed9c 1576 if (telemetreDistance == 0){
Sitkah 34:6aa4b46b102e 1577 waitingAckID_FIN = ACK_FIN_ACTION;// ack de type action
Sitkah 34:6aa4b46b102e 1578 waitingAckFrom_FIN = ACKNOWLEDGE_HERKULEX; //de la part des herkulex/actionneurs
ClementBreteau 18:cc5fec34ed9c 1579 }else if(telemetreDistance == 5000){
ClementBreteau 18:cc5fec34ed9c 1580 // on est dans le cas ou l'on fait une ligne suivant la distance du telemetre
Sitkah 34:6aa4b46b102e 1581 waitingAckID_FIN = ASSERVISSEMENT_RECALAGE;
Sitkah 34:6aa4b46b102e 1582 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
ClementBreteau 18:cc5fec34ed9c 1583 telemetreDistance = 0;
ClementBreteau 18:cc5fec34ed9c 1584 }
ClementBreteau 15:c2fc239e85df 1585 }else{ // si on attend la reponse du telemetre
ClementBreteau 15:c2fc239e85df 1586 //modeTelemetre = 1;
Sitkah 34:6aa4b46b102e 1587 waitingAckID_FIN = OBJET_SUR_TABLE;
Sitkah 34:6aa4b46b102e 1588 waitingAckFrom_FIN = 0;
ClementBreteau 15:c2fc239e85df 1589 }
antbig 0:ad97421fb1fb 1590 break;
antbig 0:ad97421fb1fb 1591 default:
antbig 0:ad97421fb1fb 1592 break;
antbig 0:ad97421fb1fb 1593 }
Sitkah 30:a1e37af4bbde 1594 }
Sitkah 30:a1e37af4bbde 1595 else {
antbig 0:ad97421fb1fb 1596 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
antbig 0:ad97421fb1fb 1597 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 0:ad97421fb1fb 1598 }
Sitkah 30:a1e37af4bbde 1599 }
Sitkah 36:6dd30780bd8e 1600 else if(cartesCheker.read_ms () > 1000){
antbig 0:ad97421fb1fb 1601 cartesCheker.stop();
antbig 0:ad97421fb1fb 1602 if(screenChecktry >=2) {//La carte n'a pas reçus l'information, on passe à l'instruction d'erreur
antbig 0:ad97421fb1fb 1603 actual_instruction = instruction.nextLineError;
antbig 0:ad97421fb1fb 1604 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
Sitkah 30:a1e37af4bbde 1605 }
Sitkah 30:a1e37af4bbde 1606 else {
Sitkah 34:6aa4b46b102e 1607 gameEtat = ETAT_GAME_PROCESS_INSTRUCTION;//On retourne dans l'etat d'envois de l'instruction
antbig 0:ad97421fb1fb 1608 }
antbig 0:ad97421fb1fb 1609 }
antbig 0:ad97421fb1fb 1610 break;
antbig 0:ad97421fb1fb 1611
antbig 0:ad97421fb1fb 1612 case ETAT_GAME_JUMP_TIME:
antbig 0:ad97421fb1fb 1613 if(cartesCheker.read_ms () >= instruction.JumpTimeOrX) {
antbig 0:ad97421fb1fb 1614 cartesCheker.stop();//On arrete le timer
antbig 0:ad97421fb1fb 1615 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 0:ad97421fb1fb 1616 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//On charge l'instruction suivante
antbig 0:ad97421fb1fb 1617 }
antbig 0:ad97421fb1fb 1618 break;
ClementBreteau 15:c2fc239e85df 1619
ClementBreteau 15:c2fc239e85df 1620 case ETAT_GAME_JUMP_CONFIG:
ClementBreteau 15:c2fc239e85df 1621 signed int depasX = 1, depasY = 1; // servent à indiquer le sens de dépassement des coordonnées
ClementBreteau 15:c2fc239e85df 1622 // 1 si l'instruction est plus grande que la position du robot
ClementBreteau 15:c2fc239e85df 1623 // -1 si l'instruction est plus petite que la position du robot
ClementBreteau 15:c2fc239e85df 1624 // 0 si l'instruction et position du robot sont proche de moins de 1cm
ClementBreteau 15:c2fc239e85df 1625 if (abs(x_robot-instruction.JumpTimeOrX)<10){
ClementBreteau 15:c2fc239e85df 1626 depasX = 0;
ClementBreteau 15:c2fc239e85df 1627 }else if(x_robot > instruction.JumpTimeOrX){
ClementBreteau 15:c2fc239e85df 1628 depasX = -1;
ClementBreteau 15:c2fc239e85df 1629 }
ClementBreteau 15:c2fc239e85df 1630
ClementBreteau 15:c2fc239e85df 1631 if(abs(y_robot-instruction.JumpY)<10){
ClementBreteau 15:c2fc239e85df 1632 depasY = 0;
ClementBreteau 15:c2fc239e85df 1633 }else if(y_robot > instruction.JumpY){
ClementBreteau 15:c2fc239e85df 1634 depasY = -1;
ClementBreteau 15:c2fc239e85df 1635 }
ClementBreteau 15:c2fc239e85df 1636
ClementBreteau 15:c2fc239e85df 1637 gameEtat = ETAT_GAME_JUMP_POSITION;
ClementBreteau 15:c2fc239e85df 1638 break;
antbig 0:ad97421fb1fb 1639 case ETAT_GAME_JUMP_POSITION:
ClementBreteau 15:c2fc239e85df 1640 bool Xok = false, Yok = false;
ClementBreteau 15:c2fc239e85df 1641
ClementBreteau 15:c2fc239e85df 1642 if (depasX == 0){
ClementBreteau 15:c2fc239e85df 1643 Xok = true;
ClementBreteau 15:c2fc239e85df 1644 }else if ((instruction.JumpTimeOrX - x_robot)*depasX < -5){
ClementBreteau 15:c2fc239e85df 1645 Xok = true;
ClementBreteau 15:c2fc239e85df 1646 }
ClementBreteau 15:c2fc239e85df 1647
ClementBreteau 15:c2fc239e85df 1648 if (depasY == 0){
ClementBreteau 15:c2fc239e85df 1649 Yok = true;
ClementBreteau 15:c2fc239e85df 1650 }else if ((instruction.JumpY - y_robot)*depasY < -5){
ClementBreteau 15:c2fc239e85df 1651 Yok = true;
ClementBreteau 15:c2fc239e85df 1652 }
ClementBreteau 15:c2fc239e85df 1653
ClementBreteau 15:c2fc239e85df 1654 // on teste si les deux coordonnées ont été dépassées, si oui on lance l'instruction suivante
ClementBreteau 15:c2fc239e85df 1655 if (Xok && Yok){
ClementBreteau 15:c2fc239e85df 1656 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
ClementBreteau 15:c2fc239e85df 1657 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//On charge l'instruction suivante
ClementBreteau 15:c2fc239e85df 1658 }
ClementBreteau 15:c2fc239e85df 1659
antbig 0:ad97421fb1fb 1660 break;
antbig 0:ad97421fb1fb 1661 case ETAT_GAME_WAIT_END_INSTRUCTION:
Sitkah 36:6dd30780bd8e 1662 canProcessRx();
Sitkah 35:742dc6b200b0 1663 if(waitingAckID_FIN == 0 && waitingAckFrom_FIN ==0) {//On attend que la carte nous indique que l'instruction est terminée
antbig 0:ad97421fb1fb 1664 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 0:ad97421fb1fb 1665 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//On charge l'instruction suivante
antbig 0:ad97421fb1fb 1666 }
Sitkah 34:6aa4b46b102e 1667
antbig 0:ad97421fb1fb 1668 break;
antbig 0:ad97421fb1fb 1669
antbig 0:ad97421fb1fb 1670
antbig 5:dcd817534b57 1671 case ETAT_WARNING_TIMEOUT://Attente de la trame fin de danger ou du timeout de 2s
antbig 12:14729d584500 1672 if(timeoutWarning.read_ms() >= BALISE_TIMEOUT)//ça fait plus de 2s, il faut changer de stratégie
antbig 5:dcd817534b57 1673 {
Sitkah 38:76f886a1c8e6 1674 if(instruction.nextLineOK == instruction.nextLineError)
Sitkah 38:76f886a1c8e6 1675 gameEtat = ETAT_EVITEMENT;
Sitkah 38:76f886a1c8e6 1676 else
Sitkah 38:76f886a1c8e6 1677 {
Sitkah 38:76f886a1c8e6 1678 actual_instruction = instruction.nextLineError;
Sitkah 38:76f886a1c8e6 1679 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
Sitkah 38:76f886a1c8e6 1680 }
antbig 5:dcd817534b57 1681 }
antbig 5:dcd817534b57 1682 break;
antbig 5:dcd817534b57 1683 case ETAT_WARING_END_BALISE_WAIT://Attente d'une seconde apres la fin d'un End Balise pour etre sur que c'est bon
antbig 12:14729d584500 1684 if(timeoutWarningWaitEnd.read_ms() >= 1000) {//c'est bon, on repart
antbig 12:14729d584500 1685 //actual_instruction = instruction.nextLineError;
antbig 12:14729d584500 1686 gameEtat = ETAT_WARNING_END_LAST_INSTRUCTION;
antbig 12:14729d584500 1687 }
antbig 5:dcd817534b57 1688 break;
antbig 5:dcd817534b57 1689 case ETAT_WARNING_END_LAST_INSTRUCTION://trouver le meilleur moyen de reprendre l'instruction en cours
ClementBreteau 25:f140c93a8666 1690 /*
antbig 12:14729d584500 1691 #ifdef ROBOT_BIG
ClementBreteau 15:c2fc239e85df 1692 actual_instruction = instruction.nextLineError;// 2 //Modification directe... c'est pas bien mais ça marchait pour le match 5
antbig 12:14729d584500 1693 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
ClementBreteau 20:de595e4ff01d 1694 #else
antbig 12:14729d584500 1695 actual_instruction = instruction.nextLineError;
antbig 12:14729d584500 1696 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
ClementBreteau 20:de595e4ff01d 1697 #endif
ClementBreteau 25:f140c93a8666 1698 gameEtat = ETAT_END;*/
ClementBreteau 21:590cdacb6a35 1699
ClementBreteau 25:f140c93a8666 1700 switch(actionPrecedente){
ClementBreteau 25:f140c93a8666 1701 case MV_LINE:
antbig 27:76ead555a63d 1702
ClementBreteau 25:f140c93a8666 1703 if(instruction.direction == BACKWARD) {
ClementBreteau 25:f140c93a8666 1704 localData1 = -1;
ClementBreteau 25:f140c93a8666 1705 } else {
ClementBreteau 25:f140c93a8666 1706 localData1 = 1;
ClementBreteau 25:f140c93a8666 1707 }
antbig 27:76ead555a63d 1708
ClementBreteau 25:f140c93a8666 1709 GoToPosition(target_x_robot,target_y_robot,target_theta_robot,localData1);
antbig 27:76ead555a63d 1710 debugXYTTarget(target_x_robot,target_y_robot,target_theta_robot);
antbig 27:76ead555a63d 1711 waitingAckID = ASSERVISSEMENT_XYT;
antbig 27:76ead555a63d 1712 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
antbig 27:76ead555a63d 1713 gameEtat = ETAT_GAME_WAIT_ACK;
antbig 27:76ead555a63d 1714 instruction.order = MV_XYT;
antbig 28:acd18776ed2d 1715 instruction.arg1 = target_x_robot;
antbig 28:acd18776ed2d 1716 instruction.arg2 = target_y_robot;
antbig 28:acd18776ed2d 1717 instruction.arg3 = target_theta_robot;
antbig 28:acd18776ed2d 1718 instruction.direction = (localData1)?FORWARD:BACKWARD;
antbig 28:acd18776ed2d 1719 ingnorInversionOnce = 1;//Pour éviter que l'ago recalcul l'inversion
antbig 27:76ead555a63d 1720 return;
ClementBreteau 25:f140c93a8666 1721
ClementBreteau 25:f140c93a8666 1722 case MV_XYT:
antbig 27:76ead555a63d 1723 gameEtat = ETAT_GAME_PROCESS_INSTRUCTION;
Sitkah 33:388aa0bf6af4 1724 ///////cv
ClementBreteau 25:f140c93a8666 1725 break;
ClementBreteau 25:f140c93a8666 1726
ClementBreteau 26:2f4fcc2354f3 1727 case MV_COURBURE:
antbig 28:acd18776ed2d 1728 //target_theta_robot = theta_robot - target_theta_robot;
antbig 28:acd18776ed2d 1729 //instruction.arg3 = instruction.arg3 - target_theta_robot;
ClementBreteau 26:2f4fcc2354f3 1730 if(instruction.direction == LEFT){
ClementBreteau 26:2f4fcc2354f3 1731 target_theta_robot = target_theta_robot - theta_robot;
ClementBreteau 26:2f4fcc2354f3 1732 }else{
antbig 28:acd18776ed2d 1733 target_theta_robot = theta_robot + target_theta_robot;
antbig 28:acd18776ed2d 1734 }
antbig 28:acd18776ed2d 1735
antbig 28:acd18776ed2d 1736
antbig 28:acd18776ed2d 1737 target_theta_robot = (target_theta_robot)%3600;
antbig 28:acd18776ed2d 1738 if(target_theta_robot > 1800) {
antbig 28:acd18776ed2d 1739 target_theta_robot = target_theta_robot-3600;
antbig 28:acd18776ed2d 1740 }
antbig 28:acd18776ed2d 1741 if(InversStrat == 1) {
antbig 28:acd18776ed2d 1742 target_theta_robot = -target_theta_robot;
antbig 28:acd18776ed2d 1743 }
antbig 28:acd18776ed2d 1744 instruction.arg3 = target_theta_robot;
antbig 28:acd18776ed2d 1745
antbig 28:acd18776ed2d 1746
antbig 28:acd18776ed2d 1747 gameEtat = ETAT_GAME_PROCESS_INSTRUCTION;
antbig 28:acd18776ed2d 1748
ClementBreteau 25:f140c93a8666 1749 break;
antbig 27:76ead555a63d 1750 default:
antbig 27:76ead555a63d 1751 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 27:76ead555a63d 1752 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
antbig 27:76ead555a63d 1753 break;
ClementBreteau 25:f140c93a8666 1754 }
ClementBreteau 25:f140c93a8666 1755
antbig 27:76ead555a63d 1756 //actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 27:76ead555a63d 1757 //gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
antbig 5:dcd817534b57 1758 break;
antbig 5:dcd817534b57 1759 case ETAT_WARNING_SWITCH_STRATEGIE://Si à la fin du timeout il y a toujours un robot, passer à l'instruction d'erreur
antbig 5:dcd817534b57 1760 actual_instruction = instruction.nextLineError;
antbig 5:dcd817534b57 1761 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
antbig 12:14729d584500 1762 ingnorBaliseOnce = 1;
antbig 5:dcd817534b57 1763 break;
Sitkah 37:fca332b64b42 1764
Sitkah 37:fca332b64b42 1765 case ETAT_EVITEMENT :
Sitkah 37:fca332b64b42 1766 E_Evitement EvitEtat= ETAT_INIT_EVITEMENT;
Sitkah 37:fca332b64b42 1767 while(1)
Sitkah 37:fca332b64b42 1768 {
Sitkah 37:fca332b64b42 1769 canProcessRx();
Sitkah 37:fca332b64b42 1770
Sitkah 37:fca332b64b42 1771 switch(EvitEtat)
Sitkah 37:fca332b64b42 1772 {
Sitkah 37:fca332b64b42 1773 case ETAT_INIT_EVITEMENT:
Sitkah 37:fca332b64b42 1774 EvitEtat = ETAT_ESTIMATION_POSITION;
Sitkah 37:fca332b64b42 1775 break;
Sitkah 37:fca332b64b42 1776
Sitkah 37:fca332b64b42 1777 case ETAT_ESTIMATION_POSITION :
Sitkah 38:76f886a1c8e6 1778 /*wait_ms(100);
Sitkah 37:fca332b64b42 1779 Rotate(3600);
Sitkah 37:fca332b64b42 1780 EvitEtat = ETAT_ESTIMATION_POSITION_ROTATION_ACK;
Sitkah 37:fca332b64b42 1781 waitingAckID = ASSERVISSEMENT_ROTATION;
Sitkah 38:76f886a1c8e6 1782 waitingAckFrom = ACKNOWLEDGE_MOTEUR;*/
Sitkah 38:76f886a1c8e6 1783 GoToPosition(1400,300,0,1);
Sitkah 38:76f886a1c8e6 1784 waitingAckID = ASSERVISSEMENT_XYT;
Sitkah 37:fca332b64b42 1785 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
Sitkah 37:fca332b64b42 1786 break;
Sitkah 37:fca332b64b42 1787
Sitkah 37:fca332b64b42 1788 case ETAT_ESTIMATION_POSITION_ROTATION_ACK:
Sitkah 37:fca332b64b42 1789 if(waitingAckID == 0 && waitingAckFrom == 0)
Sitkah 38:76f886a1c8e6 1790 {
Sitkah 37:fca332b64b42 1791 EvitEtat = ETAT_ESTIMATION_POSITION_ROTATION_ACK_END;
Sitkah 38:76f886a1c8e6 1792 waitingAckID_FIN = ASSERVISSEMENT_XYT;
Sitkah 38:76f886a1c8e6 1793 waitingAckFrom_FIN = INSTRUCTION_END_MOTEUR;
Sitkah 38:76f886a1c8e6 1794 }
Sitkah 37:fca332b64b42 1795 break;
Sitkah 37:fca332b64b42 1796
Sitkah 37:fca332b64b42 1797 case ETAT_ESTIMATION_POSITION_ROTATION_ACK_END:
Sitkah 38:76f886a1c8e6 1798 if(waitingAckID == 0 && waitingAckFrom == 0)
Sitkah 38:76f886a1c8e6 1799 EvitEtat = ETAT_ESTIMATION_POSITION_ROTATION_ACK_END;
Sitkah 37:fca332b64b42 1800 break;
Sitkah 37:fca332b64b42 1801
Sitkah 37:fca332b64b42 1802 case ETAT_FIN_EVITEMENT:
Sitkah 38:76f886a1c8e6 1803 gameEtat = ETAT_WARNING_END_LAST_INSTRUCTION;
Sitkah 37:fca332b64b42 1804 break;
Sitkah 37:fca332b64b42 1805 }
Sitkah 37:fca332b64b42 1806 }
Sitkah 37:fca332b64b42 1807
Sitkah 37:fca332b64b42 1808
Sitkah 37:fca332b64b42 1809 break;
ClementBreteau 20:de595e4ff01d 1810
ClementBreteau 20:de595e4ff01d 1811
ClementBreteau 20:de595e4ff01d 1812
ClementBreteau 14:c8fc06c4887f 1813 case ETAT_END:
ClementBreteau 14:c8fc06c4887f 1814 if (ModeDemo){
ClementBreteau 14:c8fc06c4887f 1815 gameEtat = ETAT_CHECK_CARTE_SCREEN;
ClementBreteau 14:c8fc06c4887f 1816 ModeDemo = 1;
ClementBreteau 14:c8fc06c4887f 1817 } else {
ClementBreteau 14:c8fc06c4887f 1818 gameEtat = ETAT_END_LOOP;
ClementBreteau 14:c8fc06c4887f 1819 }
antbig 0:ad97421fb1fb 1820 break;
antbig 0:ad97421fb1fb 1821 case ETAT_END_LOOP:
antbig 0:ad97421fb1fb 1822 //Rien, on tourne en rond
ClementBreteau 18:cc5fec34ed9c 1823
antbig 0:ad97421fb1fb 1824 break;
antbig 0:ad97421fb1fb 1825 default:
ClementBreteau 20:de595e4ff01d 1826
antbig 0:ad97421fb1fb 1827 break;
ClementBreteau 20:de595e4ff01d 1828 }
Sitkah 29:41e02746041d 1829 }
Sitkah 29:41e02746041d 1830
Sitkah 29:41e02746041d 1831
Sitkah 29:41e02746041d 1832
Sitkah 29:41e02746041d 1833
Sitkah 29:41e02746041d 1834
antbig 4:88431b537477 1835 /****************************************************************************************/
antbig 4:88431b537477 1836 /* FUNCTION NAME: canProcessRx */
Sitkah 29:41e02746041d 1837 /* DESCRIPTION : Fait évoluer l'automate de l'IHM en fonction des receptions sur le CAN*/
antbig 4:88431b537477 1838 /****************************************************************************************/
antbig 0:ad97421fb1fb 1839 void canProcessRx(void)
Sitkah 29:41e02746041d 1840 {
antbig 0:ad97421fb1fb 1841 static signed char FIFO_occupation=0,FIFO_max_occupation=0;
Sitkah 31:833fc481b002 1842 char message[10]="toto";
Sitkah 31:833fc481b002 1843 char message1[10]="toto";
Sitkah 31:833fc481b002 1844 char message2[10]="toto";
Sitkah 31:833fc481b002 1845 char message3[10]="toto";
antbig 0:ad97421fb1fb 1846 FIFO_occupation=FIFO_ecriture-FIFO_lecture;
antbig 0:ad97421fb1fb 1847 if(FIFO_occupation<0)
antbig 0:ad97421fb1fb 1848 FIFO_occupation=FIFO_occupation+SIZE_FIFO;
antbig 0:ad97421fb1fb 1849 if(FIFO_max_occupation<FIFO_occupation)
antbig 0:ad97421fb1fb 1850 FIFO_max_occupation=FIFO_occupation;
antbig 0:ad97421fb1fb 1851 if(FIFO_occupation!=0) {
Sitkah 29:41e02746041d 1852 int identifiant=msgRxBuffer[FIFO_lecture].id;
Sitkah 29:41e02746041d 1853 switch(identifiant) {
Sitkah 29:41e02746041d 1854
Sitkah 29:41e02746041d 1855 case ALIVE_MOTEUR:
Sitkah 29:41e02746041d 1856 if (etat == ATT) {
Sitkah 29:41e02746041d 1857
Sitkah 29:41e02746041d 1858 lcd.SetTextColor(LCD_COLOR_LIGHTGREEN);
Sitkah 34:6aa4b46b102e 1859 lcd.FillRect(0,400,400,150);
Sitkah 29:41e02746041d 1860 lcd.SetTextColor(LCD_COLOR_BLACK);
Sitkah 29:41e02746041d 1861 lcd.SetBackColor(LCD_COLOR_LIGHTGREEN);
Sitkah 34:6aa4b46b102e 1862 lcd.DisplayStringAt(80, 450, (uint8_t *)"Carte Moteur", LEFT_MODE);
Sitkah 29:41e02746041d 1863 }
Sitkah 29:41e02746041d 1864 break;
Sitkah 29:41e02746041d 1865
Sitkah 29:41e02746041d 1866 case ALIVE_BALISE:
Sitkah 29:41e02746041d 1867 if (etat == ATT) {
Sitkah 29:41e02746041d 1868
Sitkah 29:41e02746041d 1869 lcd.SetTextColor(LCD_COLOR_LIGHTGREEN);
Sitkah 34:6aa4b46b102e 1870 lcd.FillRect(0,600,400,150); //carte AX12
Sitkah 29:41e02746041d 1871 lcd.SetTextColor(LCD_COLOR_BLACK);
Sitkah 29:41e02746041d 1872 lcd.SetBackColor(LCD_COLOR_LIGHTGREEN);
Sitkah 34:6aa4b46b102e 1873 lcd.DisplayStringAt(110, 650, (uint8_t *)"Balise", LEFT_MODE);
Sitkah 29:41e02746041d 1874 }
Sitkah 29:41e02746041d 1875 break;
Sitkah 29:41e02746041d 1876
Sitkah 29:41e02746041d 1877 case RESET_IHM:
Sitkah 29:41e02746041d 1878 etat = CHOIX;
Sitkah 29:41e02746041d 1879 break;
Sitkah 29:41e02746041d 1880
antbig 4:88431b537477 1881 case DEBUG_FAKE_JAKE://Permet de lancer le match à distance
ClementBreteau 23:ab87d308eaf9 1882 case GLOBAL_JACK:
antbig 1:116040d14164 1883 if(gameEtat == ETAT_GAME_WAIT_FOR_JACK) {
antbig 1:116040d14164 1884 gameEtat = ETAT_GAME_START;
ClementBreteau 23:ab87d308eaf9 1885 SendRawId(ACKNOWLEDGE_JACK);
antbig 1:116040d14164 1886 }
antbig 1:116040d14164 1887 break;
antbig 1:116040d14164 1888
Sitkah 30:a1e37af4bbde 1889 case ALIVE_ACTIONNEURS_AVANT: //pas de break donc passe directement dans ECRAN_ALL_CHECK mais conserve l'ident initial
ClementBreteau 23:ab87d308eaf9 1890 case ALIVE_ACTIONNEURS_ARRIERE:
Sitkah 30:a1e37af4bbde 1891 case ALIVE_HERKULEX:
antbig 0:ad97421fb1fb 1892 case ECRAN_ALL_CHECK:
antbig 0:ad97421fb1fb 1893 if(waitingAckFrom == msgRxBuffer[FIFO_lecture].id) {
antbig 0:ad97421fb1fb 1894 waitingAckFrom = 0;//C'est la bonne carte qui indique qu'elle est en ligne
antbig 0:ad97421fb1fb 1895 }
Sitkah 38:76f886a1c8e6 1896 flag=1;
ClementBreteau 15:c2fc239e85df 1897 break;
antbig 0:ad97421fb1fb 1898
Sitkah 30:a1e37af4bbde 1899
Sitkah 30:a1e37af4bbde 1900
Sitkah 30:a1e37af4bbde 1901
Sitkah 30:a1e37af4bbde 1902 /////////////////////////////////////Acknowledges de Reception de la demande d'action////////////////////////////////////////
Sitkah 30:a1e37af4bbde 1903 case ACKNOWLEDGE_HERKULEX:
Sitkah 30:a1e37af4bbde 1904 case ACKNOWLEDGE_BALISE: //pas de break donc passe directement dans INSTRUCTION_END_AX12 mais conserve l'ident initial
Sitkah 34:6aa4b46b102e 1905
Sitkah 30:a1e37af4bbde 1906 case ACKNOWLEDGE_TELEMETRE:
Sitkah 30:a1e37af4bbde 1907 /////////////////////////////////////////////Acknowledges de la fin d'action/////////////////////////////////////////////////
Sitkah 34:6aa4b46b102e 1908 case ACKNOWLEDGE_MOTEUR:
antbig 0:ad97421fb1fb 1909 case INSTRUCTION_END_BALISE:
antbig 0:ad97421fb1fb 1910 case INSTRUCTION_END_MOTEUR:
Sitkah 31:833fc481b002 1911 case ACK_FIN_ACTION:
antbig 11:ed13a480ddca 1912 if(waitingAckFrom == msgRxBuffer[FIFO_lecture].id && ((unsigned short)msgRxBuffer[FIFO_lecture].data[0]|((unsigned short)(msgRxBuffer[FIFO_lecture].data[1])<<8) == waitingAckID)) {
antbig 0:ad97421fb1fb 1913 waitingAckFrom = 0;
Sitkah 30:a1e37af4bbde 1914 waitingAckID = 0;
antbig 0:ad97421fb1fb 1915 }
Sitkah 34:6aa4b46b102e 1916 if(waitingAckFrom_FIN == msgRxBuffer[FIFO_lecture].id && ((unsigned short)msgRxBuffer[FIFO_lecture].data[0]|((unsigned short)(msgRxBuffer[FIFO_lecture].data[1])<<8) == waitingAckID_FIN)) {
Sitkah 34:6aa4b46b102e 1917 waitingAckFrom_FIN = 0;
Sitkah 34:6aa4b46b102e 1918 waitingAckID_FIN = 0;
Sitkah 34:6aa4b46b102e 1919 }
Sitkah 30:a1e37af4bbde 1920
antbig 0:ad97421fb1fb 1921 break;
antbig 1:116040d14164 1922 #ifdef ROBOT_BIG
antbig 0:ad97421fb1fb 1923 case ODOMETRIE_BIG_POSITION:
antbig 0:ad97421fb1fb 1924 #else
antbig 0:ad97421fb1fb 1925 case ODOMETRIE_SMALL_POSITION:
antbig 0:ad97421fb1fb 1926 #endif
antbig 0:ad97421fb1fb 1927 x_robot=msgRxBuffer[FIFO_lecture].data[0]|((unsigned short)(msgRxBuffer[FIFO_lecture].data[1])<<8);
antbig 0:ad97421fb1fb 1928 y_robot=msgRxBuffer[FIFO_lecture].data[2]|((unsigned short)(msgRxBuffer[FIFO_lecture].data[3])<<8);
antbig 0:ad97421fb1fb 1929 theta_robot=msgRxBuffer[FIFO_lecture].data[4]|((signed short)(msgRxBuffer[FIFO_lecture].data[5])<<8);
antbig 0:ad97421fb1fb 1930 break;
Sitkah 29:41e02746041d 1931
Sitkah 30:a1e37af4bbde 1932 case ACK_ACTION:
Sitkah 30:a1e37af4bbde 1933 if(waitingAckID == msgRxBuffer[FIFO_lecture].id) {
Sitkah 30:a1e37af4bbde 1934 waitingAckFrom = 0;
Sitkah 30:a1e37af4bbde 1935 waitingAckID = 0;
Sitkah 30:a1e37af4bbde 1936 }
Sitkah 30:a1e37af4bbde 1937 break;
Sitkah 30:a1e37af4bbde 1938
ClementBreteau 16:7321fb3bb396 1939 case BALISE_DANGER :
ClementBreteau 16:7321fb3bb396 1940 SendAck(ACKNOWLEDGE_BALISE, BALISE_END_DANGER);
ClementBreteau 16:7321fb3bb396 1941 break;
ClementBreteau 16:7321fb3bb396 1942
antbig 5:dcd817534b57 1943 case BALISE_STOP:
antbig 5:dcd817534b57 1944 SendAck(ACKNOWLEDGE_BALISE, BALISE_STOP);
Sitkah 37:fca332b64b42 1945
Sitkah 37:fca332b64b42 1946 signed char fin_angle_detection = msgRxBuffer[FIFO_lecture].data[0] & 0x0F;
Sitkah 37:fca332b64b42 1947 signed char debut_angle_detection = (msgRxBuffer[FIFO_lecture].data[0] & 0xF0) >> 4;
Sitkah 37:fca332b64b42 1948
Sitkah 37:fca332b64b42 1949 if(debut_angle_detection > fin_angle_detection)
Sitkah 37:fca332b64b42 1950 {
Sitkah 38:76f886a1c8e6 1951 angle_moyen_balise_IR = (float)debut_angle_detection + ((15.0f-(float)debut_angle_detection)+(float)fin_angle_detection)/2.0f;
Sitkah 38:76f886a1c8e6 1952 if(angle_moyen_balise_IR > 15.0f)
Sitkah 38:76f886a1c8e6 1953 angle_moyen_balise_IR-=15.0f;
Sitkah 37:fca332b64b42 1954 }
Sitkah 37:fca332b64b42 1955 else
Sitkah 37:fca332b64b42 1956 angle_moyen_balise_IR = debut_angle_detection + (fin_angle_detection-debut_angle_detection)/2;
Sitkah 37:fca332b64b42 1957
Sitkah 38:76f886a1c8e6 1958 #ifdef ROBOT_BIG
Sitkah 38:76f886a1c8e6 1959 float seuil_bas_avant = 12.0; // >=
Sitkah 38:76f886a1c8e6 1960 float seuil_haut_avant = 0.0; // <=
Sitkah 38:76f886a1c8e6 1961 float seuil_bas_arriere = 4.0;
Sitkah 38:76f886a1c8e6 1962 float seuil_haut_arriere = 8.0;
Sitkah 38:76f886a1c8e6 1963 #else
Sitkah 38:76f886a1c8e6 1964 float seuil_bas_avant = 13.0;
Sitkah 38:76f886a1c8e6 1965 float seuil_haut_avant = 15.0;
Sitkah 38:76f886a1c8e6 1966 float seuil_bas_arriere = 5.0;
Sitkah 38:76f886a1c8e6 1967 float seuil_haut_arriere = 7.0;
Sitkah 38:76f886a1c8e6 1968 #endif
Sitkah 37:fca332b64b42 1969
Sitkah 38:76f886a1c8e6 1970 if (instruction.order == MV_LINE && instruction.direction == FORWARD && angle_moyen_balise_IR >= seuil_bas_avant && angle_moyen_balise_IR <= seuil_haut_avant
Sitkah 38:76f886a1c8e6 1971 || instruction.order == MV_LINE && instruction.direction == BACKWARD && angle_moyen_balise_IR >= seuil_bas_arriere && angle_moyen_balise_IR <= 7
Sitkah 38:76f886a1c8e6 1972 || instruction.order == MV_COURBURE && angle_moyen_balise_IR >= seuil_bas_avant && angle_moyen_balise_IR <= seuil_haut_avant
Sitkah 38:76f886a1c8e6 1973 || instruction.order == MV_COURBURE && angle_moyen_balise_IR >= seuil_bas_arriere && angle_moyen_balise_IR <= seuil_haut_arriere
Sitkah 38:76f886a1c8e6 1974 || instruction.order == MV_XYT && angle_moyen_balise_IR >= seuil_bas_avant && angle_moyen_balise_IR <= seuil_haut_avant
Sitkah 38:76f886a1c8e6 1975 || instruction.order == MV_XYT && angle_moyen_balise_IR >= seuil_bas_arriere && angle_moyen_balise_IR <= seuil_haut_arriere ){ //J'ai rajouté cette ligne mais il faut tester avec et sans pour voir le comportement du robot,
ClementBreteau 16:7321fb3bb396 1976 if(needToStop() != 0 && ingnorBaliseOnce ==0) {
ClementBreteau 16:7321fb3bb396 1977 if(gameEtat > ETAT_GAME_START && gameEtat != ETAT_WARNING_TIMEOUT)
ClementBreteau 16:7321fb3bb396 1978 {
ClementBreteau 16:7321fb3bb396 1979 SendRawId(ASSERVISSEMENT_STOP);
ClementBreteau 26:2f4fcc2354f3 1980 //while(1); // ligne à décommenter si on est en homologation
ClementBreteau 16:7321fb3bb396 1981 if(gameEtat != ETAT_WARING_END_BALISE_WAIT) {
ClementBreteau 16:7321fb3bb396 1982 timeoutWarning.reset();
ClementBreteau 16:7321fb3bb396 1983 timeoutWarning.start();//Reset du timer utiliser par le timeout
ClementBreteau 16:7321fb3bb396 1984 }
antbig 27:76ead555a63d 1985 gameEtat = ETAT_WARNING_TIMEOUT;
antbig 12:14729d584500 1986 }
antbig 12:14729d584500 1987 }
Sitkah 38:76f886a1c8e6 1988
antbig 28:acd18776ed2d 1989 }
Sitkah 38:76f886a1c8e6 1990
Sitkah 38:76f886a1c8e6 1991
Sitkah 38:76f886a1c8e6 1992
antbig 12:14729d584500 1993 ingnorBaliseOnce = 0;
antbig 5:dcd817534b57 1994 break;
ClementBreteau 16:7321fb3bb396 1995
antbig 5:dcd817534b57 1996 case BALISE_END_DANGER:
ClementBreteau 16:7321fb3bb396 1997 SendAck(ACKNOWLEDGE_BALISE, BALISE_END_DANGER);
antbig 5:dcd817534b57 1998 if(gameEtat == ETAT_WARNING_TIMEOUT) {
antbig 5:dcd817534b57 1999 timeoutWarningWaitEnd.reset();
antbig 5:dcd817534b57 2000 timeoutWarningWaitEnd.start();
antbig 5:dcd817534b57 2001 gameEtat = ETAT_WARING_END_BALISE_WAIT;
antbig 5:dcd817534b57 2002 }
antbig 5:dcd817534b57 2003 break;
antbig 12:14729d584500 2004
ClementBreteau 14:c8fc06c4887f 2005 case OBJET_SUR_TABLE:
ClementBreteau 15:c2fc239e85df 2006 if (msgRxBuffer[FIFO_lecture].data[1] == 0xff){
ClementBreteau 15:c2fc239e85df 2007
ClementBreteau 15:c2fc239e85df 2008 gameEtat = ETAT_WARNING_END_LAST_INSTRUCTION;
ClementBreteau 15:c2fc239e85df 2009 }
ClementBreteau 15:c2fc239e85df 2010 else{
ClementBreteau 15:c2fc239e85df 2011
ClementBreteau 15:c2fc239e85df 2012 waitingAckFrom = 0;
ClementBreteau 15:c2fc239e85df 2013 waitingAckID = 0;
ClementBreteau 15:c2fc239e85df 2014
ClementBreteau 15:c2fc239e85df 2015 strat_instructions[actual_instruction+1].arg1 = returnX(strat_instructions[actual_instruction].arg2);
ClementBreteau 15:c2fc239e85df 2016 strat_instructions[actual_instruction+1].arg2 = returnY(strat_instructions[actual_instruction].arg2);
ClementBreteau 15:c2fc239e85df 2017 }
ClementBreteau 15:c2fc239e85df 2018 modeTelemetre = 0;
ClementBreteau 14:c8fc06c4887f 2019 break;
Sitkah 29:41e02746041d 2020
Sitkah 30:a1e37af4bbde 2021 case RECEPTION_DATA:
Sitkah 30:a1e37af4bbde 2022 telemetreDistance=char_to_short_transformation(msgRxBuffer[FIFO_lecture].data[0], msgRxBuffer[FIFO_lecture].data[1]);
Sitkah 38:76f886a1c8e6 2023 telemetreDistance= (float)telemetreDistance*100.0f*35.5f+50.0f;
Sitkah 30:a1e37af4bbde 2024 waitingAckFrom = 0;
Sitkah 30:a1e37af4bbde 2025 waitingAckID = 0;
Sitkah 30:a1e37af4bbde 2026 break;
Sitkah 30:a1e37af4bbde 2027
Sitkah 31:833fc481b002 2028 case RECEPTION_RECALAGE:
Sitkah 34:6aa4b46b102e 2029 telemetreDistance_arriere_droite = char_to_short_transformation(msgRxBuffer[FIFO_lecture].data[0], msgRxBuffer[FIFO_lecture].data[1]); //
Sitkah 34:6aa4b46b102e 2030 telemetreDistance_avant_droite = char_to_short_transformation(msgRxBuffer[FIFO_lecture].data[2], msgRxBuffer[FIFO_lecture].data[3]);
Sitkah 34:6aa4b46b102e 2031 telemetreDistance_arriere_gauche = char_to_short_transformation(msgRxBuffer[FIFO_lecture].data[4], msgRxBuffer[FIFO_lecture].data[5]);
Sitkah 34:6aa4b46b102e 2032 telemetreDistance_avant_gauche = char_to_short_transformation(msgRxBuffer[FIFO_lecture].data[6], msgRxBuffer[FIFO_lecture].data[7]);
Sitkah 34:6aa4b46b102e 2033
Sitkah 34:6aa4b46b102e 2034
Sitkah 34:6aa4b46b102e 2035
Sitkah 34:6aa4b46b102e 2036 if(ModeDemo==1)
Sitkah 34:6aa4b46b102e 2037 {
Sitkah 34:6aa4b46b102e 2038 sprintf(message,"%04d mm",telemetreDistance_arriere_droite);
Sitkah 31:833fc481b002 2039 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 2040 lcd.DisplayStringAt(0, LINE(10),(unsigned char *)"LASER ARD : ",LEFT_MODE);
Sitkah 31:833fc481b002 2041 lcd.DisplayStringAt(200, LINE(10),(unsigned char *)message, LEFT_MODE);
Sitkah 31:833fc481b002 2042
Sitkah 34:6aa4b46b102e 2043 sprintf(message1,"%04d mm",telemetreDistance_avant_droite);
Sitkah 31:833fc481b002 2044 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 2045 lcd.DisplayStringAt(0, LINE(12),(unsigned char *)"LASER AVD : ",LEFT_MODE);
Sitkah 31:833fc481b002 2046 lcd.DisplayStringAt(200, LINE(12),(unsigned char *)message1, LEFT_MODE);
Sitkah 31:833fc481b002 2047
Sitkah 34:6aa4b46b102e 2048 sprintf(message2,"%04d mm",telemetreDistance_arriere_gauche);
Sitkah 31:833fc481b002 2049 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 2050 lcd.DisplayStringAt(0, LINE(14),(unsigned char *)"LASER ARG : ",LEFT_MODE);
Sitkah 31:833fc481b002 2051 lcd.DisplayStringAt(200, LINE(14),(unsigned char *)message2, LEFT_MODE);
Sitkah 31:833fc481b002 2052
Sitkah 34:6aa4b46b102e 2053 sprintf(message3,"%04d mm",telemetreDistance_avant_gauche);
Sitkah 31:833fc481b002 2054 lcd.SetBackColor(LCD_COLOR_WHITE);
Sitkah 31:833fc481b002 2055 lcd.DisplayStringAt(0, LINE(16),(unsigned char *)"LASER AVG : ",LEFT_MODE);
Sitkah 34:6aa4b46b102e 2056 lcd.DisplayStringAt(200, LINE(16),(unsigned char *)message3, LEFT_MODE);
Sitkah 31:833fc481b002 2057 }
Sitkah 30:a1e37af4bbde 2058 break;
Sitkah 29:41e02746041d 2059
Sitkah 30:a1e37af4bbde 2060 case RECEPTION_COULEUR:
Sitkah 30:a1e37af4bbde 2061 couleur1=msgRxBuffer[FIFO_lecture].data[0];
Sitkah 30:a1e37af4bbde 2062 couleur2=msgRxBuffer[FIFO_lecture].data[1];
Sitkah 30:a1e37af4bbde 2063 couleur3=msgRxBuffer[FIFO_lecture].data[2];
Sitkah 30:a1e37af4bbde 2064 break;
Sitkah 30:a1e37af4bbde 2065
Sitkah 35:742dc6b200b0 2066 case NO_BLOC: //il n'y a pas de bloc, on saute les étapes liées à l'attrape bloc
Sitkah 35:742dc6b200b0 2067 actual_instruction = instruction.nextLineError;
Sitkah 35:742dc6b200b0 2068 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
Sitkah 35:742dc6b200b0 2069 /*waitingAckID_FIN=0;
Sitkah 35:742dc6b200b0 2070 waitingAckFrom_FIN=0;*/
Sitkah 35:742dc6b200b0 2071 SendRawId(0x40);
Sitkah 35:742dc6b200b0 2072 break;
Sitkah 29:41e02746041d 2073 }
antbig 0:ad97421fb1fb 2074 FIFO_lecture=(FIFO_lecture+1)%SIZE_FIFO;
antbig 0:ad97421fb1fb 2075 }
antbig 0:ad97421fb1fb 2076 }
Sitkah 29:41e02746041d 2077
Sitkah 29:41e02746041d 2078
Sitkah 29:41e02746041d 2079
Sitkah 29:41e02746041d 2080
Sitkah 29:41e02746041d 2081
Sitkah 29:41e02746041d 2082 /****************************************************************************************/
Sitkah 29:41e02746041d 2083 /* FUNCTION NAME: Bouton_Strat */
Sitkah 29:41e02746041d 2084 /* DESCRIPTION : Sélection de la strat sur le lcd puis envoie sur CAN (à modifier!) */
Sitkah 29:41e02746041d 2085 /****************************************************************************************/
Sitkah 29:41e02746041d 2086 signed char Bouton_Strat (void)
Sitkah 29:41e02746041d 2087 {
Sitkah 29:41e02746041d 2088 Button STRAT_1 (0, 30, 190, 110, strat_sd[0]);
Sitkah 29:41e02746041d 2089 Button STRAT_2 (210, 30, 190, 110, strat_sd[1]);
Sitkah 29:41e02746041d 2090 Button STRAT_3 (0, 150, 190, 110, strat_sd[2]);
Sitkah 29:41e02746041d 2091 Button STRAT_4 (210, 150, 190, 110, strat_sd[3]);
Sitkah 29:41e02746041d 2092 Button STRAT_5 (0, 270, 190, 110,strat_sd[4]);
Sitkah 29:41e02746041d 2093 Button STRAT_6 (210, 270, 190, 110, strat_sd[5]);
Sitkah 29:41e02746041d 2094 Button STRAT_7 (0, 390, 190, 110, strat_sd[6]);
Sitkah 29:41e02746041d 2095 Button STRAT_8 (210, 390, 190, 110, strat_sd[7]);
Sitkah 29:41e02746041d 2096 Button STRAT_9 (0, 510, 190, 110, strat_sd[8]);
Sitkah 29:41e02746041d 2097 Button STRAT_10 (210, 510, 190, 110, strat_sd[9]);
Sitkah 29:41e02746041d 2098 Button RETOUR (0, 680, 400, 110, "--Precedent--");
Sitkah 29:41e02746041d 2099 //Definition des boutons
Sitkah 29:41e02746041d 2100
Sitkah 29:41e02746041d 2101 Ack_strat = 0;
Sitkah 29:41e02746041d 2102 Strat = 0;
Sitkah 29:41e02746041d 2103 STRAT_1.Draw(0xFFF0F0F0, 0);
Sitkah 29:41e02746041d 2104 STRAT_2.Draw(0xFFF0F0F0, 0);
Sitkah 29:41e02746041d 2105 STRAT_3.Draw(0xFFF0F0F0, 0);
Sitkah 29:41e02746041d 2106 STRAT_4.Draw(0xFFF0F0F0, 0);
Sitkah 29:41e02746041d 2107 STRAT_5.Draw(0xFFF0F0F0, 0);
Sitkah 29:41e02746041d 2108 STRAT_6.Draw(0xFFF0F0F0, 0);
Sitkah 29:41e02746041d 2109 STRAT_7.Draw(0xFFF0F0F0, 0);
Sitkah 29:41e02746041d 2110 STRAT_8.Draw(0xFFF0F0F0, 0);
Sitkah 29:41e02746041d 2111 STRAT_9.Draw(0xFFF0F0F0, 0);
Sitkah 29:41e02746041d 2112 STRAT_10.Draw(0xFFF0F0F0, 0);
Sitkah 29:41e02746041d 2113 RETOUR.Draw(0xFFFF0000, 0);
Sitkah 29:41e02746041d 2114
Sitkah 29:41e02746041d 2115 while(Ack_strat == 0)
Sitkah 29:41e02746041d 2116 {
Sitkah 29:41e02746041d 2117 canProcessRx();
Sitkah 29:41e02746041d 2118 CANMessage msgTx=CANMessage();
Sitkah 30:a1e37af4bbde 2119 //msgTx.id=ECRAN_CHOICE_STRAT;
Sitkah 29:41e02746041d 2120 if (RETOUR.Touched())
Sitkah 29:41e02746041d 2121 return -1;
Sitkah 29:41e02746041d 2122 while(RETOUR.Touched());
Sitkah 29:41e02746041d 2123 //////////////////////////////STRATEGIE N°1
Sitkah 29:41e02746041d 2124 if (STRAT_1.Touched()){
Sitkah 29:41e02746041d 2125 Strat = 0;
Sitkah 30:a1e37af4bbde 2126 //msgTx.data[0] = 0x1;
Sitkah 30:a1e37af4bbde 2127 //can2.write(msgTx);
Sitkah 29:41e02746041d 2128 while(STRAT_1.Touched());
Sitkah 29:41e02746041d 2129 Ack_strat =1;
Sitkah 29:41e02746041d 2130 }
Sitkah 29:41e02746041d 2131 /////////////////////////////STRATEGIE N°2
Sitkah 29:41e02746041d 2132 if (STRAT_2.Touched()){
Sitkah 29:41e02746041d 2133 Strat = 1;
Sitkah 30:a1e37af4bbde 2134 //msgTx.data[0] = 0x2;
Sitkah 30:a1e37af4bbde 2135 //can2.write(msgTx);
Sitkah 29:41e02746041d 2136 while(STRAT_2.Touched());
Sitkah 29:41e02746041d 2137 Ack_strat =1;
Sitkah 29:41e02746041d 2138 }
Sitkah 29:41e02746041d 2139 //////////////////////////////STRATEGIE N°3
Sitkah 29:41e02746041d 2140 if (STRAT_3.Touched()){
Sitkah 29:41e02746041d 2141 Strat = 2;
Sitkah 30:a1e37af4bbde 2142 //msgTx.data[0] = 0x3;
Sitkah 30:a1e37af4bbde 2143 //can2.write(msgTx);
Sitkah 29:41e02746041d 2144 while(STRAT_3.Touched());
Sitkah 29:41e02746041d 2145 Ack_strat =1;
Sitkah 29:41e02746041d 2146 }
Sitkah 29:41e02746041d 2147 /////////////////////////////STRATEGIE N°4
Sitkah 29:41e02746041d 2148 if (STRAT_4.Touched()){
Sitkah 29:41e02746041d 2149 Strat = 3;
Sitkah 30:a1e37af4bbde 2150 //msgTx.data[0] = 0x4;
Sitkah 30:a1e37af4bbde 2151 //can2.write(msgTx);
Sitkah 29:41e02746041d 2152 while(STRAT_4.Touched());
Sitkah 29:41e02746041d 2153 Ack_strat =1;
Sitkah 29:41e02746041d 2154 }
Sitkah 29:41e02746041d 2155 ///////////////////////////////STRATEGIE N°5
Sitkah 29:41e02746041d 2156 if (STRAT_5.Touched()){
Sitkah 29:41e02746041d 2157 Strat = 4;
Sitkah 30:a1e37af4bbde 2158 //msgTx.data[0] = 0x5;
Sitkah 30:a1e37af4bbde 2159 //can2.write(msgTx);
Sitkah 29:41e02746041d 2160 while(STRAT_5.Touched());
Sitkah 29:41e02746041d 2161 Ack_strat =1;
Sitkah 29:41e02746041d 2162 }
Sitkah 29:41e02746041d 2163 ////////////////////////////////STRATEGIE N°6
Sitkah 29:41e02746041d 2164 if (STRAT_6.Touched()){
Sitkah 29:41e02746041d 2165 Strat = 5;
Sitkah 30:a1e37af4bbde 2166 //msgTx.data[0] = 0x6;
Sitkah 30:a1e37af4bbde 2167 //can2.write(msgTx);
Sitkah 29:41e02746041d 2168 while(STRAT_6.Touched());
Sitkah 29:41e02746041d 2169 Ack_strat =1;
Sitkah 29:41e02746041d 2170 }
Sitkah 29:41e02746041d 2171 /////////////////////////////////STRATEGIE N°7
Sitkah 29:41e02746041d 2172 if (STRAT_7.Touched()){
Sitkah 29:41e02746041d 2173 Strat = 6;
Sitkah 30:a1e37af4bbde 2174 //msgTx.data[0] = 0x7;
Sitkah 30:a1e37af4bbde 2175 //can2.write(msgTx);
Sitkah 29:41e02746041d 2176 while(STRAT_7.Touched());
Sitkah 29:41e02746041d 2177 Ack_strat =1;
Sitkah 29:41e02746041d 2178 }
Sitkah 29:41e02746041d 2179 /////////////////////////////////STRATEGIE N°8
Sitkah 29:41e02746041d 2180 if (STRAT_8.Touched()){
Sitkah 29:41e02746041d 2181 Strat = 7;
Sitkah 30:a1e37af4bbde 2182 //msgTx.data[0] = 0x8;
Sitkah 30:a1e37af4bbde 2183 //can2.write(msgTx);
Sitkah 29:41e02746041d 2184 while(STRAT_8.Touched());
Sitkah 29:41e02746041d 2185 Ack_strat =1;
Sitkah 29:41e02746041d 2186 }
Sitkah 29:41e02746041d 2187 /////////////////////////////////STRATEGIE N°9
Sitkah 29:41e02746041d 2188 if (STRAT_9.Touched()){
Sitkah 29:41e02746041d 2189 Strat = 8;
Sitkah 30:a1e37af4bbde 2190 //msgTx.data[0] = 0x9;
Sitkah 30:a1e37af4bbde 2191 //can2.write(msgTx);
Sitkah 29:41e02746041d 2192 while(STRAT_9.Touched());
Sitkah 29:41e02746041d 2193 Ack_strat =1;
Sitkah 29:41e02746041d 2194 }
Sitkah 29:41e02746041d 2195 ///////////////////////////////////STRATEGIE N°10
Sitkah 29:41e02746041d 2196 if (STRAT_10.Touched()){
Sitkah 29:41e02746041d 2197 Strat = 9;
Sitkah 30:a1e37af4bbde 2198 //msgTx.data[0] = 0xA;
Sitkah 30:a1e37af4bbde 2199 //can2.write(msgTx);
Sitkah 29:41e02746041d 2200 while(STRAT_10.Touched());
Sitkah 29:41e02746041d 2201 Ack_strat =1;
Sitkah 29:41e02746041d 2202 }
Sitkah 29:41e02746041d 2203
Sitkah 29:41e02746041d 2204 }
Sitkah 29:41e02746041d 2205 return Strat;
Sitkah 29:41e02746041d 2206
Sitkah 29:41e02746041d 2207 }
Sitkah 29:41e02746041d 2208
Sitkah 29:41e02746041d 2209 void affichage_compteur (int nombre)
Sitkah 29:41e02746041d 2210 {
Sitkah 38:76f886a1c8e6 2211 int dizaine=0,unite=0,centaine=0;
Sitkah 38:76f886a1c8e6 2212 centaine=nombre/100;
Sitkah 29:41e02746041d 2213 dizaine = nombre/10;
Sitkah 29:41e02746041d 2214 unite = nombre-(10*dizaine);
Sitkah 38:76f886a1c8e6 2215 print_segment(unite,-50);
Sitkah 38:76f886a1c8e6 2216 print_segment(dizaine,125);
Sitkah 38:76f886a1c8e6 2217 if(centaine!=0){
Sitkah 38:76f886a1c8e6 2218 print_segment(centaine,350);
Sitkah 38:76f886a1c8e6 2219 }
Sitkah 29:41e02746041d 2220
Sitkah 29:41e02746041d 2221 }
Sitkah 29:41e02746041d 2222
Sitkah 29:41e02746041d 2223
Sitkah 29:41e02746041d 2224 //****print_segment***
Sitkah 29:41e02746041d 2225 //Dessine en 7 segment le nombre en parametre
Sitkah 29:41e02746041d 2226 // A
Sitkah 29:41e02746041d 2227 // =====
Sitkah 29:41e02746041d 2228 // | |
Sitkah 29:41e02746041d 2229 // B | G | E
Sitkah 29:41e02746041d 2230 // |=====|
Sitkah 29:41e02746041d 2231 // C | | F
Sitkah 29:41e02746041d 2232 // | |
Sitkah 29:41e02746041d 2233 // =====
Sitkah 29:41e02746041d 2234 // D
Sitkah 29:41e02746041d 2235 /*
Sitkah 29:41e02746041d 2236 position pour le chiffre des unites
Sitkah 29:41e02746041d 2237 lcd.FillRect(460,75,120,25);// A
Sitkah 29:41e02746041d 2238 lcd.FillRect(435,100,25,120);// B
Sitkah 29:41e02746041d 2239 lcd.FillRect(435,245,25,120);// C
Sitkah 29:41e02746041d 2240 lcd.FillRect(460,365,120,25);// D
Sitkah 29:41e02746041d 2241 lcd.FillRect(580,100,25,120);// E
Sitkah 29:41e02746041d 2242 lcd.FillRect(580,245,25,120);// F
Sitkah 29:41e02746041d 2243 lcd.FillRect(460,220,120,25);// G
Sitkah 29:41e02746041d 2244
Sitkah 29:41e02746041d 2245 position pour le chiffre des dizaines
Sitkah 29:41e02746041d 2246 lcd.FillRect(260,75,120,25);// A
Sitkah 29:41e02746041d 2247 lcd.FillRect(235,100,25,120);// B
Sitkah 29:41e02746041d 2248 lcd.FillRect(235,245,25,120);// C
Sitkah 29:41e02746041d 2249 lcd.FillRect(260,365,120,25);// D
Sitkah 29:41e02746041d 2250 lcd.FillRect(380,100,25,120);// E
Sitkah 29:41e02746041d 2251 lcd.FillRect(380,245,25,120);// F
Sitkah 29:41e02746041d 2252 lcd.FillRect(260,220,120,25);// G
Sitkah 29:41e02746041d 2253 */
Sitkah 29:41e02746041d 2254
Sitkah 29:41e02746041d 2255 void print_segment(int nombre, int decalage)
Sitkah 29:41e02746041d 2256 {
Sitkah 38:76f886a1c8e6 2257
Sitkah 29:41e02746041d 2258 switch(nombre)
Sitkah 29:41e02746041d 2259 {
Sitkah 29:41e02746041d 2260 case 0:
Sitkah 29:41e02746041d 2261 lcd.FillRect(240-decalage,75,120,25);
Sitkah 29:41e02746041d 2262 lcd.FillRect(215-decalage,100,25,120);
Sitkah 29:41e02746041d 2263 lcd.FillRect(215-decalage,245,25,120);
Sitkah 29:41e02746041d 2264 lcd.FillRect(360-decalage,245,25,120);
Sitkah 29:41e02746041d 2265 lcd.FillRect(360-decalage,100,25,120);
Sitkah 29:41e02746041d 2266 lcd.FillRect(240-decalage,365,120,25);
Sitkah 29:41e02746041d 2267 break;
Sitkah 29:41e02746041d 2268
Sitkah 29:41e02746041d 2269 case 1:
Sitkah 29:41e02746041d 2270 lcd.FillRect(360-decalage,100,25,120);// E
Sitkah 29:41e02746041d 2271 lcd.FillRect(360-decalage,245,25,120);// F
Sitkah 29:41e02746041d 2272 break;
Sitkah 29:41e02746041d 2273
Sitkah 29:41e02746041d 2274 case 2:
Sitkah 29:41e02746041d 2275 lcd.FillRect(240-decalage,75,120,25);// A
Sitkah 29:41e02746041d 2276 lcd.FillRect(215-decalage,245,25,120);// C
Sitkah 29:41e02746041d 2277 lcd.FillRect(240-decalage,365,120,25);// D
Sitkah 29:41e02746041d 2278 lcd.FillRect(360-decalage,100,25,120);// E
Sitkah 29:41e02746041d 2279 lcd.FillRect(240-decalage,220,120,25);// G
Sitkah 29:41e02746041d 2280 break;
Sitkah 29:41e02746041d 2281
Sitkah 29:41e02746041d 2282 case 3:
Sitkah 29:41e02746041d 2283 lcd.FillRect(240-decalage,75,120,25);// A
Sitkah 29:41e02746041d 2284 lcd.FillRect(360-decalage,100,25,120);// E
Sitkah 29:41e02746041d 2285 lcd.FillRect(240-decalage,220,120,25);// G
Sitkah 29:41e02746041d 2286 lcd.FillRect(240-decalage,365,120,25);// D
Sitkah 29:41e02746041d 2287 lcd.FillRect(360-decalage,245,25,120);// F
Sitkah 29:41e02746041d 2288 break;
Sitkah 29:41e02746041d 2289
Sitkah 29:41e02746041d 2290 case 4:
Sitkah 29:41e02746041d 2291 lcd.FillRect(215-decalage,100,25,120);// B
Sitkah 29:41e02746041d 2292 lcd.FillRect(360-decalage,100,25,120);// E
Sitkah 29:41e02746041d 2293 lcd.FillRect(360-decalage,245,25,120);// F
Sitkah 29:41e02746041d 2294 lcd.FillRect(240-decalage,220,120,25);// G
Sitkah 29:41e02746041d 2295 break;
Sitkah 29:41e02746041d 2296
Sitkah 29:41e02746041d 2297 case 5:
Sitkah 29:41e02746041d 2298 lcd.FillRect(240-decalage,75,120,25);// A
Sitkah 29:41e02746041d 2299 lcd.FillRect(215-decalage,100,25,120);// B
Sitkah 29:41e02746041d 2300 lcd.FillRect(240-decalage,220,120,25);// G
Sitkah 29:41e02746041d 2301 lcd.FillRect(240-decalage,365,120,25);// D
Sitkah 29:41e02746041d 2302 lcd.FillRect(360-decalage,245,25,120);// F
Sitkah 29:41e02746041d 2303 break;
Sitkah 29:41e02746041d 2304
Sitkah 29:41e02746041d 2305 case 6:
Sitkah 29:41e02746041d 2306 lcd.FillRect(240-decalage,75,120,25);// A
Sitkah 29:41e02746041d 2307 lcd.FillRect(215-decalage,100,25,120);// B
Sitkah 29:41e02746041d 2308 lcd.FillRect(215-decalage,245,25,120);// C
Sitkah 29:41e02746041d 2309 lcd.FillRect(240-decalage,365,120,25);// D
Sitkah 29:41e02746041d 2310 lcd.FillRect(360-decalage,245,25,120);// F
Sitkah 29:41e02746041d 2311 lcd.FillRect(240-decalage,220,120,25);// G
Sitkah 29:41e02746041d 2312 break;
Sitkah 29:41e02746041d 2313
Sitkah 29:41e02746041d 2314 case 7:
Sitkah 29:41e02746041d 2315 lcd.FillRect(240-decalage,75,120,25);// A
Sitkah 29:41e02746041d 2316 lcd.FillRect(360-decalage,100,25,120);// E
Sitkah 29:41e02746041d 2317 lcd.FillRect(360-decalage,245,25,120);// F
Sitkah 29:41e02746041d 2318 break;
Sitkah 29:41e02746041d 2319
Sitkah 29:41e02746041d 2320 case 8:
Sitkah 29:41e02746041d 2321 lcd.FillRect(240-decalage,75,120,25); // A
Sitkah 29:41e02746041d 2322 lcd.FillRect(215-decalage,100,25,120);
Sitkah 29:41e02746041d 2323 lcd.FillRect(215-decalage,245,25,120);
Sitkah 29:41e02746041d 2324 lcd.FillRect(360-decalage,245,25,120);//...
Sitkah 29:41e02746041d 2325 lcd.FillRect(360-decalage,100,25,120);
Sitkah 29:41e02746041d 2326 lcd.FillRect(240-decalage,365,120,25);
Sitkah 29:41e02746041d 2327 lcd.FillRect(240-decalage,220,120,25);// G
Sitkah 29:41e02746041d 2328 break;
Sitkah 29:41e02746041d 2329
Sitkah 29:41e02746041d 2330 case 9:
Sitkah 29:41e02746041d 2331 lcd.FillRect(240-decalage,75,120,25);// A
Sitkah 29:41e02746041d 2332 lcd.FillRect(215-decalage,100,25,120);// B
Sitkah 29:41e02746041d 2333 lcd.FillRect(240-decalage,365,120,25);// D
Sitkah 29:41e02746041d 2334 lcd.FillRect(360-decalage,100,25,120);// E
Sitkah 29:41e02746041d 2335 lcd.FillRect(360-decalage,245,25,120);// F
Sitkah 29:41e02746041d 2336 lcd.FillRect(240-decalage,220,120,25);// G
Sitkah 29:41e02746041d 2337 break;
Sitkah 29:41e02746041d 2338 }
Sitkah 29:41e02746041d 2339 }
Sitkah 29:41e02746041d 2340
Sitkah 29:41e02746041d 2341 void effacer_segment(long couleur)
Sitkah 29:41e02746041d 2342 {
Sitkah 29:41e02746041d 2343 lcd.SetTextColor(couleur);
Sitkah 29:41e02746041d 2344 lcd.FillRect(240-200,75,120,25); // A
Sitkah 29:41e02746041d 2345 lcd.FillRect(215-200,100,25,120);
Sitkah 29:41e02746041d 2346 lcd.FillRect(215-200,245,25,120);
Sitkah 29:41e02746041d 2347 lcd.FillRect(360-200,245,25,120);//...
Sitkah 29:41e02746041d 2348 lcd.FillRect(360-200,100,25,120);
Sitkah 29:41e02746041d 2349 lcd.FillRect(240-200,365,120,25);
Sitkah 29:41e02746041d 2350 lcd.FillRect(240-200,220,120,25);// G
Sitkah 29:41e02746041d 2351
Sitkah 29:41e02746041d 2352 lcd.FillRect(240,75,120,25); // A
Sitkah 29:41e02746041d 2353 lcd.FillRect(215,100,25,120);
Sitkah 29:41e02746041d 2354 lcd.FillRect(215,245,25,120);
Sitkah 29:41e02746041d 2355 lcd.FillRect(360,245,25,120);//...
Sitkah 29:41e02746041d 2356 lcd.FillRect(360,100,25,120);
Sitkah 29:41e02746041d 2357 lcd.FillRect(240,365,120,25);
Sitkah 29:41e02746041d 2358 lcd.FillRect(240,220,120,25);// G
Sitkah 29:41e02746041d 2359 }
Sitkah 36:6dd30780bd8e 2360
Sitkah 36:6dd30780bd8e 2361 short recalageAngulaireCapteur(void)
Sitkah 36:6dd30780bd8e 2362 {
Sitkah 36:6dd30780bd8e 2363 unsigned char nombresDeMesuresAuxTelemetresQuiSontCoherentes = 0;
Sitkah 36:6dd30780bd8e 2364 unsigned int moyennageTelemetre = 0;
Sitkah 36:6dd30780bd8e 2365 unsigned short angleAvant = 0;
Sitkah 36:6dd30780bd8e 2366 unsigned short angleArriere = 0;
Sitkah 36:6dd30780bd8e 2367 unsigned short orientationArrondie = 0;
Sitkah 36:6dd30780bd8e 2368
Sitkah 36:6dd30780bd8e 2369 unsigned short position_avant_gauche=0;
Sitkah 36:6dd30780bd8e 2370 unsigned short position_avant_droite=0;
Sitkah 36:6dd30780bd8e 2371 unsigned short position_arriere_gauche=0;
Sitkah 36:6dd30780bd8e 2372 unsigned short position_arriere_droite=0;
Sitkah 36:6dd30780bd8e 2373
Sitkah 36:6dd30780bd8e 2374 if(theta_robot >= 450 && theta_robot <= 1350)
Sitkah 36:6dd30780bd8e 2375 orientationArrondie = 90;
Sitkah 36:6dd30780bd8e 2376 else if(theta_robot <= -450 && theta_robot >= -1350)
Sitkah 36:6dd30780bd8e 2377 orientationArrondie = 270;
Sitkah 36:6dd30780bd8e 2378 else if(theta_robot <= 450 && theta_robot >= -450)
Sitkah 36:6dd30780bd8e 2379 orientationArrondie = 0;
Sitkah 36:6dd30780bd8e 2380 else if(theta_robot >= 1350 && theta_robot <= -1350)
Sitkah 36:6dd30780bd8e 2381 orientationArrondie = 180;
Sitkah 36:6dd30780bd8e 2382
Sitkah 36:6dd30780bd8e 2383 // Calcul de position pour faire la vérification de cohérence
Sitkah 36:6dd30780bd8e 2384 if(orientationArrondie == 90 || orientationArrondie == 270)
Sitkah 36:6dd30780bd8e 2385 {
Sitkah 36:6dd30780bd8e 2386 position_avant_gauche = (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?3000:0) + (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?-1:1)*telemetreDistance_avant_gauche;
Sitkah 36:6dd30780bd8e 2387 position_avant_droite = (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?3000:0) + (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?-1:1)*telemetreDistance_avant_droite;
Sitkah 36:6dd30780bd8e 2388 position_arriere_gauche = (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?0:3000) + (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?1:-1)*telemetreDistance_arriere_gauche;
Sitkah 36:6dd30780bd8e 2389 position_arriere_droite = (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?0:3000) + (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?1:-1)*telemetreDistance_arriere_droite;
Sitkah 36:6dd30780bd8e 2390
Sitkah 36:6dd30780bd8e 2391 }
Sitkah 36:6dd30780bd8e 2392 else if(orientationArrondie == 0 || orientationArrondie == 180)
Sitkah 36:6dd30780bd8e 2393 {
Sitkah 36:6dd30780bd8e 2394 position_avant_gauche = ((theta_robot < 900 && theta_robot > -900)?2000:0) + ((theta_robot < 900 && theta_robot > -900)?-1:1)*telemetreDistance_avant_gauche;
Sitkah 36:6dd30780bd8e 2395 position_avant_droite = ((theta_robot < 900 && theta_robot > -900)?2000:0) + ((theta_robot < 900 && theta_robot > -900)?-1:1)*telemetreDistance_avant_droite;
Sitkah 36:6dd30780bd8e 2396 position_arriere_gauche = ((theta_robot < 900 && theta_robot > -900)?0:2000) + ((theta_robot < 900 && theta_robot > -900)?1:-1)*telemetreDistance_arriere_gauche;
Sitkah 36:6dd30780bd8e 2397 position_arriere_droite = ((theta_robot < 900 && theta_robot > -900)?0:2000) + ((theta_robot < 900 && theta_robot > -900)?1:-1)*telemetreDistance_arriere_droite;
Sitkah 36:6dd30780bd8e 2398 }
Sitkah 36:6dd30780bd8e 2399
Sitkah 36:6dd30780bd8e 2400
Sitkah 36:6dd30780bd8e 2401 if(orientationArrondie == 90 || orientationArrondie == 270) // Si il est en axe Y
Sitkah 36:6dd30780bd8e 2402 {
Sitkah 36:6dd30780bd8e 2403 if(position_arriere_droite >= y_robot-instruction.arg1 && position_arriere_droite <= y_robot+instruction.arg1) // Et que les mesures sont cohérentes
Sitkah 36:6dd30780bd8e 2404 {
Sitkah 36:6dd30780bd8e 2405 if(position_arriere_gauche >= y_robot-instruction.arg1 && position_arriere_gauche <= y_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2406 {
Sitkah 36:6dd30780bd8e 2407 if(telemetreDistance_arriere_droite > telemetreDistance_arriere_gauche)
Sitkah 36:6dd30780bd8e 2408 angleArriere =900+(1800 * atan2((double)(telemetreDistance_arriere_droite-telemetreDistance_arriere_gauche) , (double)ESPACE_INTER_TELEMETRE ))/M_PI;
Sitkah 36:6dd30780bd8e 2409 else
Sitkah 36:6dd30780bd8e 2410 angleArriere =(1800 * atan2( (double) ESPACE_INTER_TELEMETRE,(double) (telemetreDistance_arriere_gauche-telemetreDistance_arriere_droite) ))/M_PI;
Sitkah 36:6dd30780bd8e 2411
Sitkah 36:6dd30780bd8e 2412 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2413 moyennageTelemetre += angleArriere;
Sitkah 36:6dd30780bd8e 2414 }
Sitkah 36:6dd30780bd8e 2415 }
Sitkah 36:6dd30780bd8e 2416 }
Sitkah 36:6dd30780bd8e 2417 else if(orientationArrondie == 0 || orientationArrondie == 180) // Si il est en axe X
Sitkah 36:6dd30780bd8e 2418 {
Sitkah 36:6dd30780bd8e 2419 if(position_arriere_droite >= x_robot-instruction.arg1 && position_arriere_droite <= x_robot+instruction.arg1) // Et que les mesures sont cohérentes
Sitkah 36:6dd30780bd8e 2420 {
Sitkah 36:6dd30780bd8e 2421 if(position_arriere_gauche >= x_robot-instruction.arg1 && position_arriere_gauche <= x_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2422 {
Sitkah 36:6dd30780bd8e 2423 if(telemetreDistance_arriere_droite > telemetreDistance_arriere_gauche)
Sitkah 36:6dd30780bd8e 2424 angleArriere =900+(1800 * atan2( (double) (telemetreDistance_arriere_droite-telemetreDistance_arriere_gauche) , (double) ESPACE_INTER_TELEMETRE ))/M_PI;
Sitkah 36:6dd30780bd8e 2425 else
Sitkah 36:6dd30780bd8e 2426 angleArriere =(1800 * atan2( (double) ESPACE_INTER_TELEMETRE,(double) (telemetreDistance_arriere_gauche-telemetreDistance_arriere_droite) ))/M_PI;
Sitkah 36:6dd30780bd8e 2427
Sitkah 36:6dd30780bd8e 2428 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2429 moyennageTelemetre += angleArriere;
Sitkah 36:6dd30780bd8e 2430 }
Sitkah 36:6dd30780bd8e 2431 }
Sitkah 36:6dd30780bd8e 2432 }
Sitkah 36:6dd30780bd8e 2433
Sitkah 36:6dd30780bd8e 2434 if(orientationArrondie == 90 || orientationArrondie == 270) // Si il est en axe Y
Sitkah 36:6dd30780bd8e 2435 {
Sitkah 36:6dd30780bd8e 2436 if(position_avant_droite >= y_robot-instruction.arg1 && position_avant_droite <= y_robot+instruction.arg1) // Et que les mesures sont cohérentes
Sitkah 36:6dd30780bd8e 2437 {
Sitkah 36:6dd30780bd8e 2438 if(position_avant_gauche >= y_robot-instruction.arg1 && position_avant_gauche <= y_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2439 {
Sitkah 36:6dd30780bd8e 2440 if(telemetreDistance_avant_droite > telemetreDistance_avant_gauche)
Sitkah 36:6dd30780bd8e 2441 angleAvant = (1800 * atan2( (double) ESPACE_INTER_TELEMETRE,(double) (telemetreDistance_avant_droite-telemetreDistance_avant_gauche) ))/M_PI;
Sitkah 36:6dd30780bd8e 2442 else
Sitkah 36:6dd30780bd8e 2443 angleAvant = 900 + (1800 * atan2( (double)( telemetreDistance_avant_gauche-telemetreDistance_avant_droite) ,(double) ESPACE_INTER_TELEMETRE ))/M_PI;
Sitkah 36:6dd30780bd8e 2444
Sitkah 36:6dd30780bd8e 2445 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2446 moyennageTelemetre += angleAvant;
Sitkah 36:6dd30780bd8e 2447 }
Sitkah 36:6dd30780bd8e 2448 }
Sitkah 36:6dd30780bd8e 2449 }
Sitkah 36:6dd30780bd8e 2450 else if(orientationArrondie == 0 || orientationArrondie == 180) // Si il est en axe X
Sitkah 36:6dd30780bd8e 2451 {
Sitkah 36:6dd30780bd8e 2452 if(position_avant_droite >= x_robot-instruction.arg1 && position_avant_droite <= x_robot+instruction.arg1) // Et que les mesures sont cohérentes
Sitkah 36:6dd30780bd8e 2453 {
Sitkah 36:6dd30780bd8e 2454 if(position_avant_gauche >= x_robot-instruction.arg1 && position_avant_gauche <= x_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2455 {
Sitkah 36:6dd30780bd8e 2456 if(telemetreDistance_avant_droite > telemetreDistance_avant_gauche)
Sitkah 36:6dd30780bd8e 2457 angleAvant = (1800 * atan2((double) ESPACE_INTER_TELEMETRE, (double) (telemetreDistance_avant_droite-telemetreDistance_avant_gauche) ))/M_PI;
Sitkah 36:6dd30780bd8e 2458 else
Sitkah 36:6dd30780bd8e 2459 angleAvant = 900 + (1800 * atan2( (double) (telemetreDistance_avant_gauche-telemetreDistance_avant_droite) ,(double) ESPACE_INTER_TELEMETRE ))/M_PI;
Sitkah 36:6dd30780bd8e 2460
Sitkah 36:6dd30780bd8e 2461 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2462 moyennageTelemetre += angleAvant;
Sitkah 36:6dd30780bd8e 2463 }
Sitkah 36:6dd30780bd8e 2464 }
Sitkah 36:6dd30780bd8e 2465 }
Sitkah 36:6dd30780bd8e 2466
Sitkah 36:6dd30780bd8e 2467 angleRecalage = moyennageTelemetre/nombresDeMesuresAuxTelemetresQuiSontCoherentes;
Sitkah 36:6dd30780bd8e 2468
Sitkah 36:6dd30780bd8e 2469
Sitkah 36:6dd30780bd8e 2470
Sitkah 36:6dd30780bd8e 2471 if(nombresDeMesuresAuxTelemetresQuiSontCoherentes)
Sitkah 36:6dd30780bd8e 2472 {
Sitkah 36:6dd30780bd8e 2473 if(orientationArrondie == 0)
Sitkah 36:6dd30780bd8e 2474 {
Sitkah 36:6dd30780bd8e 2475 angleRecalage -= 900;
Sitkah 36:6dd30780bd8e 2476
Sitkah 36:6dd30780bd8e 2477 /*if(telemetreDistance_avant_droite > telemetreDistance_avant_gauche)
Sitkah 36:6dd30780bd8e 2478 distanceRecalage = *);
Sitkah 36:6dd30780bd8e 2479 else
Sitkah 36:6dd30780bd8e 2480 distanceRecalage = 900 + (1800 * atan( (double)( (telemetreDistance_avant_droite-telemetreDistance_avant_gauche) / ESPACE_INTER_TELEMETRE )))/M_PI;*/
Sitkah 36:6dd30780bd8e 2481 }
Sitkah 36:6dd30780bd8e 2482 else if(orientationArrondie == 90)
Sitkah 36:6dd30780bd8e 2483 {
Sitkah 36:6dd30780bd8e 2484 angleRecalage += 0;
Sitkah 36:6dd30780bd8e 2485 }
Sitkah 36:6dd30780bd8e 2486 else if(orientationArrondie == 180)
Sitkah 36:6dd30780bd8e 2487 {
Sitkah 36:6dd30780bd8e 2488 angleRecalage += 900;
Sitkah 36:6dd30780bd8e 2489 }
Sitkah 36:6dd30780bd8e 2490 else if(orientationArrondie == 270)
Sitkah 36:6dd30780bd8e 2491 {
Sitkah 36:6dd30780bd8e 2492 angleRecalage += 1800;
Sitkah 36:6dd30780bd8e 2493 }
Sitkah 36:6dd30780bd8e 2494 }
Sitkah 36:6dd30780bd8e 2495
Sitkah 36:6dd30780bd8e 2496 return (nombresDeMesuresAuxTelemetresQuiSontCoherentes && (angleAvant-angleArriere<80 && angleAvant-angleArriere>-80)) ? angleRecalage : theta_robot;
Sitkah 36:6dd30780bd8e 2497 }
Sitkah 36:6dd30780bd8e 2498
Sitkah 36:6dd30780bd8e 2499 short recalageDistanceX(void)
Sitkah 36:6dd30780bd8e 2500 {
Sitkah 36:6dd30780bd8e 2501 unsigned char nombresDeMesuresAuxTelemetresQuiSontCoherentes = 0;
Sitkah 36:6dd30780bd8e 2502 unsigned int moyennageTelemetre = 0;
Sitkah 36:6dd30780bd8e 2503
Sitkah 36:6dd30780bd8e 2504 telemetreDistance_avant_gauche = ((theta_robot < 900 && theta_robot > -900)?2000:0) + ((theta_robot < 900 && theta_robot > -900)?-1:1)*telemetreDistance_avant_gauche;
Sitkah 36:6dd30780bd8e 2505 telemetreDistance_avant_droite = ((theta_robot < 900 && theta_robot > -900)?2000:0) + ((theta_robot < 900 && theta_robot > -900)?-1:1)*telemetreDistance_avant_droite;
Sitkah 36:6dd30780bd8e 2506 telemetreDistance_arriere_gauche = ((theta_robot < 900 && theta_robot > -900)?0:2000) + ((theta_robot < 900 && theta_robot > -900)?1:-1)*telemetreDistance_arriere_gauche;
Sitkah 36:6dd30780bd8e 2507 telemetreDistance_arriere_droite = ((theta_robot < 900 && theta_robot > -900)?0:2000) + ((theta_robot < 900 && theta_robot > -900)?1:-1)*telemetreDistance_arriere_droite;
Sitkah 36:6dd30780bd8e 2508
Sitkah 36:6dd30780bd8e 2509 if(telemetreDistance_avant_gauche >= x_robot-instruction.arg1 && telemetreDistance_avant_gauche <= x_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2510 {
Sitkah 36:6dd30780bd8e 2511 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2512 moyennageTelemetre += telemetreDistance_avant_gauche;
Sitkah 36:6dd30780bd8e 2513 }
Sitkah 36:6dd30780bd8e 2514 if(telemetreDistance_avant_droite >= x_robot-instruction.arg1 && telemetreDistance_avant_droite <= x_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2515 {
Sitkah 36:6dd30780bd8e 2516 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2517 moyennageTelemetre += telemetreDistance_avant_droite;
Sitkah 36:6dd30780bd8e 2518 }
Sitkah 36:6dd30780bd8e 2519 if(telemetreDistance_arriere_gauche >= x_robot-instruction.arg1 && telemetreDistance_arriere_gauche <= x_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2520 {
Sitkah 36:6dd30780bd8e 2521 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2522 moyennageTelemetre += telemetreDistance_arriere_gauche;
Sitkah 36:6dd30780bd8e 2523 }
Sitkah 36:6dd30780bd8e 2524 if(telemetreDistance_arriere_droite >= x_robot-instruction.arg1 && telemetreDistance_arriere_droite <= x_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2525 {
Sitkah 36:6dd30780bd8e 2526 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2527 moyennageTelemetre += telemetreDistance_arriere_droite;
Sitkah 36:6dd30780bd8e 2528 }
Sitkah 36:6dd30780bd8e 2529
Sitkah 36:6dd30780bd8e 2530 moyennageTelemetre /= nombresDeMesuresAuxTelemetresQuiSontCoherentes;
Sitkah 36:6dd30780bd8e 2531
Sitkah 36:6dd30780bd8e 2532 return (nombresDeMesuresAuxTelemetresQuiSontCoherentes)? moyennageTelemetre : x_robot; //SetOdometrie(ODOMETRIE_SMALL_POSITION, moyennageTelemetre, y_robot, theta_robot);
Sitkah 36:6dd30780bd8e 2533 }
Sitkah 36:6dd30780bd8e 2534
Sitkah 36:6dd30780bd8e 2535 short recalageDistanceY(void)
Sitkah 36:6dd30780bd8e 2536 {
Sitkah 36:6dd30780bd8e 2537 unsigned char nombresDeMesuresAuxTelemetresQuiSontCoherentes = 0;
Sitkah 36:6dd30780bd8e 2538 unsigned int moyennageTelemetre = 0;
Sitkah 36:6dd30780bd8e 2539
Sitkah 36:6dd30780bd8e 2540 telemetreDistance_avant_gauche = (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?3000:0) + (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?-1:1)*telemetreDistance_avant_gauche;
Sitkah 36:6dd30780bd8e 2541 telemetreDistance_avant_droite = (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?3000:0) + (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?-1:1)*telemetreDistance_avant_droite;
Sitkah 36:6dd30780bd8e 2542 telemetreDistance_arriere_gauche = (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?0:3000) + (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?1:-1)*telemetreDistance_arriere_gauche;
Sitkah 36:6dd30780bd8e 2543 telemetreDistance_arriere_droite = (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?0:3000) + (((theta_robot < 1800 && theta_robot > 0) || (theta_robot < -1800 && theta_robot > -3600))?1:-1)*telemetreDistance_arriere_droite;
Sitkah 36:6dd30780bd8e 2544
Sitkah 36:6dd30780bd8e 2545 if(telemetreDistance_avant_gauche >= y_robot-instruction.arg1 && telemetreDistance_avant_gauche <= y_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2546 {
Sitkah 36:6dd30780bd8e 2547 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2548 moyennageTelemetre += telemetreDistance_avant_gauche;
Sitkah 36:6dd30780bd8e 2549 }
Sitkah 36:6dd30780bd8e 2550 if(telemetreDistance_avant_droite >= y_robot-instruction.arg1 && telemetreDistance_avant_droite <= y_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2551 {
Sitkah 36:6dd30780bd8e 2552 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2553 moyennageTelemetre += telemetreDistance_avant_droite;
Sitkah 36:6dd30780bd8e 2554 }
Sitkah 36:6dd30780bd8e 2555 if(telemetreDistance_arriere_gauche >= y_robot-instruction.arg1 && telemetreDistance_arriere_gauche <= y_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2556 {
Sitkah 36:6dd30780bd8e 2557 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2558 moyennageTelemetre += telemetreDistance_arriere_gauche;
Sitkah 36:6dd30780bd8e 2559 }
Sitkah 36:6dd30780bd8e 2560 if(telemetreDistance_arriere_droite >= y_robot-instruction.arg1 && telemetreDistance_arriere_droite <= y_robot+instruction.arg1)
Sitkah 36:6dd30780bd8e 2561 {
Sitkah 36:6dd30780bd8e 2562 nombresDeMesuresAuxTelemetresQuiSontCoherentes++;
Sitkah 36:6dd30780bd8e 2563 moyennageTelemetre += telemetreDistance_arriere_droite;
Sitkah 36:6dd30780bd8e 2564 }
Sitkah 36:6dd30780bd8e 2565
Sitkah 36:6dd30780bd8e 2566 moyennageTelemetre /= nombresDeMesuresAuxTelemetresQuiSontCoherentes;
Sitkah 36:6dd30780bd8e 2567
Sitkah 36:6dd30780bd8e 2568 return (nombresDeMesuresAuxTelemetresQuiSontCoherentes)? moyennageTelemetre : y_robot ; // SetOdometrie(ODOMETRIE_SMALL_POSITION, x_robot, moyennageTelemetre, theta_robot);
Sitkah 36:6dd30780bd8e 2569 }
Sitkah 36:6dd30780bd8e 2570