Programme carte strategie (disco)

Dependencies:   mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac

Committer:
antbig
Date:
Sun Apr 17 14:03:03 2016 +0000
Revision:
4:88431b537477
Parent:
2:8d8e2cf798a3
Child:
5:dcd817534b57
Ajout possibilit? de choisir id strat via CAN

Who changed what in which revision?

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