From c76c939c7878ba9ce479bf7fad10e5a7226ea624 Mon Sep 17 00:00:00 2001 From: Samuel Date: Thu, 29 May 2025 21:24:42 +0200 Subject: [PATCH] Match2 --- Cerveau/Cerveau.ino | 19 ++++++----- Cerveau/Com_chassis.ino | 28 +++++++++-------- Cerveau/Com_detection_adversaire.ino | 12 +++---- Cerveau/Com_gradins.ino | 12 +++---- Cerveau/Com_triangulation.ino | 47 +++++++++++++++++----------- 5 files changed, 64 insertions(+), 54 deletions(-) diff --git a/Cerveau/Cerveau.ino b/Cerveau/Cerveau.ino index 8e80474..62cb60b 100644 --- a/Cerveau/Cerveau.ino +++ b/Cerveau/Cerveau.ino @@ -338,11 +338,15 @@ void gestion_match(){ translation_x_mm = 0; translation_y_mm = 0; rotation_rad = 100; + Serial.println("C1"); Triangulation_send_immobile(1); + Serial.println("C2"); while(M5.BtnC.read()){ M5.update(); } + Serial.println("C3"); delay(200); + Serial.println("C4"); IHM_attente_match(&couleur); tirette_enlevee = 0; @@ -421,12 +425,12 @@ void IHM_attente_match(int * couleur){ M5.update(); if(M5.BtnA.read() == 1){ affiche_msg("Couleur", " BLEU "); - Triangulation_send_config(configuration_match_bleu); + //Triangulation_send_config(configuration_match_bleu); m_couleur = COULEUR_BLEU; } if(M5.BtnB.read() == 1){ affiche_msg("Couleur", " JAUNE "); - Triangulation_send_config(configuration_match_jaune); + //Triangulation_send_config(configuration_match_jaune); m_couleur = COULEUR_JAUNE; } if(M5.BtnC.read() == 1){ @@ -450,7 +454,7 @@ enum etat_action_t Strategie(int couleur){ STRAT_ALLER_BACKSTAGE, // Déplacement relatif STRAT_FIN - }etat_strategie = STRAT_RECULE_BANDEROLE; + }etat_strategie = STRAT_INIT; enum etat_action_t etat_action; int translation_x_mm, translation_y_mm; static unsigned long temps_timer; @@ -459,9 +463,10 @@ enum etat_action_t Strategie(int couleur){ switch(etat_strategie){ case STRAT_INIT: temps_timer = millis(); + etat_strategie = STRAT_RECULE_BANDEROLE; break; case STRAT_RECULE_BANDEROLE: - if(millis() - temps_timer > 300){ + if(millis() - temps_timer >300){ // Déplacement en X translation_x_mm = -300; translation_y_mm = 0; @@ -520,9 +525,9 @@ enum etat_action_t Strategie(int couleur){ case STRAT_ALLER_PREPA_BACKSTAGE: if(couleur == COULEUR_JAUNE){ - etat_action = deplacement_relatif(0, 0, 165. / 180 * M_PI, 0); + etat_action = deplacement_relatif(0, 0, -15. / 180 * M_PI, 0); }else{ - etat_action = deplacement_relatif(0, 0, -165. / 180 * M_PI, 0); + etat_action = deplacement_relatif(0, 0, 15. / 180 * M_PI, 0); } if(etat_action == ACTION_TERMINEE){ etat_strategie = STRAT_ATTENTE_BACKSTAGE; @@ -536,7 +541,7 @@ enum etat_action_t Strategie(int couleur){ break; case STRAT_ALLER_BACKSTAGE: - etat_action = deplacement_relatif(1140, 0, 0, 0); + etat_action = deplacement_relatif(-1140, 0, 0, 0); if(etat_action == ACTION_TERMINEE){ etat_strategie = STRAT_FIN; } diff --git a/Cerveau/Com_chassis.ino b/Cerveau/Com_chassis.ino index 9db6fa7..d692095 100644 --- a/Cerveau/Com_chassis.ino +++ b/Cerveau/Com_chassis.ino @@ -8,23 +8,22 @@ int Scan_chassis(struct chassis_reception_t * chassis_reception){ } /// @brief Lit l'état du chassis en I2C -int Scan_chassis(struct chassis_reception_t * chassis_reception, bool blocking){ - unsigned char tampon2[14]; +int Scan_chassis(struct chassis_reception_t * chassis_reception, bool continuous_try){ + unsigned char tampon[14]; //(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée) - error = I2C_lire_registre(I2C_SLAVE_chassi, 0, tampon2, 12); - if (error !=0){ - Err_Chassi_com =1;IndexErr = 2; + error = I2C_lire_registre(I2C_SLAVE_chassi, 0, tampon, 12); + while(error !=0 && continuous_try){ affiche_erreur("Scan_Chassi", "Erreur I2C"); - if(blocking){ - while(1); - } - }else{ + error = I2C_lire_registre(I2C_SLAVE_chassi, 0, tampon, 12); + } + + if(error == 0){ Err_Chassi_com =0; IndexErr = 0; - - Mvt_finit = (MOUVEMENT_FINI == tampon2[0]); - chassis_reception->status = tampon2[0]; + Mvt_finit = (MOUVEMENT_FINI == tampon[0]); + chassis_reception->status = tampon[0]; } + return error; } @@ -54,7 +53,10 @@ void send_Chassis(struct chassis_emission_t * chassis_emission){ Mot[9] = chassis_emission->acceleration >>8; Mot[10] = chassis_emission->acceleration; - error = I2C_ecrire_registre(I2C_SLAVE_chassi, 0, Mot, 11); + do{ + error = I2C_ecrire_registre(I2C_SLAVE_chassi, 0, Mot, 11); + }while(!error); + if (error !=0){Err_Cha_send =1; IndexErr = 5;} else{Err_Cha_send =0;IndexErr = 0;} if(error==0){ //si pas d'erreur de transmission alors RAZ des valeurs diff --git a/Cerveau/Com_detection_adversaire.ino b/Cerveau/Com_detection_adversaire.ino index f2eef8b..975862e 100644 --- a/Cerveau/Com_detection_adversaire.ino +++ b/Cerveau/Com_detection_adversaire.ino @@ -3,20 +3,16 @@ #include int Detect_adv_lire(struct detect_adv_reception_t * detect_adv_reception){ - return Detect_adv_lire(detect_adv_reception, true); + return Detect_adv_lire(detect_adv_reception, false); } /// @brief Lit les capteurs VL53L1X -int Detect_adv_lire(struct detect_adv_reception_t * detect_adv_reception, bool blocking){ +int Detect_adv_lire(struct detect_adv_reception_t * detect_adv_reception, bool continuous_try){ unsigned char tampon2[14]; //(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée) error = I2C_lire_registre(I2C_SLAVE_detect_adv, 0, detect_adv_reception->distance_cm, 12); - if (error !=0){ + while(error !=0 && continuous_try){ affiche_erreur("Scan_Detect_adversaire", "Erreur I2C"); - if(blocking){ - while(1); - } - }else{ - Serial.println("I2C OK"); + error = I2C_lire_registre(I2C_SLAVE_detect_adv, 0, detect_adv_reception->distance_cm, 12); } return error; } diff --git a/Cerveau/Com_gradins.ino b/Cerveau/Com_gradins.ino index e35e067..4aed2e3 100644 --- a/Cerveau/Com_gradins.ino +++ b/Cerveau/Com_gradins.ino @@ -9,19 +9,17 @@ int Detect_gradin(struct detect_gradin_t * detect_gradin){ } /// @brief Lit les capteurs VL53L1X -int Detect_gradin(struct detect_gradin_t * detect_gradin, bool blocking){ +int Detect_gradin(struct detect_gradin_t * detect_gradin, bool continuous_try){ unsigned char tampon[14]; char chaine[200]; int angle_mrad; //(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée) error = I2C_lire_registre(I2C_SLAVE_detect_gradin, 0, tampon, 13); - if (error !=0){ + while (error !=0 && continuous_try){ affiche_erreur("Detect_gradin", "Erreur I2C"); - if (blocking){ - while(1); - } - }else{ - + error = I2C_lire_registre(I2C_SLAVE_detect_gradin, 0, tampon, 13); + } + if(!error){ detect_gradin->status = tampon[0]; detect_gradin->centre_x_mm = tampon[1] << 24 | tampon[2] << 16 | tampon[3] << 8 | tampon[4]; detect_gradin->centre_y_mm = tampon[5] << 24 | tampon[6] << 16 | tampon[7] << 8 | tampon[8]; diff --git a/Cerveau/Com_triangulation.ino b/Cerveau/Com_triangulation.ino index 7dbe07c..f25395f 100644 --- a/Cerveau/Com_triangulation.ino +++ b/Cerveau/Com_triangulation.ino @@ -4,22 +4,19 @@ int Scan_Triangulation(struct triangulation_reception_t * triangulation_receptio /// @brief Récupère position (X, Y) et l'orientation du robot -int Scan_Triangulation(struct triangulation_reception_t * triangulation_reception, bool blocking){ +int Scan_Triangulation(struct triangulation_reception_t * triangulation_reception, bool continuous_try){ unsigned char tampon2[14]; lec_Balise_1, lec_Balise_2, lec_Balise_3 = 0, 0, 0; //(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée) triangulation_reception->validite = false; error = I2C_lire_registre(I2C_SLAVE_trian, 0, tampon2, 13); // si errror != de 0 alors erreur de communication - if (error !=0){ + while (error !=0 && continuous_try){ Err_Tri_com =1;IndexErr = 1;lec_Balise_1=0;lec_Balise_2=0;lec_Balise_3=0; - affiche_erreur("Scan_Triangulation", "Erreur I2C"); - if(blocking){ - while(1); - } - return error; + error = I2C_lire_registre(I2C_SLAVE_trian, 0, tampon2, 13); // si errror != de 0 alors erreur de communication } - else{Err_Tri_com =0;IndexErr = 0;} + if (error ==0){ + Err_Tri_com =0;IndexErr = 0; triangulation_reception->pos_x_mm = tampon2[1]<< 24 | tampon2[2]<< 16 | tampon2[3]<< 8 | tampon2[4] ; triangulation_reception->pos_y_mm = tampon2[5]<< 24 | tampon2[6]<< 16 | tampon2[7]<< 8 | tampon2[8] ; @@ -39,30 +36,42 @@ int Scan_Triangulation(struct triangulation_reception_t * triangulation_receptio if(Position_actuelle_Y < PosLimNeg | Position_actuelle_Y > PosLimPos){ triangulation_reception->pos_y_mm = 9999; } + if(lec_Balise_1 == 1 && lec_Balise_2 == 1 && lec_Balise_3 == 1 && lec_Calcul_ok == 1 && error ==0){ + triangulation_reception->validite = true; + } } - if(lec_Balise_1 == 1 && lec_Balise_2 == 1 && lec_Balise_3 == 1 && lec_Calcul_ok == 1 && error ==0){ - triangulation_reception->validite = true; - } + return error; } -void Triangulation_send_immobile(int immobile){ + +int Triangulation_send_immobile(int immobile){ + return Triangulation_send_immobile(immobile, true); +} + +int Triangulation_send_immobile(int immobile, bool continuous_try){ unsigned char donnee=0; if(immobile){ donnee = 1; } error = I2C_ecrire_registre(I2C_SLAVE_trian, 13, &donnee, 1); // si errror != de 0 alors erreur de communication - if (error !=0){ + while (error !=0 && continuous_try){ affiche_erreur("Send_Triangulation", "Erreur I2C"); - while(1); + error = I2C_ecrire_registre(I2C_SLAVE_trian, 13, &donnee, 1); // si errror != de 0 alors erreur de communication } + return error; } +int Triangulation_send_config(unsigned char configuration){ + Triangulation_send_config(configuration, true); +} -void Triangulation_send_config(unsigned char configuration){ +int Triangulation_send_config(unsigned char configuration, bool continuous_try){ error = I2C_ecrire_registre(I2C_SLAVE_trian, 14, &configuration, 1); // si errror != de 0 alors erreur de communication - if (error !=0){ - affiche_erreur("Send_Triangulation", "Erreur I2C"); - while(1); + while (error !=0 || continuous_try){ + affiche_erreur("Triangulation_send_config", "Erreur I2C"); + error = I2C_ecrire_registre(I2C_SLAVE_trian, 14, &configuration, 1); // si errror != de 0 alors erreur de communication } -} \ No newline at end of file + return error; +} +