homologation gros robot et test avec les ack de la carte a tout faire

Fork of CRAC-Strat_2017_HOMOLOGATION_PETIT_ROBOT by CRAC Team

Committer:
antbig
Date:
Wed Apr 13 22:04:54 2016 +0000
Revision:
0:ad97421fb1fb
Child:
1:116040d14164
Ajout interruption fin de match

Who changed what in which revision?

UserRevisionLine numberNew contents of line
antbig 0:ad97421fb1fb 1 #include "Strategie.h"
antbig 0:ad97421fb1fb 2
antbig 0:ad97421fb1fb 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 0:ad97421fb1fb 10 Timeout chronoEnd;//permet d'envoyer la trame CAN pour la fin
antbig 0:ad97421fb1fb 11
antbig 0:ad97421fb1fb 12 unsigned short waitingAckID = 0;//L'id du ack attendu
antbig 0:ad97421fb1fb 13 unsigned short waitingAckFrom = 0;//La provenance du ack attendu
antbig 0:ad97421fb1fb 14
antbig 0:ad97421fb1fb 15 signed char FIFO_lecture=0;//Position du fifo de lecture des messages CAN
antbig 0:ad97421fb1fb 16
antbig 0:ad97421fb1fb 17 signed short x_robot,y_robot,theta_robot;//La position du robot
antbig 0:ad97421fb1fb 18
antbig 0:ad97421fb1fb 19 unsigned short id_check[NOMBRE_CARTES]= {CHECK_BALISE,CHECK_MOTEUR};
antbig 0:ad97421fb1fb 20 unsigned short id_alive[NOMBRE_CARTES]= {ALIVE_BALISE,ALIVE_MOTEUR};
antbig 0:ad97421fb1fb 21 unsigned char checkCurrent = 0;
antbig 0:ad97421fb1fb 22 unsigned char countAliveCard = 0;
antbig 0:ad97421fb1fb 23
antbig 0:ad97421fb1fb 24
antbig 0:ad97421fb1fb 25 void chronometre_ISR (void)
antbig 0:ad97421fb1fb 26 {
antbig 0:ad97421fb1fb 27 SendRawId(ASSERVISSEMENT_STOP);//On stope les moteurs
antbig 0:ad97421fb1fb 28 SendRawId(GLOBAL_GAME_END);//Indication fin de match
antbig 0:ad97421fb1fb 29 gameTimer.stop();//Arret du timer
antbig 0:ad97421fb1fb 30
antbig 0:ad97421fb1fb 31 #if ROBOT_TYPE == ROBOT_BIG
antbig 0:ad97421fb1fb 32 doFunnyAction();
antbig 0:ad97421fb1fb 33 #endif
antbig 0:ad97421fb1fb 34
antbig 0:ad97421fb1fb 35 gameEtat = ETAT_END_LOOP;
antbig 0:ad97421fb1fb 36 }
antbig 0:ad97421fb1fb 37
antbig 0:ad97421fb1fb 38 void automate_process(void)
antbig 0:ad97421fb1fb 39 {
antbig 0:ad97421fb1fb 40 static struct S_Instruction instruction;
antbig 0:ad97421fb1fb 41 signed char localData1 = 0;
antbig 0:ad97421fb1fb 42 signed short localData2 = 0;
antbig 0:ad97421fb1fb 43 unsigned short localData3 = 0;
antbig 0:ad97421fb1fb 44 signed short localData4 = 0;
antbig 0:ad97421fb1fb 45
antbig 0:ad97421fb1fb 46 if(gameTimer.read_ms() >= 88000) {//Fin du match (On autorise 2s pour déposer des éléments
antbig 0:ad97421fb1fb 47 gameTimer.stop();
antbig 0:ad97421fb1fb 48 gameTimer.reset();
antbig 0:ad97421fb1fb 49 gameEtat = ETAT_END;//Fin du temps
antbig 0:ad97421fb1fb 50 }
antbig 0:ad97421fb1fb 51
antbig 0:ad97421fb1fb 52 if(lastEtat != gameEtat || debugetatTimer.read_ms() >= 1000) {
antbig 0:ad97421fb1fb 53 lastEtat = gameEtat;
antbig 0:ad97421fb1fb 54 debugetatTimer.reset();
antbig 0:ad97421fb1fb 55 sendStratEtat((unsigned char)gameEtat);
antbig 0:ad97421fb1fb 56 }
antbig 0:ad97421fb1fb 57
antbig 0:ad97421fb1fb 58 switch(gameEtat)
antbig 0:ad97421fb1fb 59 {
antbig 0:ad97421fb1fb 60 case ETAT_CHECK_CARTE_SCREEN:
antbig 0:ad97421fb1fb 61 /*
antbig 0:ad97421fb1fb 62 Verification de l'état de la carte ecran
antbig 0:ad97421fb1fb 63 */
antbig 0:ad97421fb1fb 64 waitingAckFrom = ALIVE_IHM;//On indique que l'on attend un ack de la carte IHM
antbig 0:ad97421fb1fb 65 SendRawId(CHECK_IHM);//On demande à la carte IHM d'insiquer ça présence
antbig 0:ad97421fb1fb 66
antbig 0:ad97421fb1fb 67 screenChecktry++;//On incrèment le conteur de tentative de 1
antbig 0:ad97421fb1fb 68 cartesCheker.reset();//On reset le timeOut
antbig 0:ad97421fb1fb 69 cartesCheker.start();//On lance le timer pour le timeout
antbig 0:ad97421fb1fb 70 gameEtat = ETAT_CHECK_CARTE_SCREEN_WAIT_ACK;
antbig 0:ad97421fb1fb 71
antbig 0:ad97421fb1fb 72 break;
antbig 0:ad97421fb1fb 73 case ETAT_CHECK_CARTE_SCREEN_WAIT_ACK:
antbig 0:ad97421fb1fb 74 /*
antbig 0:ad97421fb1fb 75 Attente du ALIVE de la carte écran.
antbig 0:ad97421fb1fb 76
antbig 0:ad97421fb1fb 77 Si la carte ne répond pas apres 10ms, on retoune dans l'etat ETAT_CHECK_CARTE_SCREEN
antbig 0:ad97421fb1fb 78 maximum 3 tentatives
antbig 0:ad97421fb1fb 79 Si pas de réponse, clignotement de toutes les leds possible
antbig 0:ad97421fb1fb 80 */
antbig 0:ad97421fb1fb 81 if(waitingAckFrom == 0) {//C'est bon la carte est en ligne
antbig 0:ad97421fb1fb 82 cartesCheker.stop();
antbig 0:ad97421fb1fb 83 screenChecktry = 0;
antbig 0:ad97421fb1fb 84 gameEtat = ETAT_CHECK_CARTES;
antbig 0:ad97421fb1fb 85 } else if(cartesCheker.read_ms () > 100) {
antbig 0:ad97421fb1fb 86 cartesCheker.stop();
antbig 0:ad97421fb1fb 87 if(screenChecktry >=3) {
antbig 0:ad97421fb1fb 88 errorLoop();//Erreur La carte IHM n'est pas en ligne
antbig 0:ad97421fb1fb 89 } else {
antbig 0:ad97421fb1fb 90 gameEtat = ETAT_CHECK_CARTE_SCREEN;
antbig 0:ad97421fb1fb 91 }
antbig 0:ad97421fb1fb 92 }
antbig 0:ad97421fb1fb 93 break;
antbig 0:ad97421fb1fb 94 case ETAT_CHECK_CARTES:
antbig 0:ad97421fb1fb 95 /*
antbig 0:ad97421fb1fb 96 Il faut faire une boucle pour verifier toutes les cartes les une apres les autres
antbig 0:ad97421fb1fb 97 */
antbig 0:ad97421fb1fb 98 waitingAckFrom = id_alive[checkCurrent];//On indique que l'on attend un ack de la carte IHM
antbig 0:ad97421fb1fb 99 SendRawId(id_check[checkCurrent]);//On demande à la carte IHM d'insiquer ça présence
antbig 0:ad97421fb1fb 100
antbig 0:ad97421fb1fb 101 screenChecktry++;//On incrèment le conteur de tentative de 1
antbig 0:ad97421fb1fb 102 cartesCheker.reset();//On reset le timeOut
antbig 0:ad97421fb1fb 103 cartesCheker.start();//On lance le timer pour le timeout
antbig 0:ad97421fb1fb 104 gameEtat = ETAT_CHECK_CARTES_WAIT_ACK;
antbig 0:ad97421fb1fb 105 break;
antbig 0:ad97421fb1fb 106 case ETAT_CHECK_CARTES_WAIT_ACK:
antbig 0:ad97421fb1fb 107 /*
antbig 0:ad97421fb1fb 108 On attend l'ack de la carte en cours de vérification
antbig 0:ad97421fb1fb 109 */
antbig 0:ad97421fb1fb 110 //printf("cartesCheker = %d waitingAckFrom = %d\n",cartesCheker.read_ms(), waitingAckFrom);
antbig 0:ad97421fb1fb 111 if(waitingAckFrom == 0) {//C'est bon la carte est en ligne
antbig 0:ad97421fb1fb 112 cartesCheker.stop();
antbig 0:ad97421fb1fb 113 screenChecktry = 0;
antbig 0:ad97421fb1fb 114 countAliveCard++;
antbig 0:ad97421fb1fb 115 if(checkCurrent >= NOMBRE_CARTES) {
antbig 0:ad97421fb1fb 116 if(countAliveCard >= NOMBRE_CARTES) {
antbig 0:ad97421fb1fb 117 gameEtat = ETAT_CONFIG;
antbig 0:ad97421fb1fb 118 SendRawId(ECRAN_ALL_CHECK);//On dit à l'IHM que toutes les cartes sont en ligne
antbig 0:ad97421fb1fb 119 } else {
antbig 0:ad97421fb1fb 120 gameEtat = ETAT_WAIT_FORCE;//Passage en attente de forçage du lancement
antbig 0:ad97421fb1fb 121 waitingAckFrom = ECRAN_ALL_CHECK;
antbig 0:ad97421fb1fb 122 }
antbig 0:ad97421fb1fb 123 } else {
antbig 0:ad97421fb1fb 124 checkCurrent++;
antbig 0:ad97421fb1fb 125 gameEtat = ETAT_CHECK_CARTES;
antbig 0:ad97421fb1fb 126 }
antbig 0:ad97421fb1fb 127 } else if(cartesCheker.read_ms () > 100) {
antbig 0:ad97421fb1fb 128 cartesCheker.stop();
antbig 0:ad97421fb1fb 129 if(screenChecktry >=3) {
antbig 0:ad97421fb1fb 130 screenChecktry = 0;
antbig 0:ad97421fb1fb 131 if(checkCurrent >= NOMBRE_CARTES) {
antbig 0:ad97421fb1fb 132 if(countAliveCard == NOMBRE_CARTES) {
antbig 0:ad97421fb1fb 133 gameEtat = ETAT_CONFIG;
antbig 0:ad97421fb1fb 134 SendRawId(ECRAN_ALL_CHECK);//On dit à l'IHM que toutes les cartes sont en ligne
antbig 0:ad97421fb1fb 135 } else {
antbig 0:ad97421fb1fb 136 gameEtat = ETAT_WAIT_FORCE;//Passage en attente de forçage du lancement
antbig 0:ad97421fb1fb 137 waitingAckFrom = ECRAN_ALL_CHECK;
antbig 0:ad97421fb1fb 138 }
antbig 0:ad97421fb1fb 139 } else {
antbig 0:ad97421fb1fb 140 checkCurrent++;
antbig 0:ad97421fb1fb 141 gameEtat = ETAT_CHECK_CARTES;
antbig 0:ad97421fb1fb 142 }
antbig 0:ad97421fb1fb 143 } else {
antbig 0:ad97421fb1fb 144 gameEtat = ETAT_CHECK_CARTES;
antbig 0:ad97421fb1fb 145 }
antbig 0:ad97421fb1fb 146 }
antbig 0:ad97421fb1fb 147 break;
antbig 0:ad97421fb1fb 148 case ETAT_WAIT_FORCE:
antbig 0:ad97421fb1fb 149 /*
antbig 0:ad97421fb1fb 150 Attente du forçage de la part de la carte IHM
antbig 0:ad97421fb1fb 151 */
antbig 0:ad97421fb1fb 152 if(waitingAckFrom == 0) {
antbig 0:ad97421fb1fb 153 gameEtat = ETAT_CONFIG;
antbig 0:ad97421fb1fb 154 }
antbig 0:ad97421fb1fb 155 break;
antbig 0:ad97421fb1fb 156 case ETAT_CONFIG:
antbig 0:ad97421fb1fb 157 /*
antbig 0:ad97421fb1fb 158 Attente de l'odre de choix de mode,
antbig 0:ad97421fb1fb 159 Il est possible de modifier la couleur et l'id de la stratégie
antbig 0:ad97421fb1fb 160 Il est aussi possible d'envoyer les ordres de debug
antbig 0:ad97421fb1fb 161 */
antbig 0:ad97421fb1fb 162 break;
antbig 0:ad97421fb1fb 163 case ETAT_GAME_START:
antbig 0:ad97421fb1fb 164 //On charge la liste des instructions
antbig 0:ad97421fb1fb 165 strcpy(cheminFileStart,"/local/test.txt");//On ouvre le fichier test.txt
antbig 0:ad97421fb1fb 166 loadAllInstruction();//Mise en cache de toute les instructions
antbig 0:ad97421fb1fb 167 fakeJack.reset();//Utiliser pour simuler le jack
antbig 0:ad97421fb1fb 168 fakeJack.start();//Utiliser pour simuler le jack
antbig 0:ad97421fb1fb 169 gameEtat = ETAT_GAME_WAIT_FOR_JACK;
antbig 0:ad97421fb1fb 170 SendRawId(ECRAN_ACK_START_MATCH);
antbig 0:ad97421fb1fb 171 tactile_printf("Attente du JACK.");
antbig 0:ad97421fb1fb 172 break;
antbig 0:ad97421fb1fb 173 case ETAT_GAME_WAIT_FOR_JACK:
antbig 0:ad97421fb1fb 174 //TODO Attendre le jack
antbig 0:ad97421fb1fb 175 if(fakeJack.read_ms() > 3000) {//Utiliser pour simuler le jack
antbig 0:ad97421fb1fb 176 fakeJack.stop();
antbig 0:ad97421fb1fb 177 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
antbig 0:ad97421fb1fb 178 gameTimer.reset();
antbig 0:ad97421fb1fb 179 gameTimer.start();
antbig 0:ad97421fb1fb 180 chronoEnd.attach(&chronometre_ISR,90);
antbig 0:ad97421fb1fb 181 }
antbig 0:ad97421fb1fb 182 break;
antbig 0:ad97421fb1fb 183 case ETAT_GAME_LOAD_NEXT_INSTRUCTION:
antbig 0:ad97421fb1fb 184 /*
antbig 0:ad97421fb1fb 185 Chargement de l'instruction suivante ou arret du robot si il n'y a plus d'instruction
antbig 0:ad97421fb1fb 186 */
antbig 0:ad97421fb1fb 187 //printf("load next instruction\n");
antbig 0:ad97421fb1fb 188 if(actual_instruction >= nb_instructions || actual_instruction == 255) {
antbig 0:ad97421fb1fb 189 gameEtat = ETAT_END;
antbig 0:ad97421fb1fb 190 //Il n'y a plus d'instruction, fin du jeu
antbig 0:ad97421fb1fb 191 } else {
antbig 0:ad97421fb1fb 192 instruction = strat_instructions[actual_instruction];
antbig 0:ad97421fb1fb 193 //On effectue le traitement de l'instruction
antbig 0:ad97421fb1fb 194 gameEtat = ETAT_GAME_PROCESS_INSTRUCTION;
antbig 0:ad97421fb1fb 195 //actual_instruction++;
antbig 0:ad97421fb1fb 196 }
antbig 0:ad97421fb1fb 197 screenChecktry = 0;
antbig 0:ad97421fb1fb 198 break;
antbig 0:ad97421fb1fb 199 case ETAT_GAME_PROCESS_INSTRUCTION:
antbig 0:ad97421fb1fb 200 /*
antbig 0:ad97421fb1fb 201 Traitement de l'instruction, envoie de la trame CAN
antbig 0:ad97421fb1fb 202 */
antbig 0:ad97421fb1fb 203 //debug_Instruction(instruction);
antbig 0:ad97421fb1fb 204 switch(instruction.order)
antbig 0:ad97421fb1fb 205 {
antbig 0:ad97421fb1fb 206 case MV_COURBURE:
antbig 0:ad97421fb1fb 207 //TODO - mettre l'ACK à jour
antbig 0:ad97421fb1fb 208 if(instruction.nextActionType == ENCHAINEMENT) {
antbig 0:ad97421fb1fb 209 //TODO - flag dans le trame pour indiquer l'enchainement
antbig 0:ad97421fb1fb 210 }
antbig 0:ad97421fb1fb 211 break;
antbig 0:ad97421fb1fb 212 case MV_LINE:
antbig 0:ad97421fb1fb 213 waitingAckID = ASSERVISSEMENT_RECALAGE;
antbig 0:ad97421fb1fb 214 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
antbig 0:ad97421fb1fb 215 if(instruction.nextActionType == ENCHAINEMENT) {
antbig 0:ad97421fb1fb 216 //TODO - flag dans le trame pour indiquer l'enchainement
antbig 0:ad97421fb1fb 217
antbig 0:ad97421fb1fb 218 }
antbig 0:ad97421fb1fb 219 break;
antbig 0:ad97421fb1fb 220 case MV_TURN:
antbig 0:ad97421fb1fb 221 if(instruction.direction == RELATIVE) {
antbig 0:ad97421fb1fb 222 localData2 = instruction.arg3;
antbig 0:ad97421fb1fb 223 } else {
antbig 0:ad97421fb1fb 224 if(abs(instruction.arg3 - theta_robot) > 180) {
antbig 0:ad97421fb1fb 225 localData2 = 360 - instruction.arg3 - theta_robot;
antbig 0:ad97421fb1fb 226 } else {
antbig 0:ad97421fb1fb 227 localData2 = instruction.arg3 - theta_robot;
antbig 0:ad97421fb1fb 228 }
antbig 0:ad97421fb1fb 229 }
antbig 0:ad97421fb1fb 230 Rotate(localData2);
antbig 0:ad97421fb1fb 231 waitingAckID = ASSERVISSEMENT_ROTATION;
antbig 0:ad97421fb1fb 232 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
antbig 0:ad97421fb1fb 233 break;
antbig 0:ad97421fb1fb 234 case MV_XYT:
antbig 0:ad97421fb1fb 235 if(instruction.direction == BACKWARD) {
antbig 0:ad97421fb1fb 236 localData1 = -1;
antbig 0:ad97421fb1fb 237 } else {
antbig 0:ad97421fb1fb 238 localData1 = 1;
antbig 0:ad97421fb1fb 239 }
antbig 0:ad97421fb1fb 240 GoToPosition(instruction.arg1,instruction.arg2,instruction.arg3,localData1);
antbig 0:ad97421fb1fb 241 waitingAckID = ASSERVISSEMENT_XYT;
antbig 0:ad97421fb1fb 242 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
antbig 0:ad97421fb1fb 243 break;
antbig 0:ad97421fb1fb 244 case MV_RECALAGE:
antbig 0:ad97421fb1fb 245 waitingAckID = ASSERVISSEMENT_RECALAGE;
antbig 0:ad97421fb1fb 246 waitingAckFrom = ACKNOWLEDGE_MOTEUR;
antbig 0:ad97421fb1fb 247 //TODO - mettre l'ACK à jour
antbig 0:ad97421fb1fb 248 break;
antbig 0:ad97421fb1fb 249 case ACTION:
antbig 0:ad97421fb1fb 250 if(doAction(instruction.arg1,instruction.arg2,instruction.arg3)) {
antbig 0:ad97421fb1fb 251 //L'action est spécifique
antbig 0:ad97421fb1fb 252 } else {
antbig 0:ad97421fb1fb 253 //C'est un AX12 qu'il faut bouger
antbig 0:ad97421fb1fb 254 }
antbig 0:ad97421fb1fb 255
antbig 0:ad97421fb1fb 256 //TODO - mettre l'ACK à jour
antbig 0:ad97421fb1fb 257 if(instruction.nextActionType == ENCHAINEMENT) {
antbig 0:ad97421fb1fb 258 //TODO - flag dans le trame pour indiquer l'enchainement
antbig 0:ad97421fb1fb 259 }
antbig 0:ad97421fb1fb 260 break;
antbig 0:ad97421fb1fb 261 default:
antbig 0:ad97421fb1fb 262 //Instruction inconnue, on l'ignore
antbig 0:ad97421fb1fb 263 break;
antbig 0:ad97421fb1fb 264 }
antbig 0:ad97421fb1fb 265
antbig 0:ad97421fb1fb 266
antbig 0:ad97421fb1fb 267
antbig 0:ad97421fb1fb 268 if(instruction.nextActionType == JUMP || instruction.nextActionType == WAIT) {
antbig 0:ad97421fb1fb 269 gameEtat = ETAT_GAME_WAIT_ACK;//Il faut attendre que la carte est bien reçu l'acknowledge
antbig 0:ad97421fb1fb 270 screenChecktry++;//On incrèment le conteur de tentative de 1
antbig 0:ad97421fb1fb 271 cartesCheker.reset();//On reset le timeOut
antbig 0:ad97421fb1fb 272 cartesCheker.start();
antbig 0:ad97421fb1fb 273 } else {//C'est un enchainement
antbig 0:ad97421fb1fb 274 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 0:ad97421fb1fb 275 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//C'est un enchainement, on charge directement l'instruction suivante
antbig 0:ad97421fb1fb 276 }
antbig 0:ad97421fb1fb 277
antbig 0:ad97421fb1fb 278 break;
antbig 0:ad97421fb1fb 279 case ETAT_GAME_WAIT_ACK:
antbig 0:ad97421fb1fb 280 /*
antbig 0:ad97421fb1fb 281 Attente de l'ack de l'instruction
antbig 0:ad97421fb1fb 282 */
antbig 0:ad97421fb1fb 283 if(waitingAckID == 0 && waitingAckFrom ==0) {//Les ack ont été reset, c'est bon on continu
antbig 0:ad97421fb1fb 284 //if(true) {
antbig 0:ad97421fb1fb 285 cartesCheker.stop();
antbig 0:ad97421fb1fb 286 if(instruction.nextActionType == JUMP) {
antbig 0:ad97421fb1fb 287 if(instruction.jumpAction == JUMP_TIME) {
antbig 0:ad97421fb1fb 288 gameEtat = ETAT_GAME_JUMP_TIME;
antbig 0:ad97421fb1fb 289 cartesCheker.reset();//On reset le timeOut
antbig 0:ad97421fb1fb 290 cartesCheker.start();
antbig 0:ad97421fb1fb 291 } else if(instruction.jumpAction == JUMP_POSITION) {
antbig 0:ad97421fb1fb 292 gameEtat = ETAT_GAME_JUMP_POSITION;
antbig 0:ad97421fb1fb 293 } else {
antbig 0:ad97421fb1fb 294 //ERROR
antbig 0:ad97421fb1fb 295 }
antbig 0:ad97421fb1fb 296 } else if(instruction.nextActionType == WAIT) {
antbig 0:ad97421fb1fb 297 gameEtat = ETAT_GAME_WAIT_END_INSTRUCTION;
antbig 0:ad97421fb1fb 298 switch(instruction.order)
antbig 0:ad97421fb1fb 299 {
antbig 0:ad97421fb1fb 300 case MV_COURBURE:
antbig 0:ad97421fb1fb 301 waitingAckID = ASSERVISSEMENT_COURBURE;
antbig 0:ad97421fb1fb 302 waitingAckFrom = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 303 break;
antbig 0:ad97421fb1fb 304 case MV_LINE:
antbig 0:ad97421fb1fb 305 waitingAckID = ASSERVISSEMENT_RECALAGE;
antbig 0:ad97421fb1fb 306 waitingAckFrom = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 307 break;
antbig 0:ad97421fb1fb 308 case MV_TURN:
antbig 0:ad97421fb1fb 309 waitingAckID = ASSERVISSEMENT_ROTATION;
antbig 0:ad97421fb1fb 310 waitingAckFrom = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 311 break;
antbig 0:ad97421fb1fb 312 case MV_XYT:
antbig 0:ad97421fb1fb 313 waitingAckID = ASSERVISSEMENT_XYT;
antbig 0:ad97421fb1fb 314 waitingAckFrom = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 315 break;
antbig 0:ad97421fb1fb 316 case MV_RECALAGE:
antbig 0:ad97421fb1fb 317 waitingAckID = ASSERVISSEMENT_RECALAGE;
antbig 0:ad97421fb1fb 318 waitingAckFrom = INSTRUCTION_END_MOTEUR;
antbig 0:ad97421fb1fb 319 break;
antbig 0:ad97421fb1fb 320 case ACTION:
antbig 0:ad97421fb1fb 321 //TODO
antbig 0:ad97421fb1fb 322 break;
antbig 0:ad97421fb1fb 323 default:
antbig 0:ad97421fb1fb 324 break;
antbig 0:ad97421fb1fb 325 }
antbig 0:ad97421fb1fb 326 } else {
antbig 0:ad97421fb1fb 327 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
antbig 0:ad97421fb1fb 328 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 0:ad97421fb1fb 329 }
antbig 0:ad97421fb1fb 330 } else if(cartesCheker.read_ms () > 50){
antbig 0:ad97421fb1fb 331 cartesCheker.stop();
antbig 0:ad97421fb1fb 332 if(screenChecktry >=2) {//La carte n'a pas reçus l'information, on passe à l'instruction d'erreur
antbig 0:ad97421fb1fb 333 actual_instruction = instruction.nextLineError;
antbig 0:ad97421fb1fb 334 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;
antbig 0:ad97421fb1fb 335 } else {
antbig 0:ad97421fb1fb 336 gameEtat = ETAT_GAME_PROCESS_INSTRUCTION;//On retourne dans l'etat d'envois de l'instruction
antbig 0:ad97421fb1fb 337 }
antbig 0:ad97421fb1fb 338 }
antbig 0:ad97421fb1fb 339 break;
antbig 0:ad97421fb1fb 340
antbig 0:ad97421fb1fb 341 case ETAT_GAME_JUMP_TIME:
antbig 0:ad97421fb1fb 342 if(cartesCheker.read_ms () >= instruction.JumpTimeOrX) {
antbig 0:ad97421fb1fb 343 cartesCheker.stop();//On arrete le timer
antbig 0:ad97421fb1fb 344 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 0:ad97421fb1fb 345 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//On charge l'instruction suivante
antbig 0:ad97421fb1fb 346 }
antbig 0:ad97421fb1fb 347 break;
antbig 0:ad97421fb1fb 348 case ETAT_GAME_JUMP_POSITION:
antbig 0:ad97421fb1fb 349
antbig 0:ad97421fb1fb 350 break;
antbig 0:ad97421fb1fb 351 case ETAT_GAME_WAIT_END_INSTRUCTION:
antbig 0:ad97421fb1fb 352 if(waitingAckID == 0 && waitingAckFrom ==0) {//On attend que la carte nous indique que l'instruction est terminée
antbig 0:ad97421fb1fb 353 actual_instruction = instruction.nextLineOK;//On indique que l'on va charger l'instruction suivante
antbig 0:ad97421fb1fb 354 gameEtat = ETAT_GAME_LOAD_NEXT_INSTRUCTION;//On charge l'instruction suivante
antbig 0:ad97421fb1fb 355 }
antbig 0:ad97421fb1fb 356 break;
antbig 0:ad97421fb1fb 357
antbig 0:ad97421fb1fb 358
antbig 0:ad97421fb1fb 359
antbig 0:ad97421fb1fb 360 case ETAT_END:
antbig 0:ad97421fb1fb 361
antbig 0:ad97421fb1fb 362 gameEtat = ETAT_END_LOOP;
antbig 0:ad97421fb1fb 363 break;
antbig 0:ad97421fb1fb 364 case ETAT_END_LOOP:
antbig 0:ad97421fb1fb 365 //Rien, on tourne en rond
antbig 0:ad97421fb1fb 366 break;
antbig 0:ad97421fb1fb 367 default:
antbig 0:ad97421fb1fb 368
antbig 0:ad97421fb1fb 369 break;
antbig 0:ad97421fb1fb 370 }
antbig 0:ad97421fb1fb 371 }
antbig 0:ad97421fb1fb 372
antbig 0:ad97421fb1fb 373 void canProcessRx(void)
antbig 0:ad97421fb1fb 374 {
antbig 0:ad97421fb1fb 375 static signed char FIFO_occupation=0,FIFO_max_occupation=0;
antbig 0:ad97421fb1fb 376
antbig 0:ad97421fb1fb 377 FIFO_occupation=FIFO_ecriture-FIFO_lecture;
antbig 0:ad97421fb1fb 378 if(FIFO_occupation<0)
antbig 0:ad97421fb1fb 379 FIFO_occupation=FIFO_occupation+SIZE_FIFO;
antbig 0:ad97421fb1fb 380 if(FIFO_max_occupation<FIFO_occupation)
antbig 0:ad97421fb1fb 381 FIFO_max_occupation=FIFO_occupation;
antbig 0:ad97421fb1fb 382 if(FIFO_occupation!=0) {
antbig 0:ad97421fb1fb 383
antbig 0:ad97421fb1fb 384 switch(msgRxBuffer[FIFO_lecture].id) {
antbig 0:ad97421fb1fb 385 case ASSERVISSEMENT_STOP:
antbig 0:ad97421fb1fb 386
antbig 0:ad97421fb1fb 387 break;
antbig 0:ad97421fb1fb 388 case ALIVE_BALISE:
antbig 0:ad97421fb1fb 389 case ALIVE_MOTEUR:
antbig 0:ad97421fb1fb 390 case ALIVE_IHM:
antbig 0:ad97421fb1fb 391 case ECRAN_ALL_CHECK:
antbig 0:ad97421fb1fb 392 if(waitingAckFrom == msgRxBuffer[FIFO_lecture].id) {
antbig 0:ad97421fb1fb 393 waitingAckFrom = 0;//C'est la bonne carte qui indique qu'elle est en ligne
antbig 0:ad97421fb1fb 394 }
antbig 0:ad97421fb1fb 395 break;
antbig 0:ad97421fb1fb 396
antbig 0:ad97421fb1fb 397 case ACKNOWLEDGE_BALISE:
antbig 0:ad97421fb1fb 398 case ACKNOWLEDGE_MOTEUR:
antbig 0:ad97421fb1fb 399 case ACKNOWLEDGE_IHM:
antbig 0:ad97421fb1fb 400 case INSTRUCTION_END_BALISE:
antbig 0:ad97421fb1fb 401 case INSTRUCTION_END_MOTEUR:
antbig 0:ad97421fb1fb 402 case INSTRUCTION_END_IHM:
antbig 0:ad97421fb1fb 403 if(waitingAckFrom == msgRxBuffer[FIFO_lecture].id && (msgRxBuffer[FIFO_lecture].data[0]|((unsigned int)(msgRxBuffer[FIFO_lecture].data[1])<<8) == waitingAckID)) {
antbig 0:ad97421fb1fb 404 waitingAckFrom = 0;
antbig 0:ad97421fb1fb 405 waitingAckID = 0;
antbig 0:ad97421fb1fb 406 }
antbig 0:ad97421fb1fb 407 break;
antbig 0:ad97421fb1fb 408 #if ROBOT_TYPE == ROBOT_BIG
antbig 0:ad97421fb1fb 409 case ODOMETRIE_BIG_POSITION:
antbig 0:ad97421fb1fb 410 #else
antbig 0:ad97421fb1fb 411 case ODOMETRIE_SMALL_POSITION:
antbig 0:ad97421fb1fb 412 #endif
antbig 0:ad97421fb1fb 413 x_robot=msgRxBuffer[FIFO_lecture].data[0]|((unsigned short)(msgRxBuffer[FIFO_lecture].data[1])<<8);
antbig 0:ad97421fb1fb 414 y_robot=msgRxBuffer[FIFO_lecture].data[2]|((unsigned short)(msgRxBuffer[FIFO_lecture].data[3])<<8);
antbig 0:ad97421fb1fb 415 theta_robot=msgRxBuffer[FIFO_lecture].data[4]|((signed short)(msgRxBuffer[FIFO_lecture].data[5])<<8);
antbig 0:ad97421fb1fb 416 break;
antbig 0:ad97421fb1fb 417
antbig 0:ad97421fb1fb 418 case ECRAN_START_MATCH:
antbig 0:ad97421fb1fb 419 if(gameEtat == ETAT_CONFIG) {
antbig 0:ad97421fb1fb 420 gameEtat = ETAT_GAME_START;
antbig 0:ad97421fb1fb 421 }
antbig 0:ad97421fb1fb 422 break;
antbig 0:ad97421fb1fb 423 case SERVO_AX12_SETGOAL:
antbig 0:ad97421fb1fb 424 if(AX12_isLocal(msgRxBuffer[FIFO_lecture].data[0]))
antbig 0:ad97421fb1fb 425 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 0:ad97421fb1fb 426
antbig 0:ad97421fb1fb 427 break;
antbig 0:ad97421fb1fb 428 case SERVO_AX12_PROCESS:
antbig 0:ad97421fb1fb 429 AX12_processChange();
antbig 0:ad97421fb1fb 430 break;
antbig 0:ad97421fb1fb 431 }
antbig 0:ad97421fb1fb 432
antbig 0:ad97421fb1fb 433 FIFO_lecture=(FIFO_lecture+1)%SIZE_FIFO;
antbig 0:ad97421fb1fb 434 }
antbig 0:ad97421fb1fb 435 }