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