code strat avant match 2, strat inversée OK normalement

Fork of CRAC-Strat_2017_fin_premier_match by CRAC Team

Committer:
ClementBreteau
Date:
Thu May 25 17:17:42 2017 +0000
Revision:
24:4a28a72781a6
Parent:
23:ab87d308eaf9
code de strat avant match2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ClementBreteau 14:c8fc06c4887f 1 #include "Strategie.h"
antbig 0:ad97421fb1fb 2
antbig 5:dcd817534b57 3 E_stratGameEtat gameEtat = ETAT_CHECK_CARTE_SCREEN;
antbig 0:ad97421fb1fb 4 E_stratGameEtat lastEtat = ETAT_CHECK_CARTE_SCREEN;
antbig 0:ad97421fb1fb 5 unsigned char screenChecktry = 0;
antbig 0:ad97421fb1fb 6 Timer cartesCheker;//Le timer pour le timeout de la vérification des cartes
antbig 0:ad97421fb1fb 7 Timer fakeJack;
antbig 0:ad97421fb1fb 8 Timer gameTimer;
antbig 0:ad97421fb1fb 9 Timer debugetatTimer;
antbig 5:dcd817534b57 10 Timer timeoutWarning;
antbig 5:dcd817534b57 11 Timer timeoutWarningWaitEnd;
antbig 0:ad97421fb1fb 12 Timeout chronoEnd;//permet d'envoyer la trame CAN pour la fin
antbig 0:ad97421fb1fb 13
antbig 0:ad97421fb1fb 14 unsigned short waitingAckID = 0;//L'id du ack attendu
antbig 0:ad97421fb1fb 15 unsigned short waitingAckFrom = 0;//La provenance du ack attendu
ClementBreteau 14:c8fc06c4887f 16 char modeTelemetre; // Si à 1, indique que l'on attend une reponse du telemetre
ClementBreteau 21:590cdacb6a35 17 unsigned short telemetreDistance = 0;
antbig 0:ad97421fb1fb 18 signed char FIFO_lecture=0;//Position du fifo de lecture des messages CAN
antbig 0:ad97421fb1fb 19
antbig 0:ad97421fb1fb 20 signed short x_robot,y_robot,theta_robot;//La position du robot
antbig 0:ad97421fb1fb 21
antbig 12:14729d584500 22 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
antbig 12:14729d584500 23
antbig 5:dcd817534b57 24 #ifdef ROBOT_BIG
ClementBreteau 14:c8fc06c4887f 25 //unsigned short id_check[NOMBRE_CARTES]= {CHECK_BALISE,CHECK_MOTEUR,CHECK_ACTIONNEURS,CHECK_AX12,CHECK_POMPES};
ClementBreteau 14:c8fc06c4887f 26 //unsigned short id_alive[NOMBRE_CARTES]= {ALIVE_BALISE,ALIVE_MOTEUR,ALIVE_ACTIONNEURS,ALIVE_AX12,ALIVE_POMPES};
ClementBreteau 14:c8fc06c4887f 27
ClementBreteau 23:ab87d308eaf9 28 unsigned short id_check[NOMBRE_CARTES]= {CHECK_MOTEUR,CHECK_BALISE,CHECK_ACTIONNEURS_AVANT,CHECK_ACTIONNEURS_ARRIERE};
ClementBreteau 23:ab87d308eaf9 29 unsigned short id_alive[NOMBRE_CARTES]= {ALIVE_MOTEUR,ALIVE_BALISE,ALIVE_ACTIONNEURS_AVANT,ALIVE_ACTIONNEURS_ARRIERE};
ClementBreteau 15:c2fc239e85df 30
ClementBreteau 15:c2fc239e85df 31 InterruptIn jack(p25); // entrée analogique en interruption pour le jack
ClementBreteau 15:c2fc239e85df 32 #else
ClementBreteau 15:c2fc239e85df 33 //unsigned short id_check[NOMBRE_CARTES]= {CHECK_BALISE,CHECK_MOTEUR,CHECK_ACTIONNEURS};
ClementBreteau 15:c2fc239e85df 34 //unsigned short id_alive[NOMBRE_CARTES]= {ALIVE_BALISE,ALIVE_MOTEUR,ALIVE_ACTIONNEURS};
ClementBreteau 15:c2fc239e85df 35
ClementBreteau 14:c8fc06c4887f 36 unsigned short id_check[NOMBRE_CARTES]= {CHECK_MOTEUR};
ClementBreteau 14:c8fc06c4887f 37 unsigned short id_alive[NOMBRE_CARTES]= {ALIVE_MOTEUR};
ClementBreteau 14:c8fc06c4887f 38
ClementBreteau 18:cc5fec34ed9c 39 InterruptIn jack(p25); // entrée analogique en interruption pour le jack
antbig 5:dcd817534b57 40 #endif
antbig 0:ad97421fb1fb 41 unsigned char checkCurrent = 0;
antbig 0:ad97421fb1fb 42 unsigned char countAliveCard = 0;
antbig 0:ad97421fb1fb 43
antbig 2:8d8e2cf798a3 44 unsigned char InversStrat = 1;//Si à 1, indique que l'on part de l'autre cote de la table(inversion des Y)
antbig 1:116040d14164 45
ClementBreteau 14:c8fc06c4887f 46 unsigned char ModeDemo = 0; // Si à 1, indique que l'on est dans le mode demo
ClementBreteau 14:c8fc06c4887f 47
antbig 5:dcd817534b57 48 unsigned char countRobotNear = 0;//Le nombre de robot à proximité
antbig 5:dcd817534b57 49
antbig 12:14729d584500 50 unsigned char ingnorBaliseOnce = 0;
antbig 12:14729d584500 51
ClementBreteau 14:c8fc06c4887f 52
antbig 4:88431b537477 53 /****************************************************************************************/
antbig 4:88431b537477 54 /* FUNCTION NAME: chronometre_ISR */
antbig 4:88431b537477 55 /* DESCRIPTION : Interruption à la fin des 90s du match */
antbig 4:88431b537477 56 /****************************************************************************************/
antbig 0:ad97421fb1fb 57 void chronometre_ISR (void)
antbig 0:ad97421fb1fb 58 {
antbig 0:ad97421fb1fb 59 SendRawId(ASSERVISSEMENT_STOP);//On stope les moteurs
antbig 0:ad97421fb1fb 60 SendRawId(GLOBAL_GAME_END);//Indication fin de match
antbig 0:ad97421fb1fb 61 gameTimer.stop();//Arret du timer
antbig 0:ad97421fb1fb 62
antbig 1:116040d14164 63 #ifdef ROBOT_BIG
antbig 12:14729d584500 64 wait_ms(2000);
antbig 0:ad97421fb1fb 65 doFunnyAction();
antbig 0:ad97421fb1fb 66 #endif
antbig 0:ad97421fb1fb 67
antbig 1:116040d14164 68 while(1);//On bloque la programme dans l'interruption
antbig 0:ad97421fb1fb 69 }
antbig 0:ad97421fb1fb 70
antbig 4:88431b537477 71 /****************************************************************************************/
antbig 8:0edc7dfb7f7e 72 /* FUNCTION NAME: jack_ISR */
antbig 8:0edc7dfb7f7e 73 /* DESCRIPTION : Interruption en changement d'état sur le Jack */
antbig 8:0edc7dfb7f7e 74 /****************************************************************************************/
antbig 8:0edc7dfb7f7e 75 void jack_ISR (void)
antbig 8:0edc7dfb7f7e 76 {
antbig 8:0edc7dfb7f7e 77 if(gameEtat == ETAT_GAME_WAIT_FOR_JACK) {
antbig 8:0edc7dfb7f7e 78 led4=1;
antbig 8:0edc7dfb7f7e 79 gameEtat = ETAT_GAME_START;//On débute le match
antbig 8:0edc7dfb7f7e 80 }
antbig 8:0edc7dfb7f7e 81 }
antbig 8:0edc7dfb7f7e 82
antbig 8:0edc7dfb7f7e 83 /****************************************************************************************/
antbig 4:88431b537477 84 /* FUNCTION NAME: automate_process */
antbig 4:88431b537477 85 /* DESCRIPTION : Automate de gestion de la stratégie du robot */
antbig 4:88431b537477 86 /****************************************************************************************/
antbig 0:ad97421fb1fb 87 void automate_process(void)
antbig 0:ad97421fb1fb 88 {
antbig 0:ad97421fb1fb 89 static struct S_Instruction instruction;
antbig 1:116040d14164 90 static unsigned char AX12_enchainement = 0;
antbig 1:116040d14164 91 static unsigned char MV_enchainement = 0;
antbig 0:ad97421fb1fb 92 signed char localData1 = 0;
antbig 0:ad97421fb1fb 93 signed short localData2 = 0;
antbig 0:ad97421fb1fb 94 unsigned short localData3 = 0;
ClementBreteau 14:c8fc06c4887f 95 //signed short localData4 = 0;
antbig 1:116040d14164 96 unsigned char localData5 = 0;
antbig 0:ad97421fb1fb 97
antbig 12:14729d584500 98 if(gameTimer.read_ms() >= 89000) {//Fin du match (On autorise 2s pour déposer des éléments
antbig 0:ad97421fb1fb 99 gameTimer.stop();
antbig 0:ad97421fb1fb 100 gameTimer.reset();
antbig 0:ad97421fb1fb 101 gameEtat = ETAT_END;//Fin du temps
antbig 0:ad97421fb1fb 102 }
antbig 0:ad97421fb1fb 103
antbig 0:ad97421fb1fb 104 if(lastEtat != gameEtat || debugetatTimer.read_ms() >= 1000) {
antbig 0:ad97421fb1fb 105 lastEtat = gameEtat;
antbig 0:ad97421fb1fb 106 debugetatTimer.reset();
antbig 11:ed13a480ddca 107 sendStratEtat((unsigned char)gameEtat, (unsigned char)actual_instruction);
antbig 0:ad97421fb1fb 108 }
antbig 0:ad97421fb1fb 109
antbig 0:ad97421fb1fb 110 switch(gameEtat)
antbig 0:ad97421fb1fb 111 {
antbig 0:ad97421fb1fb 112 case ETAT_CHECK_CARTE_SCREEN:
antbig 0:ad97421fb1fb 113 /*
antbig 0:ad97421fb1fb 114 Verification de l'état de la carte ecran
antbig 0:ad97421fb1fb 115 */
antbig 0:ad97421fb1fb 116 waitingAckFrom = ALIVE_IHM;//On indique que l'on attend un ack de la carte IHM
antbig 0:ad97421fb1fb 117 SendRawId(CHECK_IHM);//On demande à la carte IHM d'insiquer ça présence
antbig 0:ad97421fb1fb 118
antbig 0:ad97421fb1fb 119 screenChecktry++;//On incrèment le conteur de tentative de 1
antbig 0:ad97421fb1fb 120 cartesCheker.reset();//On reset le timeOut
antbig 0:ad97421fb1fb 121 cartesCheker.start();//On lance le timer pour le timeout
antbig 0:ad97421fb1fb 122 gameEtat = ETAT_CHECK_CARTE_SCREEN_WAIT_ACK;
antbig 0:ad97421fb1fb 123
ClementBreteau 14:c8fc06c4887f 124 //gameEtat = ETAT_GAME_START;
ClementBreteau 14:c8fc06c4887f 125
antbig 0:ad97421fb1fb 126 break;
antbig 0:ad97421fb1fb 127 case ETAT_CHECK_CARTE_SCREEN_WAIT_ACK:
antbig 0:ad97421fb1fb 128 /*
antbig 0:ad97421fb1fb 129 Attente du ALIVE de la carte écran.
antbig 0:ad97421fb1fb 130
antbig 0:ad97421fb1fb 131 Si la carte ne répond pas apres 10ms, on retoune dans l'etat ETAT_CHECK_CARTE_SCREEN
antbig 0:ad97421fb1fb 132 maximum 3 tentatives
antbig 0:ad97421fb1fb 133 Si pas de réponse, clignotement de toutes les leds possible
antbig 0:ad97421fb1fb 134 */
antbig 0:ad97421fb1fb 135 if(waitingAckFrom == 0) {//C'est bon la carte est en ligne
antbig 0:ad97421fb1fb 136 cartesCheker.stop();
antbig 0:ad97421fb1fb 137 screenChecktry = 0;
antbig 0:ad97421fb1fb 138 gameEtat = ETAT_CHECK_CARTES;
antbig 0:ad97421fb1fb 139 } else if(cartesCheker.read_ms () > 100) {
antbig 0:ad97421fb1fb 140 cartesCheker.stop();
antbig 0:ad97421fb1fb 141 if(screenChecktry >=3) {
antbig 0:ad97421fb1fb 142 errorLoop();//Erreur La carte IHM n'est pas en ligne
antbig 0:ad97421fb1fb 143 } else {
antbig 0:ad97421fb1fb 144 gameEtat = ETAT_CHECK_CARTE_SCREEN;
antbig 0:ad97421fb1fb 145 }
antbig 0:ad97421fb1fb 146 }
antbig 0:ad97421fb1fb 147 break;
antbig 0:ad97421fb1fb 148 case ETAT_CHECK_CARTES:
antbig 0:ad97421fb1fb 149 /*
antbig 0:ad97421fb1fb 150 Il faut faire une boucle pour verifier toutes les cartes les une apres les autres
antbig 0:ad97421fb1fb 151 */
antbig 0:ad97421fb1fb 152 waitingAckFrom = id_alive[checkCurrent];//On indique que l'on attend un ack de la carte IHM
antbig 11:ed13a480ddca 153 SendRawId(id_check[checkCurrent]);//On demande à la carte d'indiquer ça présence
antbig 0:ad97421fb1fb 154
antbig 0:ad97421fb1fb 155 screenChecktry++;//On incrèment le conteur de tentative de 1
antbig 0:ad97421fb1fb 156 cartesCheker.reset();//On reset le timeOut
antbig 0:ad97421fb1fb 157 cartesCheker.start();//On lance le timer pour le timeout
antbig 0:ad97421fb1fb 158 gameEtat = ETAT_CHECK_CARTES_WAIT_ACK;
ClementBreteau 14:c8fc06c4887f 159
ClementBreteau 14:c8fc06c4887f 160
ClementBreteau 14:c8fc06c4887f 161
ClementBreteau 14:c8fc06c4887f 162
antbig 0:ad97421fb1fb 163 break;
antbig 0:ad97421fb1fb 164 case ETAT_CHECK_CARTES_WAIT_ACK:
antbig 0:ad97421fb1fb 165 /*
antbig 0:ad97421fb1fb 166 On attend l'ack de la carte en cours de vérification
antbig 0:ad97421fb1fb 167 */
antbig 0:ad97421fb1fb 168 //printf("cartesCheker = %d waitingAckFrom = %d\n",cartesCheker.read_ms(), waitingAckFrom);
antbig 0:ad97421fb1fb 169 if(waitingAckFrom == 0) {//C'est bon la carte est en ligne
antbig 0:ad97421fb1fb 170 cartesCheker.stop();
antbig 0:ad97421fb1fb 171 screenChecktry = 0;
antbig 0:ad97421fb1fb 172 countAliveCard++;
antbig 11:ed13a480ddca 173 checkCurrent++;
antbig 0:ad97421fb1fb 174 if(checkCurrent >= NOMBRE_CARTES) {
antbig 12:14729d584500 175 //printf("all card check, missing %d cards\n",(NOMBRE_CARTES-countAliveCard));
antbig 0:ad97421fb1fb 176 if(countAliveCard >= NOMBRE_CARTES) {
antbig 0:ad97421fb1fb 177 gameEtat = ETAT_CONFIG;
antbig 0:ad97421fb1fb 178 SendRawId(ECRAN_ALL_CHECK);//On dit à l'IHM que toutes les cartes sont en ligne
antbig 5:dcd817534b57 179 tactile_printf("Selection couleur et strategie");
antbig 0:ad97421fb1fb 180 } else {
antbig 0:ad97421fb1fb 181 gameEtat = ETAT_WAIT_FORCE;//Passage en attente de forçage du lancement
antbig 0:ad97421fb1fb 182 waitingAckFrom = ECRAN_ALL_CHECK;
antbig 0:ad97421fb1fb 183 }
antbig 0:ad97421fb1fb 184 } else {
antbig 0:ad97421fb1fb 185 gameEtat = ETAT_CHECK_CARTES;
antbig 0:ad97421fb1fb 186 }
antbig 0:ad97421fb1fb 187 } else if(cartesCheker.read_ms () > 100) {
antbig 0:ad97421fb1fb 188 cartesCheker.stop();
antbig 0:ad97421fb1fb 189 if(screenChecktry >=3) {
antbig 12:14729d584500 190 //printf("missing card %d\n",id_check[checkCurrent]);
antbig 0:ad97421fb1fb 191 screenChecktry = 0;
antbig 11:ed13a480ddca 192 checkCurrent++;
antbig 12:14729d584500 193
antbig 0:ad97421fb1fb 194 if(checkCurrent >= NOMBRE_CARTES) {
antbig 0:ad97421fb1fb 195 if(countAliveCard == NOMBRE_CARTES) {
antbig 0:ad97421fb1fb 196 gameEtat = ETAT_CONFIG;
antbig 0:ad97421fb1fb 197 SendRawId(ECRAN_ALL_CHECK);//On dit à l'IHM que toutes les cartes sont en ligne
antbig 0:ad97421fb1fb 198 } else {
antbig 0:ad97421fb1fb 199 gameEtat = ETAT_WAIT_FORCE;//Passage en attente de forçage du lancement
antbig 0:ad97421fb1fb 200 waitingAckFrom = ECRAN_ALL_CHECK;
antbig 0:ad97421fb1fb 201 }
antbig 0:ad97421fb1fb 202 } else {
antbig 0:ad97421fb1fb 203 gameEtat = ETAT_CHECK_CARTES;
antbig 0:ad97421fb1fb 204 }
antbig 0:ad97421fb1fb 205 } else {
antbig 0:ad97421fb1fb 206 gameEtat = ETAT_CHECK_CARTES;
antbig 0:ad97421fb1fb 207 }
antbig 0:ad97421fb1fb 208 }
antbig 0:ad97421fb1fb 209 break;
antbig 0:ad97421fb1fb 210 case ETAT_WAIT_FORCE:
antbig 0:ad97421fb1fb 211 /*
antbig 0:ad97421fb1fb 212 Attente du forçage de la part de la carte IHM
antbig 0:ad97421fb1fb 213 */
antbig 0:ad97421fb1fb 214 if(waitingAckFrom == 0) {
antbig 0:ad97421fb1fb 215 gameEtat = ETAT_CONFIG;
antbig 0:ad97421fb1fb 216 }
antbig 0:ad97421fb1fb 217 break;
antbig 0:ad97421fb1fb 218 case ETAT_CONFIG:
antbig 0:ad97421fb1fb 219 /*
antbig 0:ad97421fb1fb 220 Attente de l'odre de choix de mode,
antbig 0:ad97421fb1fb 221 Il est possible de modifier la couleur et l'id de la stratégie
antbig 0:ad97421fb1fb 222 Il est aussi possible d'envoyer les ordres de debug
antbig 0:ad97421fb1fb 223 */
ClementBreteau 14:c8fc06c4887f 224 modeTelemetre = 0;
antbig 0:ad97421fb1fb 225 break;
antbig 1:116040d14164 226 case ETAT_GAME_INIT:
antbig 0:ad97421fb1fb 227 //On charge la liste des instructions
antbig 0:ad97421fb1fb 228 loadAllInstruction();//Mise en cache de toute les instructions
ClementBreteau 14:c8fc06c4887f 229
antbig 0:ad97421fb1fb 230 gameEtat = ETAT_GAME_WAIT_FOR_JACK;
antbig 0:ad97421fb1fb 231 SendRawId(ECRAN_ACK_START_MATCH);
antbig 0:ad97421fb1fb 232 tactile_printf("Attente du JACK.");
antbig 12:14729d584500 233 setAsservissementEtat(1);//On réactive l'asservissement
antbig 12:14729d584500 234 jack.mode(PullDown); // désactivation de la résistance interne du jack
antbig 8:0edc7dfb7f7e 235 jack.fall(&jack_ISR); // création de l'interrupt attachée au changement d'état (front descendant) sur le jack
antbig 12:14729d584500 236
antbig 12:14729d584500 237 #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 238 localData2 = POSITION_DEBUT_T;
antbig 12:14729d584500 239 localData3 = POSITION_DEBUT_Y;
antbig 12:14729d584500 240 if(InversStrat == 1) {
antbig 12:14729d584500 241 localData2 = -localData2;//Inversion theta
antbig 12:14729d584500 242 localData3 = 3000 - POSITION_DEBUT_Y;//Inversion du Y
antbig 12:14729d584500 243 }
antbig 12:14729d584500 244 SetOdometrie(ODOMETRIE_BIG_POSITION, POSITION_DEBUT_X,localData3,localData2);
ClementBreteau 18:cc5fec34ed9c 245 #endif
ClementBreteau 18:cc5fec34ed9c 246 #ifdef ROBOT_SMALL
clementlignie 22:a466d08ac42b 247 localData2 = POSITION_DEBUT_T;
clementlignie 22:a466d08ac42b 248 localData3 = POSITION_DEBUT_Y;
clementlignie 22:a466d08ac42b 249 if(InversStrat == 1) {
clementlignie 22:a466d08ac42b 250 localData2 = -localData2;//Inversion theta
clementlignie 22:a466d08ac42b 251 localData3 = 3000 - POSITION_DEBUT_Y;//Inversion du Y
clementlignie 22:a466d08ac42b 252 }
clementlignie 22:a466d08ac42b 253 SetOdometrie(ODOMETRIE_SMALL_POSITION, POSITION_DEBUT_X,localData3,localData2);
ClementBreteau 18:cc5fec34ed9c 254 #endif
antbig 0:ad97421fb1fb 255 break;
antbig 0:ad97421fb1fb 256 case ETAT_GAME_WAIT_FOR_JACK:
antbig 12:14729d584500 257 //On attend le jack
antbig 1:116040d14164 258 break;
antbig 1:116040d14164 259 case ETAT_GAME_START:
antbig 1:116040d14164 260 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
ClementBreteau 14:c8fc06c4887f 261
ClementBreteau 14:c8fc06c4887f 262 if (ModeDemo == 0){
ClementBreteau 14:c8fc06c4887f 263 chronoEnd.attach(&chronometre_ISR,90);//On lance le chrono de 90s
ClementBreteau 14:c8fc06c4887f 264 gameTimer.start();
ClementBreteau 14:c8fc06c4887f 265 }
antbig 1:116040d14164 266 gameTimer.reset();
antbig 12:14729d584500 267 jack.fall(NULL);//On désactive l'interruption du jack
antbig 10:a788d9cf60f2 268 SendRawId(GLOBAL_START);
antbig 12:14729d584500 269 tactile_printf("Start");//Pas vraiment util mais bon
antbig 0:ad97421fb1fb 270 break;
antbig 0:ad97421fb1fb 271 case ETAT_GAME_LOAD_NEXT_INSTRUCTION:
antbig 0:ad97421fb1fb 272 /*
antbig 0:ad97421fb1fb 273 Chargement de l'instruction suivante ou arret du robot si il n'y a plus d'instruction
antbig 0:ad97421fb1fb 274 */
antbig 0:ad97421fb1fb 275 //printf("load next instruction\n");
ClementBreteau 14:c8fc06c4887f 276
antbig 0:ad97421fb1fb 277 if(actual_instruction >= nb_instructions || actual_instruction == 255) {
antbig 0:ad97421fb1fb 278 gameEtat = ETAT_END;
antbig 0:ad97421fb1fb 279 //Il n'y a plus d'instruction, fin du jeu
antbig 0:ad97421fb1fb 280 } else {
antbig 0:ad97421fb1fb 281 instruction = strat_instructions[actual_instruction];
antbig 0:ad97421fb1fb 282 //On effectue le traitement de l'instruction
antbig 0:ad97421fb1fb 283 gameEtat = ETAT_GAME_PROCESS_INSTRUCTION;
antbig 0:ad97421fb1fb 284 }
antbig 0:ad97421fb1fb 285 screenChecktry = 0;
antbig 0:ad97421fb1fb 286 break;
antbig 0:ad97421fb1fb 287 case ETAT_GAME_PROCESS_INSTRUCTION:
antbig 0:ad97421fb1fb 288 /*
antbig 0:ad97421fb1fb 289 Traitement de l'instruction, envoie de la trame CAN
antbig 0:ad97421fb1fb 290 */
antbig 0:ad97421fb1fb 291 //debug_Instruction(instruction);
antbig 0:ad97421fb1fb 292 switch(instruction.order)
antbig 0:ad97421fb1fb 293 {
antbig 12:14729d584500 294 case MV_COURBURE://C'est un rayon de courbure
antbig 6:eddfa414fd11 295 waitingAckID = ASSERVISSEMENT_COURBURE;
antbig 6:eddfa414fd11 296 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
antbig 0:ad97421fb1fb 297 if(instruction.nextActionType == ENCHAINEMENT) {
antbig 6:eddfa414fd11 298 MV_enchainement++;
antbig 6:eddfa414fd11 299 localData5 = 1;
antbig 6:eddfa414fd11 300 } else {
antbig 6:eddfa414fd11 301 if(MV_enchainement > 0) {
antbig 6:eddfa414fd11 302 localData5 = 2;
antbig 6:eddfa414fd11 303 MV_enchainement = 0;
antbig 6:eddfa414fd11 304 } else {
antbig 6:eddfa414fd11 305 localData5 = 0;
antbig 6:eddfa414fd11 306 }
antbig 0:ad97421fb1fb 307 }
antbig 11:ed13a480ddca 308 localData1 = ((instruction.direction == LEFT)?1:-1);
ClementBreteau 23:ab87d308eaf9 309 localData2 = instruction.arg3;
antbig 12:14729d584500 310 if(InversStrat == 1)
antbig 12:14729d584500 311 {
antbig 12:14729d584500 312 localData1 = -localData1;//Inversion de la direction
ClementBreteau 23:ab87d308eaf9 313 #ifdef ROBOT_BIG
ClementBreteau 24:4a28a72781a6 314 localData2 = localData2;
ClementBreteau 23:ab87d308eaf9 315 #endif
antbig 12:14729d584500 316 }
ClementBreteau 18:cc5fec34ed9c 317
ClementBreteau 23:ab87d308eaf9 318 BendRadius(instruction.arg1, localData2, localData1, localData5);
antbig 0:ad97421fb1fb 319 break;
antbig 12:14729d584500 320 case MV_LINE://Ligne droite
antbig 0:ad97421fb1fb 321 waitingAckID = ASSERVISSEMENT_RECALAGE;
antbig 0:ad97421fb1fb 322 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
antbig 0:ad97421fb1fb 323 if(instruction.nextActionType == ENCHAINEMENT) {
antbig 1:116040d14164 324 MV_enchainement++;
antbig 1:116040d14164 325 localData5 = 1;
antbig 1:116040d14164 326 } else {
antbig 12:14729d584500 327 if(MV_enchainement > 0) {//Utilisé en cas d'enchainement,
antbig 1:116040d14164 328 localData5 = 2;
antbig 1:116040d14164 329 MV_enchainement = 0;
antbig 1:116040d14164 330 } else {
antbig 1:116040d14164 331 localData5 = 0;
antbig 1:116040d14164 332 }
antbig 0:ad97421fb1fb 333 }
ClementBreteau 16:7321fb3bb396 334 #ifdef ROBOT_BIG
ClementBreteau 15:c2fc239e85df 335 if(InversStrat == 1) {
ClementBreteau 15:c2fc239e85df 336 /*if (instruction.direction == FORWARD) instruction.direction = BACKWARD;
ClementBreteau 15:c2fc239e85df 337 else instruction.direction = FORWARD;*/
ClementBreteau 15:c2fc239e85df 338 instruction.direction = ((instruction.direction == FORWARD)?BACKWARD:FORWARD);
ClementBreteau 15:c2fc239e85df 339 }
ClementBreteau 16:7321fb3bb396 340 #endif
antbig 1:116040d14164 341 localData2 = (((instruction.direction == FORWARD)?1:-1)*instruction.arg1);
antbig 1:116040d14164 342 GoStraight(localData2, 0, 0, localData5);
ClementBreteau 14:c8fc06c4887f 343
antbig 0:ad97421fb1fb 344 break;
antbig 12:14729d584500 345 case MV_TURN: //Rotation sur place
antbig 0:ad97421fb1fb 346 if(instruction.direction == RELATIVE) {
antbig 0:ad97421fb1fb 347 localData2 = instruction.arg3;
antbig 12:14729d584500 348 } else {//C'est un rotation absolu, il faut la convertir en relative
antbig 12:14729d584500 349 localData2 = instruction.arg3;
antbig 12:14729d584500 350
antbig 12:14729d584500 351 localData2 = (localData2 - theta_robot)%3600;
antbig 12:14729d584500 352 if(localData2 > 1800) {
antbig 12:14729d584500 353 localData2 = localData2-3600;
antbig 12:14729d584500 354 }
antbig 12:14729d584500 355
antbig 0:ad97421fb1fb 356 }
ClementBreteau 23:ab87d308eaf9 357 #ifdef ROBOT_SMALL
clementlignie 22:a466d08ac42b 358 if(InversStrat == 1) {
clementlignie 22:a466d08ac42b 359 localData2 = -localData2;
clementlignie 22:a466d08ac42b 360 }
ClementBreteau 23:ab87d308eaf9 361 #endif
antbig 0:ad97421fb1fb 362 Rotate(localData2);
antbig 0:ad97421fb1fb 363 waitingAckID = ASSERVISSEMENT_ROTATION;
antbig 0:ad97421fb1fb 364 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
antbig 0:ad97421fb1fb 365 break;
antbig 0:ad97421fb1fb 366 case MV_XYT:
antbig 0:ad97421fb1fb 367 if(instruction.direction == BACKWARD) {
antbig 0:ad97421fb1fb 368 localData1 = -1;
antbig 0:ad97421fb1fb 369 } else {
antbig 0:ad97421fb1fb 370 localData1 = 1;
antbig 0:ad97421fb1fb 371 }
antbig 2:8d8e2cf798a3 372
antbig 2:8d8e2cf798a3 373 if(InversStrat == 1) {
antbig 12:14729d584500 374 localData2 = -instruction.arg3;
antbig 2:8d8e2cf798a3 375 localData3 = 3000 - instruction.arg2;//Inversion du Y
antbig 2:8d8e2cf798a3 376 } else {
antbig 2:8d8e2cf798a3 377 localData3 = instruction.arg2;
antbig 12:14729d584500 378 localData2 = instruction.arg3;
antbig 2:8d8e2cf798a3 379 }
ClementBreteau 23:ab87d308eaf9 380
ClementBreteau 23:ab87d308eaf9 381 #ifdef ROBOT_BIG
ClementBreteau 23:ab87d308eaf9 382 if(InversStrat == 1) {
ClementBreteau 23:ab87d308eaf9 383 localData1 = -localData1;
ClementBreteau 23:ab87d308eaf9 384 localData3 = -localData3;
ClementBreteau 23:ab87d308eaf9 385 }
ClementBreteau 23:ab87d308eaf9 386 #endif
ClementBreteau 23:ab87d308eaf9 387
antbig 12:14729d584500 388 GoToPosition(instruction.arg1,localData3,localData2,localData1);
antbig 0:ad97421fb1fb 389 waitingAckID = ASSERVISSEMENT_XYT;
antbig 0:ad97421fb1fb 390 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
antbig 0:ad97421fb1fb 391 break;
antbig 0:ad97421fb1fb 392 case MV_RECALAGE:
antbig 0:ad97421fb1fb 393 waitingAckID = ASSERVISSEMENT_RECALAGE;
antbig 0:ad97421fb1fb 394 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
antbig 11:ed13a480ddca 395 instruction.nextActionType = WAIT;
antbig 12:14729d584500 396 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 397
antbig 11:ed13a480ddca 398 if(instruction.precision == RECALAGE_Y) {
antbig 11:ed13a480ddca 399 localData5 = 2;
antbig 11:ed13a480ddca 400 if(InversStrat == 1) {
antbig 11:ed13a480ddca 401 localData3 = 3000 - instruction.arg1;//Inversion du Y
antbig 11:ed13a480ddca 402 } else {
antbig 11:ed13a480ddca 403 localData3 = instruction.arg1;
antbig 11:ed13a480ddca 404 }
antbig 11:ed13a480ddca 405 } else {
antbig 11:ed13a480ddca 406 localData5 = 1;
antbig 11:ed13a480ddca 407 localData3 = instruction.arg1;
antbig 11:ed13a480ddca 408 }
antbig 11:ed13a480ddca 409
antbig 11:ed13a480ddca 410 GoStraight(localData2, localData5, localData3, 0);
antbig 0:ad97421fb1fb 411 break;
antbig 0:ad97421fb1fb 412 case ACTION:
ClementBreteau 18:cc5fec34ed9c 413 int tempo = 0;
ClementBreteau 18:cc5fec34ed9c 414 waitingAckID= SERVO_AX12_ACTION;
ClementBreteau 15:c2fc239e85df 415 waitingAckFrom = ACKNOWLEDGE_AX12;
ClementBreteau 18:cc5fec34ed9c 416 tempo = doAction(instruction.arg1,instruction.arg2,instruction.arg3);
ClementBreteau 18:cc5fec34ed9c 417 if(tempo == 1){
antbig 0:ad97421fb1fb 418 //L'action est spécifique
antbig 11:ed13a480ddca 419 if((waitingAckFrom == 0 && waitingAckID == 0) || instruction.nextActionType == ENCHAINEMENT) {
ClementBreteau 18:cc5fec34ed9c 420
antbig 11:ed13a480ddca 421 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 11:ed13a480ddca 422 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
antbig 11:ed13a480ddca 423 } else {
ClementBreteau 15:c2fc239e85df 424 gameEtat = ETAT_GAME_WAIT_ACK;
antbig 11:ed13a480ddca 425 }
ClementBreteau 18:cc5fec34ed9c 426 #ifdef ROBOT_SMALL
ClementBreteau 18:cc5fec34ed9c 427 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
ClementBreteau 18:cc5fec34ed9c 428 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
ClementBreteau 18:cc5fec34ed9c 429 #endif
antbig 11:ed13a480ddca 430 return;
ClementBreteau 18:cc5fec34ed9c 431 #ifdef ROBOT_SMALL
ClementBreteau 18:cc5fec34ed9c 432 } else if (tempo == 2) {
ClementBreteau 18:cc5fec34ed9c 433 // on est dans le cas de l'avance selon le telemetre
ClementBreteau 18:cc5fec34ed9c 434 waitingAckID = ASSERVISSEMENT_RECALAGE;
ClementBreteau 18:cc5fec34ed9c 435 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
ClementBreteau 18:cc5fec34ed9c 436
ClementBreteau 18:cc5fec34ed9c 437 localData2 = (((instruction.direction == FORWARD)?1:-1)*instruction.arg1);
ClementBreteau 18:cc5fec34ed9c 438 GoStraight(telemetreDistance, 0, 0, 0);
ClementBreteau 18:cc5fec34ed9c 439 // on reset la distance du telemetre à 0
ClementBreteau 18:cc5fec34ed9c 440 telemetreDistance = 5000;
ClementBreteau 18:cc5fec34ed9c 441 #endif
ClementBreteau 18:cc5fec34ed9c 442 }else{
antbig 0:ad97421fb1fb 443 //C'est un AX12 qu'il faut bouger
ClementBreteau 15:c2fc239e85df 444 //AX12_setGoal(instruction.arg1,instruction.arg3/10,instruction.arg2);
ClementBreteau 15:c2fc239e85df 445 //AX12_enchainement++;
ClementBreteau 14:c8fc06c4887f 446
antbig 0:ad97421fb1fb 447 }
antbig 0:ad97421fb1fb 448 break;
antbig 0:ad97421fb1fb 449 default:
antbig 0:ad97421fb1fb 450 //Instruction inconnue, on l'ignore
antbig 0:ad97421fb1fb 451 break;
antbig 0:ad97421fb1fb 452 }
antbig 0:ad97421fb1fb 453
antbig 0:ad97421fb1fb 454
antbig 0:ad97421fb1fb 455
antbig 0:ad97421fb1fb 456 if(instruction.nextActionType == JUMP || instruction.nextActionType == WAIT) {
antbig 0:ad97421fb1fb 457 gameEtat = ETAT_GAME_WAIT_ACK;//Il faut attendre que la carte est bien reçu l'acknowledge
antbig 0:ad97421fb1fb 458 screenChecktry++;//On incrèment le conteur de tentative de 1
antbig 0:ad97421fb1fb 459 cartesCheker.reset();//On reset le timeOut
antbig 0:ad97421fb1fb 460 cartesCheker.start();
antbig 1:116040d14164 461 if(AX12_enchainement > 0) {
ClementBreteau 15:c2fc239e85df 462 //AX12_processChange();//Il faut lancer le déplacement des AX12
ClementBreteau 15:c2fc239e85df 463 //AX12_enchainement = 0;
antbig 1:116040d14164 464 }
antbig 0:ad97421fb1fb 465 } else {//C'est un enchainement
ClementBreteau 15:c2fc239e85df 466 if(instruction.order == MV_LINE){
ClementBreteau 15:c2fc239e85df 467 gameEtat = ETAT_GAME_WAIT_ACK;
ClementBreteau 15:c2fc239e85df 468
ClementBreteau 15:c2fc239e85df 469 }else{
ClementBreteau 15:c2fc239e85df 470 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
ClementBreteau 15:c2fc239e85df 471 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//C'est un enchainement, on charge directement l'instruction suivante
ClementBreteau 15:c2fc239e85df 472 }
antbig 0:ad97421fb1fb 473 }
antbig 0:ad97421fb1fb 474
antbig 0:ad97421fb1fb 475 break;
antbig 0:ad97421fb1fb 476 case ETAT_GAME_WAIT_ACK:
antbig 0:ad97421fb1fb 477 /*
antbig 0:ad97421fb1fb 478 Attente de l'ack de l'instruction
antbig 0:ad97421fb1fb 479 */
ClementBreteau 14:c8fc06c4887f 480 if(waitingAckID == 0 && waitingAckFrom == 0) {//Les ack ont été reset, c'est bon on continu
antbig 0:ad97421fb1fb 481 //if(true) {
antbig 0:ad97421fb1fb 482 cartesCheker.stop();
antbig 0:ad97421fb1fb 483 if(instruction.nextActionType == JUMP) {
antbig 11:ed13a480ddca 484 if(instruction.jumpAction == JUMP_POSITION) {
antbig 11:ed13a480ddca 485 gameEtat = ETAT_GAME_JUMP_POSITION;
antbig 11:ed13a480ddca 486 } else {//Pour eviter les erreurs, on dit que c'est par défaut un jump time
antbig 0:ad97421fb1fb 487 gameEtat = ETAT_GAME_JUMP_TIME;
antbig 0:ad97421fb1fb 488 cartesCheker.reset();//On reset le timeOut
antbig 11:ed13a480ddca 489 cartesCheker.start();
antbig 0:ad97421fb1fb 490 }
antbig 0:ad97421fb1fb 491 } else if(instruction.nextActionType == WAIT) {
antbig 0:ad97421fb1fb 492 gameEtat = ETAT_GAME_WAIT_END_INSTRUCTION;
antbig 0:ad97421fb1fb 493 switch(instruction.order)
antbig 0:ad97421fb1fb 494 {
antbig 0:ad97421fb1fb 495 case MV_COURBURE:
antbig 0:ad97421fb1fb 496 waitingAckID = ASSERVISSEMENT_COURBURE;
antbig 0:ad97421fb1fb 497 waitingAckFrom = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 498 break;
antbig 0:ad97421fb1fb 499 case MV_LINE:
antbig 0:ad97421fb1fb 500 waitingAckID = ASSERVISSEMENT_RECALAGE;
antbig 0:ad97421fb1fb 501 waitingAckFrom = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 502 break;
antbig 0:ad97421fb1fb 503 case MV_TURN:
antbig 0:ad97421fb1fb 504 waitingAckID = ASSERVISSEMENT_ROTATION;
antbig 0:ad97421fb1fb 505 waitingAckFrom = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 506 break;
antbig 0:ad97421fb1fb 507 case MV_XYT:
antbig 0:ad97421fb1fb 508 waitingAckID = ASSERVISSEMENT_XYT;
antbig 0:ad97421fb1fb 509 waitingAckFrom = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 510 break;
antbig 0:ad97421fb1fb 511 case MV_RECALAGE:
antbig 0:ad97421fb1fb 512 waitingAckID = ASSERVISSEMENT_RECALAGE;
antbig 0:ad97421fb1fb 513 waitingAckFrom = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 514 break;
antbig 0:ad97421fb1fb 515 case ACTION:
ClementBreteau 15:c2fc239e85df 516
ClementBreteau 15:c2fc239e85df 517 if (modeTelemetre == 0){
ClementBreteau 18:cc5fec34ed9c 518 if (telemetreDistance == 0){
ClementBreteau 18:cc5fec34ed9c 519 waitingAckID = SERVO_AX12_ACTION;// instruction.arg1;
ClementBreteau 18:cc5fec34ed9c 520 waitingAckFrom = INSTRUCTION_END_AX12; //SERVO_AX12_DONE;
ClementBreteau 18:cc5fec34ed9c 521 }else if(telemetreDistance == 5000){
ClementBreteau 18:cc5fec34ed9c 522 // on est dans le cas ou l'on fait une ligne suivant la distance du telemetre
ClementBreteau 18:cc5fec34ed9c 523 waitingAckID = ASSERVISSEMENT_RECALAGE;
ClementBreteau 18:cc5fec34ed9c 524 waitingAckFrom = INSTRUCTION_END_MOTEUR;
ClementBreteau 18:cc5fec34ed9c 525 telemetreDistance = 0;
ClementBreteau 18:cc5fec34ed9c 526 }
ClementBreteau 15:c2fc239e85df 527 }else{ // si on attend la reponse du telemetre
ClementBreteau 15:c2fc239e85df 528 //modeTelemetre = 1;
ClementBreteau 15:c2fc239e85df 529 waitingAckID = OBJET_SUR_TABLE;
ClementBreteau 15:c2fc239e85df 530 waitingAckFrom = 0;
ClementBreteau 15:c2fc239e85df 531 }
antbig 0:ad97421fb1fb 532 break;
antbig 0:ad97421fb1fb 533 default:
antbig 0:ad97421fb1fb 534 break;
antbig 0:ad97421fb1fb 535 }
antbig 0:ad97421fb1fb 536 } else {
antbig 0:ad97421fb1fb 537 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
antbig 0:ad97421fb1fb 538 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 0:ad97421fb1fb 539 }
antbig 0:ad97421fb1fb 540 } else if(cartesCheker.read_ms () > 50){
antbig 0:ad97421fb1fb 541 cartesCheker.stop();
antbig 0:ad97421fb1fb 542 if(screenChecktry >=2) {//La carte n'a pas reçus l'information, on passe à l'instruction d'erreur
antbig 0:ad97421fb1fb 543 actual_instruction = instruction.nextLineError;
antbig 0:ad97421fb1fb 544 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
antbig 0:ad97421fb1fb 545 } else {
antbig 0:ad97421fb1fb 546 gameEtat = ETAT_GAME_PROCESS_INSTRUCTION;//On retourne dans l'etat d'envois de l'instruction
antbig 0:ad97421fb1fb 547 }
antbig 0:ad97421fb1fb 548 }
antbig 0:ad97421fb1fb 549 break;
antbig 0:ad97421fb1fb 550
antbig 0:ad97421fb1fb 551 case ETAT_GAME_JUMP_TIME:
antbig 0:ad97421fb1fb 552 if(cartesCheker.read_ms () >= instruction.JumpTimeOrX) {
antbig 0:ad97421fb1fb 553 cartesCheker.stop();//On arrete le timer
antbig 0:ad97421fb1fb 554 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 0:ad97421fb1fb 555 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//On charge l'instruction suivante
antbig 0:ad97421fb1fb 556 }
antbig 0:ad97421fb1fb 557 break;
ClementBreteau 15:c2fc239e85df 558
ClementBreteau 15:c2fc239e85df 559 case ETAT_GAME_JUMP_CONFIG:
ClementBreteau 15:c2fc239e85df 560 signed int depasX = 1, depasY = 1; // servent à indiquer le sens de dépassement des coordonnées
ClementBreteau 15:c2fc239e85df 561 // 1 si l'instruction est plus grande que la position du robot
ClementBreteau 15:c2fc239e85df 562 // -1 si l'instruction est plus petite que la position du robot
ClementBreteau 15:c2fc239e85df 563 // 0 si l'instruction et position du robot sont proche de moins de 1cm
ClementBreteau 15:c2fc239e85df 564 if (abs(x_robot-instruction.JumpTimeOrX)<10){
ClementBreteau 15:c2fc239e85df 565 depasX = 0;
ClementBreteau 15:c2fc239e85df 566 }else if(x_robot > instruction.JumpTimeOrX){
ClementBreteau 15:c2fc239e85df 567 depasX = -1;
ClementBreteau 15:c2fc239e85df 568 }
ClementBreteau 15:c2fc239e85df 569
ClementBreteau 15:c2fc239e85df 570 if(abs(y_robot-instruction.JumpY)<10){
ClementBreteau 15:c2fc239e85df 571 depasY = 0;
ClementBreteau 15:c2fc239e85df 572 }else if(y_robot > instruction.JumpY){
ClementBreteau 15:c2fc239e85df 573 depasY = -1;
ClementBreteau 15:c2fc239e85df 574 }
ClementBreteau 15:c2fc239e85df 575
ClementBreteau 15:c2fc239e85df 576 gameEtat = ETAT_GAME_JUMP_POSITION;
ClementBreteau 15:c2fc239e85df 577 break;
antbig 0:ad97421fb1fb 578 case ETAT_GAME_JUMP_POSITION:
ClementBreteau 15:c2fc239e85df 579 bool Xok = false, Yok = false;
ClementBreteau 15:c2fc239e85df 580
ClementBreteau 15:c2fc239e85df 581 if (depasX == 0){
ClementBreteau 15:c2fc239e85df 582 Xok = true;
ClementBreteau 15:c2fc239e85df 583 }else if ((instruction.JumpTimeOrX - x_robot)*depasX < -5){
ClementBreteau 15:c2fc239e85df 584 Xok = true;
ClementBreteau 15:c2fc239e85df 585 }
ClementBreteau 15:c2fc239e85df 586
ClementBreteau 15:c2fc239e85df 587 if (depasY == 0){
ClementBreteau 15:c2fc239e85df 588 Yok = true;
ClementBreteau 15:c2fc239e85df 589 }else if ((instruction.JumpY - y_robot)*depasY < -5){
ClementBreteau 15:c2fc239e85df 590 Yok = true;
ClementBreteau 15:c2fc239e85df 591 }
ClementBreteau 15:c2fc239e85df 592
ClementBreteau 15:c2fc239e85df 593 // on teste si les deux coordonnées ont été dépassées, si oui on lance l'instruction suivante
ClementBreteau 15:c2fc239e85df 594 if (Xok && Yok){
ClementBreteau 15:c2fc239e85df 595 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
ClementBreteau 15:c2fc239e85df 596 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//On charge l'instruction suivante
ClementBreteau 15:c2fc239e85df 597 }
ClementBreteau 15:c2fc239e85df 598
antbig 0:ad97421fb1fb 599 break;
antbig 0:ad97421fb1fb 600 case ETAT_GAME_WAIT_END_INSTRUCTION:
antbig 0:ad97421fb1fb 601 if(waitingAckID == 0 && waitingAckFrom ==0) {//On attend que la carte nous indique que l'instruction est terminée
antbig 0:ad97421fb1fb 602 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 0:ad97421fb1fb 603 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//On charge l'instruction suivante
antbig 0:ad97421fb1fb 604 }
antbig 0:ad97421fb1fb 605 break;
antbig 0:ad97421fb1fb 606
antbig 0:ad97421fb1fb 607
antbig 5:dcd817534b57 608 case ETAT_WARNING_TIMEOUT://Attente de la trame fin de danger ou du timeout de 2s
antbig 12:14729d584500 609 if(timeoutWarning.read_ms() >= BALISE_TIMEOUT)//ça fait plus de 2s, il faut changer de stratégie
antbig 5:dcd817534b57 610 {
antbig 5:dcd817534b57 611 gameEtat = ETAT_WARNING_SWITCH_STRATEGIE;
antbig 5:dcd817534b57 612 }
antbig 5:dcd817534b57 613 break;
antbig 5:dcd817534b57 614 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 615 if(timeoutWarningWaitEnd.read_ms() >= 1000) {//c'est bon, on repart
antbig 12:14729d584500 616 //actual_instruction = instruction.nextLineError;
antbig 12:14729d584500 617 gameEtat = ETAT_WARNING_END_LAST_INSTRUCTION;
antbig 12:14729d584500 618 }
antbig 5:dcd817534b57 619 break;
antbig 5:dcd817534b57 620 case ETAT_WARNING_END_LAST_INSTRUCTION://trouver le meilleur moyen de reprendre l'instruction en cours
antbig 12:14729d584500 621 #ifdef ROBOT_BIG
ClementBreteau 15:c2fc239e85df 622 actual_instruction = instruction.nextLineError;// 2 //Modification directe... c'est pas bien mais ça marchait pour le match 5
antbig 12:14729d584500 623 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
ClementBreteau 20:de595e4ff01d 624 #else
antbig 12:14729d584500 625 actual_instruction = instruction.nextLineError;
antbig 12:14729d584500 626 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
ClementBreteau 20:de595e4ff01d 627 #endif
ClementBreteau 20:de595e4ff01d 628 gameEtat = ETAT_END;
ClementBreteau 21:590cdacb6a35 629
antbig 5:dcd817534b57 630 break;
antbig 5:dcd817534b57 631 case ETAT_WARNING_SWITCH_STRATEGIE://Si à la fin du timeout il y a toujours un robot, passer à l'instruction d'erreur
antbig 5:dcd817534b57 632 actual_instruction = instruction.nextLineError;
antbig 5:dcd817534b57 633 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
antbig 12:14729d584500 634 ingnorBaliseOnce = 1;
antbig 5:dcd817534b57 635 break;
ClementBreteau 20:de595e4ff01d 636
ClementBreteau 20:de595e4ff01d 637
ClementBreteau 20:de595e4ff01d 638
ClementBreteau 14:c8fc06c4887f 639 case ETAT_END:
ClementBreteau 14:c8fc06c4887f 640 if (ModeDemo){
ClementBreteau 14:c8fc06c4887f 641 gameEtat = ETAT_CHECK_CARTE_SCREEN;
ClementBreteau 14:c8fc06c4887f 642 ModeDemo = 1;
ClementBreteau 14:c8fc06c4887f 643 } else {
ClementBreteau 14:c8fc06c4887f 644 gameEtat = ETAT_END_LOOP;
ClementBreteau 14:c8fc06c4887f 645 }
antbig 0:ad97421fb1fb 646 break;
antbig 0:ad97421fb1fb 647 case ETAT_END_LOOP:
antbig 0:ad97421fb1fb 648 //Rien, on tourne en rond
ClementBreteau 18:cc5fec34ed9c 649
antbig 0:ad97421fb1fb 650 break;
antbig 0:ad97421fb1fb 651 default:
ClementBreteau 20:de595e4ff01d 652
antbig 0:ad97421fb1fb 653 break;
ClementBreteau 20:de595e4ff01d 654 }
ClementBreteau 20:de595e4ff01d 655 }
ClementBreteau 20:de595e4ff01d 656
antbig 4:88431b537477 657 /****************************************************************************************/
antbig 4:88431b537477 658 /* FUNCTION NAME: canProcessRx */
antbig 4:88431b537477 659 /* DESCRIPTION : Fonction de traitement des messages CAN */
antbig 4:88431b537477 660 /****************************************************************************************/
antbig 0:ad97421fb1fb 661 void canProcessRx(void)
ClementBreteau 20:de595e4ff01d 662 {
antbig 0:ad97421fb1fb 663 static signed char FIFO_occupation=0,FIFO_max_occupation=0;
antbig 4:88431b537477 664 CANMessage msgTx=CANMessage();
antbig 0:ad97421fb1fb 665 FIFO_occupation=FIFO_ecriture-FIFO_lecture;
antbig 0:ad97421fb1fb 666 if(FIFO_occupation<0)
antbig 0:ad97421fb1fb 667 FIFO_occupation=FIFO_occupation+SIZE_FIFO;
antbig 0:ad97421fb1fb 668 if(FIFO_max_occupation<FIFO_occupation)
antbig 0:ad97421fb1fb 669 FIFO_max_occupation=FIFO_occupation;
antbig 0:ad97421fb1fb 670 if(FIFO_occupation!=0) {
antbig 0:ad97421fb1fb 671
antbig 0:ad97421fb1fb 672 switch(msgRxBuffer[FIFO_lecture].id) {
antbig 4:88431b537477 673 case DEBUG_FAKE_JAKE://Permet de lancer le match à distance
ClementBreteau 23:ab87d308eaf9 674 case GLOBAL_JACK:
antbig 1:116040d14164 675 if(gameEtat == ETAT_GAME_WAIT_FOR_JACK) {
antbig 1:116040d14164 676 gameEtat = ETAT_GAME_START;
ClementBreteau 23:ab87d308eaf9 677 SendRawId(ACKNOWLEDGE_JACK);
antbig 1:116040d14164 678 }
antbig 1:116040d14164 679 break;
antbig 1:116040d14164 680
antbig 0:ad97421fb1fb 681 case ALIVE_BALISE:
antbig 0:ad97421fb1fb 682 case ALIVE_MOTEUR:
antbig 0:ad97421fb1fb 683 case ALIVE_IHM:
ClementBreteau 23:ab87d308eaf9 684 case ALIVE_ACTIONNEURS_AVANT:
ClementBreteau 23:ab87d308eaf9 685 case ALIVE_ACTIONNEURS_ARRIERE:
antbig 12:14729d584500 686 case ALIVE_AX12:
antbig 0:ad97421fb1fb 687 case ECRAN_ALL_CHECK:
antbig 0:ad97421fb1fb 688 if(waitingAckFrom == msgRxBuffer[FIFO_lecture].id) {
antbig 0:ad97421fb1fb 689 waitingAckFrom = 0;//C'est la bonne carte qui indique qu'elle est en ligne
antbig 0:ad97421fb1fb 690 }
ClementBreteau 15:c2fc239e85df 691 break;
antbig 0:ad97421fb1fb 692
antbig 0:ad97421fb1fb 693 case ACKNOWLEDGE_BALISE:
antbig 0:ad97421fb1fb 694 case ACKNOWLEDGE_MOTEUR:
antbig 0:ad97421fb1fb 695 case ACKNOWLEDGE_IHM:
ClementBreteau 14:c8fc06c4887f 696 case ACKNOWLEDGE_TELEMETRE:
ClementBreteau 15:c2fc239e85df 697 case ACKNOWLEDGE_AX12:
antbig 0:ad97421fb1fb 698 case INSTRUCTION_END_BALISE:
antbig 0:ad97421fb1fb 699 case INSTRUCTION_END_MOTEUR:
antbig 0:ad97421fb1fb 700 case INSTRUCTION_END_IHM:
ClementBreteau 15:c2fc239e85df 701 case INSTRUCTION_END_AX12:
ClementBreteau 18:cc5fec34ed9c 702
antbig 11:ed13a480ddca 703 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 704 waitingAckFrom = 0;
antbig 0:ad97421fb1fb 705 waitingAckID = 0;
antbig 0:ad97421fb1fb 706 }
antbig 0:ad97421fb1fb 707 break;
antbig 1:116040d14164 708 #ifdef ROBOT_BIG
antbig 0:ad97421fb1fb 709 case ODOMETRIE_BIG_POSITION:
antbig 0:ad97421fb1fb 710 #else
antbig 0:ad97421fb1fb 711 case ODOMETRIE_SMALL_POSITION:
antbig 0:ad97421fb1fb 712 #endif
antbig 0:ad97421fb1fb 713 x_robot=msgRxBuffer[FIFO_lecture].data[0]|((unsigned short)(msgRxBuffer[FIFO_lecture].data[1])<<8);
antbig 0:ad97421fb1fb 714 y_robot=msgRxBuffer[FIFO_lecture].data[2]|((unsigned short)(msgRxBuffer[FIFO_lecture].data[3])<<8);
antbig 0:ad97421fb1fb 715 theta_robot=msgRxBuffer[FIFO_lecture].data[4]|((signed short)(msgRxBuffer[FIFO_lecture].data[5])<<8);
antbig 0:ad97421fb1fb 716 break;
antbig 0:ad97421fb1fb 717
antbig 0:ad97421fb1fb 718 case ECRAN_START_MATCH:
antbig 0:ad97421fb1fb 719 if(gameEtat == ETAT_CONFIG) {
antbig 1:116040d14164 720 gameEtat = ETAT_GAME_INIT;
antbig 0:ad97421fb1fb 721 }
antbig 0:ad97421fb1fb 722 break;
antbig 0:ad97421fb1fb 723 case SERVO_AX12_SETGOAL:
antbig 9:d0042422d95a 724 //SendAck(0x114, SERVO_AX12_SETGOAL);
ClementBreteau 14:c8fc06c4887f 725 //if(AX12_isLocal(msgRxBuffer[FIFO_lecture].data[0]))
ClementBreteau 14:c8fc06c4887f 726 //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 727
antbig 0:ad97421fb1fb 728 break;
ClementBreteau 14:c8fc06c4887f 729
antbig 0:ad97421fb1fb 730 case SERVO_AX12_PROCESS:
ClementBreteau 14:c8fc06c4887f 731 SendAck(0x114, SERVO_AX12_PROCESS);
ClementBreteau 14:c8fc06c4887f 732 //AX12_processChange(1);
antbig 0:ad97421fb1fb 733 break;
ClementBreteau 14:c8fc06c4887f 734
antbig 1:116040d14164 735 case SERVO_AX12_DONE:
ClementBreteau 15:c2fc239e85df 736 SendRawId(POMPE_PWM);
ClementBreteau 14:c8fc06c4887f 737 /*//SendAck(0x114, SERVO_AX12_DONE);
antbig 1:116040d14164 738 AX12_notifyCANEnd(((unsigned short)(msgRxBuffer[FIFO_lecture].data[0])));
ClementBreteau 14:c8fc06c4887f 739
ClementBreteau 15:c2fc239e85df 740 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
ClementBreteau 14:c8fc06c4887f 741 waitingAckFrom = 0;
ClementBreteau 14:c8fc06c4887f 742 waitingAckID = 0;*/
ClementBreteau 14:c8fc06c4887f 743
antbig 1:116040d14164 744 break;
antbig 2:8d8e2cf798a3 745 case ECRAN_CHOICE_COLOR://Choix de la couleur
antbig 4:88431b537477 746 if(gameEtat == ETAT_CONFIG) {//C'est bon on a le droit de modifier les config
antbig 2:8d8e2cf798a3 747 if(msgRxBuffer[FIFO_lecture].data[0] == 0)
antbig 2:8d8e2cf798a3 748 InversStrat = 0;//Pas d'inversion de la couleur
antbig 2:8d8e2cf798a3 749 else
antbig 2:8d8e2cf798a3 750 InversStrat = 1;//Inversion de la couleur
antbig 4:88431b537477 751
antbig 4:88431b537477 752 msgTx.id=ECRAN_ACK_COLOR; // tx ack de la couleur
antbig 4:88431b537477 753 msgTx.len=1;
antbig 4:88431b537477 754 msgTx.format=CANStandard;
antbig 4:88431b537477 755 msgTx.type=CANData;
antbig 4:88431b537477 756 // couleur sur 1 octet
antbig 4:88431b537477 757 msgTx.data[0]=msgRxBuffer[FIFO_lecture].data[0];
antbig 4:88431b537477 758 can1.write(msgTx);
antbig 9:d0042422d95a 759
antbig 2:8d8e2cf798a3 760 }
antbig 2:8d8e2cf798a3 761 break;
ClementBreteau 14:c8fc06c4887f 762
antbig 2:8d8e2cf798a3 763 case ECRAN_CHOICE_STRAT://Choix du fichier de stratégie à utiliser
antbig 4:88431b537477 764 if(gameEtat == ETAT_CONFIG) {//C'est bon on a le droit de modifier les config
antbig 4:88431b537477 765 msgTx.id=ECRAN_ACK_STRAT; // tx ack de la couleur
antbig 4:88431b537477 766 msgTx.len=1;
antbig 4:88431b537477 767 msgTx.format=CANStandard;
antbig 4:88431b537477 768 msgTx.type=CANData;
antbig 4:88431b537477 769 if(SelectStrategy(msgRxBuffer[FIFO_lecture].data[0])) {
antbig 4:88431b537477 770 // id de la stratégie sur 1 octet
ClementBreteau 16:7321fb3bb396 771 if (msgRxBuffer[FIFO_lecture].data[0] < 0x10){ // Si la strat est une strat de match, on desactive le mode demo
ClementBreteau 14:c8fc06c4887f 772 ModeDemo = 0;
ClementBreteau 16:7321fb3bb396 773 } else { // sinon, on active le mode demo, utile pour la fin de la demo
ClementBreteau 14:c8fc06c4887f 774 ModeDemo = 1;
ClementBreteau 14:c8fc06c4887f 775 }
ClementBreteau 14:c8fc06c4887f 776
antbig 4:88431b537477 777 msgTx.data[0]=msgRxBuffer[FIFO_lecture].data[0];
antbig 4:88431b537477 778 } else {
antbig 4:88431b537477 779 //erreur sur 1 octet
antbig 4:88431b537477 780 msgTx.data[0]=0;
antbig 4:88431b537477 781 }
antbig 4:88431b537477 782 can1.write(msgTx);
antbig 9:d0042422d95a 783 wait_ms(10);
antbig 12:14729d584500 784 setAsservissementEtat(0);//Désactivation de l'asservissement pour repositionner le robot dans le zone de départ
antbig 12:14729d584500 785 tactile_printf("Strat %d, Asser desactive",msgTx.data[0]);
antbig 2:8d8e2cf798a3 786 }
antbig 2:8d8e2cf798a3 787 break;
ClementBreteau 16:7321fb3bb396 788 case BALISE_DANGER :
ClementBreteau 16:7321fb3bb396 789 SendAck(ACKNOWLEDGE_BALISE, BALISE_END_DANGER);
ClementBreteau 16:7321fb3bb396 790 break;
ClementBreteau 16:7321fb3bb396 791
antbig 5:dcd817534b57 792 case BALISE_STOP:
antbig 5:dcd817534b57 793 SendAck(ACKNOWLEDGE_BALISE, BALISE_STOP);
ClementBreteau 18:cc5fec34ed9c 794 //if (instruction[actual_instruction].order != MV_TURN){ //J'ai rajouté cette ligne mais il faut tester avec et sans pour voir le comportement du robot,
ClementBreteau 16:7321fb3bb396 795 if(needToStop() != 0 && ingnorBaliseOnce ==0) {
ClementBreteau 16:7321fb3bb396 796 if(gameEtat > ETAT_GAME_START && gameEtat != ETAT_WARNING_TIMEOUT)
ClementBreteau 16:7321fb3bb396 797 {
ClementBreteau 16:7321fb3bb396 798 SendRawId(ASSERVISSEMENT_STOP);
ClementBreteau 21:590cdacb6a35 799 while(1); // ligne à décommenter si on est en homologation
ClementBreteau 16:7321fb3bb396 800 gameEtat = ETAT_WARNING_TIMEOUT;
ClementBreteau 16:7321fb3bb396 801 if(gameEtat != ETAT_WARING_END_BALISE_WAIT) {
ClementBreteau 16:7321fb3bb396 802 timeoutWarning.reset();
ClementBreteau 16:7321fb3bb396 803 timeoutWarning.start();//Reset du timer utiliser par le timeout
ClementBreteau 16:7321fb3bb396 804 }
antbig 12:14729d584500 805 }
antbig 12:14729d584500 806 }
ClementBreteau 18:cc5fec34ed9c 807 //}
antbig 12:14729d584500 808 ingnorBaliseOnce = 0;
antbig 5:dcd817534b57 809 break;
ClementBreteau 16:7321fb3bb396 810
antbig 5:dcd817534b57 811 case BALISE_END_DANGER:
ClementBreteau 16:7321fb3bb396 812 SendAck(ACKNOWLEDGE_BALISE, BALISE_END_DANGER);
antbig 5:dcd817534b57 813 if(gameEtat == ETAT_WARNING_TIMEOUT) {
antbig 5:dcd817534b57 814 timeoutWarningWaitEnd.reset();
antbig 5:dcd817534b57 815 timeoutWarningWaitEnd.start();
antbig 5:dcd817534b57 816 gameEtat = ETAT_WARING_END_BALISE_WAIT;
antbig 5:dcd817534b57 817 }
antbig 5:dcd817534b57 818 break;
antbig 12:14729d584500 819
antbig 12:14729d584500 820 case ECRAN_CHOICE_START_ACTION:
antbig 12:14729d584500 821 if(gameEtat == ETAT_CONFIG) {//C'est bon on a le droit de modifier les config
antbig 12:14729d584500 822 if(msgRxBuffer[FIFO_lecture].data[0] == 1) {
antbig 12:14729d584500 823 runRobotTest();
antbig 12:14729d584500 824 } else {
antbig 12:14729d584500 825 initRobotActionneur();
antbig 12:14729d584500 826 }
antbig 12:14729d584500 827 wait_ms(500);
antbig 12:14729d584500 828 SendRawId(ECRAN_ACK_CHOICE_START_ACTION);
antbig 12:14729d584500 829 }
antbig 12:14729d584500 830 break;
ClementBreteau 14:c8fc06c4887f 831
ClementBreteau 14:c8fc06c4887f 832 case OBJET_SUR_TABLE:
ClementBreteau 15:c2fc239e85df 833 if (msgRxBuffer[FIFO_lecture].data[1] == 0xff){
ClementBreteau 15:c2fc239e85df 834
ClementBreteau 15:c2fc239e85df 835 gameEtat = ETAT_WARNING_END_LAST_INSTRUCTION;
ClementBreteau 15:c2fc239e85df 836 }
ClementBreteau 15:c2fc239e85df 837 else{
ClementBreteau 15:c2fc239e85df 838
ClementBreteau 15:c2fc239e85df 839 waitingAckFrom = 0;
ClementBreteau 15:c2fc239e85df 840 waitingAckID = 0;
ClementBreteau 15:c2fc239e85df 841
ClementBreteau 15:c2fc239e85df 842 strat_instructions[actual_instruction+1].arg1 = returnX(strat_instructions[actual_instruction].arg2);
ClementBreteau 15:c2fc239e85df 843 strat_instructions[actual_instruction+1].arg2 = returnY(strat_instructions[actual_instruction].arg2);
ClementBreteau 15:c2fc239e85df 844 }
ClementBreteau 15:c2fc239e85df 845 modeTelemetre = 0;
ClementBreteau 14:c8fc06c4887f 846 break;
antbig 0:ad97421fb1fb 847 }
antbig 0:ad97421fb1fb 848
antbig 0:ad97421fb1fb 849 FIFO_lecture=(FIFO_lecture+1)%SIZE_FIFO;
antbig 0:ad97421fb1fb 850 }
antbig 0:ad97421fb1fb 851 }