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