Programme carte strategie (disco)

Dependencies:   mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac

Committer:
Sitkah
Date:
Fri Apr 06 13:47:19 2018 +0000
Revision:
29:41e02746041d
Parent:
28:acd18776ed2d
Child:
30:a1e37af4bbde
version fusionn?e

Who changed what in which revision?

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