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