Programme carte strategie (disco)

Dependencies:   mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac

Committer:
Sitkah
Date:
Tue Apr 24 18:09:51 2018 +0000
Revision:
31:833fc481b002
Parent:
30:a1e37af4bbde
Child:
32:1c9ab15c740e
ne pas utiliser;

Who changed what in which revision?

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