Match2
This commit is contained in:
parent
d94cedd6e2
commit
c76c939c78
@ -338,11 +338,15 @@ void gestion_match(){
|
|||||||
translation_x_mm = 0;
|
translation_x_mm = 0;
|
||||||
translation_y_mm = 0;
|
translation_y_mm = 0;
|
||||||
rotation_rad = 100;
|
rotation_rad = 100;
|
||||||
|
Serial.println("C1");
|
||||||
Triangulation_send_immobile(1);
|
Triangulation_send_immobile(1);
|
||||||
|
Serial.println("C2");
|
||||||
while(M5.BtnC.read()){
|
while(M5.BtnC.read()){
|
||||||
M5.update();
|
M5.update();
|
||||||
}
|
}
|
||||||
|
Serial.println("C3");
|
||||||
delay(200);
|
delay(200);
|
||||||
|
Serial.println("C4");
|
||||||
IHM_attente_match(&couleur);
|
IHM_attente_match(&couleur);
|
||||||
tirette_enlevee = 0;
|
tirette_enlevee = 0;
|
||||||
|
|
||||||
@ -421,12 +425,12 @@ void IHM_attente_match(int * couleur){
|
|||||||
M5.update();
|
M5.update();
|
||||||
if(M5.BtnA.read() == 1){
|
if(M5.BtnA.read() == 1){
|
||||||
affiche_msg("Couleur", " BLEU ");
|
affiche_msg("Couleur", " BLEU ");
|
||||||
Triangulation_send_config(configuration_match_bleu);
|
//Triangulation_send_config(configuration_match_bleu);
|
||||||
m_couleur = COULEUR_BLEU;
|
m_couleur = COULEUR_BLEU;
|
||||||
}
|
}
|
||||||
if(M5.BtnB.read() == 1){
|
if(M5.BtnB.read() == 1){
|
||||||
affiche_msg("Couleur", " JAUNE ");
|
affiche_msg("Couleur", " JAUNE ");
|
||||||
Triangulation_send_config(configuration_match_jaune);
|
//Triangulation_send_config(configuration_match_jaune);
|
||||||
m_couleur = COULEUR_JAUNE;
|
m_couleur = COULEUR_JAUNE;
|
||||||
}
|
}
|
||||||
if(M5.BtnC.read() == 1){
|
if(M5.BtnC.read() == 1){
|
||||||
@ -450,7 +454,7 @@ enum etat_action_t Strategie(int couleur){
|
|||||||
STRAT_ALLER_BACKSTAGE, // Déplacement relatif
|
STRAT_ALLER_BACKSTAGE, // Déplacement relatif
|
||||||
STRAT_FIN
|
STRAT_FIN
|
||||||
|
|
||||||
}etat_strategie = STRAT_RECULE_BANDEROLE;
|
}etat_strategie = STRAT_INIT;
|
||||||
enum etat_action_t etat_action;
|
enum etat_action_t etat_action;
|
||||||
int translation_x_mm, translation_y_mm;
|
int translation_x_mm, translation_y_mm;
|
||||||
static unsigned long temps_timer;
|
static unsigned long temps_timer;
|
||||||
@ -459,6 +463,7 @@ enum etat_action_t Strategie(int couleur){
|
|||||||
switch(etat_strategie){
|
switch(etat_strategie){
|
||||||
case STRAT_INIT:
|
case STRAT_INIT:
|
||||||
temps_timer = millis();
|
temps_timer = millis();
|
||||||
|
etat_strategie = STRAT_RECULE_BANDEROLE;
|
||||||
break;
|
break;
|
||||||
case STRAT_RECULE_BANDEROLE:
|
case STRAT_RECULE_BANDEROLE:
|
||||||
if(millis() - temps_timer >300){
|
if(millis() - temps_timer >300){
|
||||||
@ -520,9 +525,9 @@ enum etat_action_t Strategie(int couleur){
|
|||||||
|
|
||||||
case STRAT_ALLER_PREPA_BACKSTAGE:
|
case STRAT_ALLER_PREPA_BACKSTAGE:
|
||||||
if(couleur == COULEUR_JAUNE){
|
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{
|
}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){
|
if(etat_action == ACTION_TERMINEE){
|
||||||
etat_strategie = STRAT_ATTENTE_BACKSTAGE;
|
etat_strategie = STRAT_ATTENTE_BACKSTAGE;
|
||||||
@ -536,7 +541,7 @@ enum etat_action_t Strategie(int couleur){
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case STRAT_ALLER_BACKSTAGE:
|
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){
|
if(etat_action == ACTION_TERMINEE){
|
||||||
etat_strategie = STRAT_FIN;
|
etat_strategie = STRAT_FIN;
|
||||||
}
|
}
|
||||||
|
@ -8,23 +8,22 @@ int Scan_chassis(struct chassis_reception_t * chassis_reception){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Lit l'état du chassis en I2C
|
/// @brief Lit l'état du chassis en I2C
|
||||||
int Scan_chassis(struct chassis_reception_t * chassis_reception, bool blocking){
|
int Scan_chassis(struct chassis_reception_t * chassis_reception, bool continuous_try){
|
||||||
unsigned char tampon2[14];
|
unsigned char tampon[14];
|
||||||
//(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée)
|
//(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée)
|
||||||
error = I2C_lire_registre(I2C_SLAVE_chassi, 0, tampon2, 12);
|
error = I2C_lire_registre(I2C_SLAVE_chassi, 0, tampon, 12);
|
||||||
if (error !=0){
|
while(error !=0 && continuous_try){
|
||||||
Err_Chassi_com =1;IndexErr = 2;
|
|
||||||
affiche_erreur("Scan_Chassi", "Erreur I2C");
|
affiche_erreur("Scan_Chassi", "Erreur I2C");
|
||||||
if(blocking){
|
error = I2C_lire_registre(I2C_SLAVE_chassi, 0, tampon, 12);
|
||||||
while(1);
|
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
|
if(error == 0){
|
||||||
Err_Chassi_com =0;
|
Err_Chassi_com =0;
|
||||||
IndexErr = 0;
|
IndexErr = 0;
|
||||||
|
Mvt_finit = (MOUVEMENT_FINI == tampon[0]);
|
||||||
Mvt_finit = (MOUVEMENT_FINI == tampon2[0]);
|
chassis_reception->status = tampon[0];
|
||||||
chassis_reception->status = tampon2[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +53,10 @@ void send_Chassis(struct chassis_emission_t * chassis_emission){
|
|||||||
Mot[9] = chassis_emission->acceleration >>8;
|
Mot[9] = chassis_emission->acceleration >>8;
|
||||||
Mot[10] = chassis_emission->acceleration;
|
Mot[10] = chassis_emission->acceleration;
|
||||||
|
|
||||||
|
do{
|
||||||
error = I2C_ecrire_registre(I2C_SLAVE_chassi, 0, Mot, 11);
|
error = I2C_ecrire_registre(I2C_SLAVE_chassi, 0, Mot, 11);
|
||||||
|
}while(!error);
|
||||||
|
|
||||||
if (error !=0){Err_Cha_send =1; IndexErr = 5;}
|
if (error !=0){Err_Cha_send =1; IndexErr = 5;}
|
||||||
else{Err_Cha_send =0;IndexErr = 0;}
|
else{Err_Cha_send =0;IndexErr = 0;}
|
||||||
if(error==0){ //si pas d'erreur de transmission alors RAZ des valeurs
|
if(error==0){ //si pas d'erreur de transmission alors RAZ des valeurs
|
||||||
|
@ -3,20 +3,16 @@
|
|||||||
#include <HardwareSerial.h>
|
#include <HardwareSerial.h>
|
||||||
|
|
||||||
int Detect_adv_lire(struct detect_adv_reception_t * detect_adv_reception){
|
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
|
/// @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];
|
unsigned char tampon2[14];
|
||||||
//(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée)
|
//(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);
|
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");
|
affiche_erreur("Scan_Detect_adversaire", "Erreur I2C");
|
||||||
if(blocking){
|
error = I2C_lire_registre(I2C_SLAVE_detect_adv, 0, detect_adv_reception->distance_cm, 12);
|
||||||
while(1);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
Serial.println("I2C OK");
|
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -9,19 +9,17 @@ int Detect_gradin(struct detect_gradin_t * detect_gradin){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Lit les capteurs VL53L1X
|
/// @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];
|
unsigned char tampon[14];
|
||||||
char chaine[200];
|
char chaine[200];
|
||||||
int angle_mrad;
|
int angle_mrad;
|
||||||
//(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée)
|
//(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée)
|
||||||
error = I2C_lire_registre(I2C_SLAVE_detect_gradin, 0, tampon, 13);
|
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");
|
affiche_erreur("Detect_gradin", "Erreur I2C");
|
||||||
if (blocking){
|
error = I2C_lire_registre(I2C_SLAVE_detect_gradin, 0, tampon, 13);
|
||||||
while(1);
|
|
||||||
}
|
}
|
||||||
}else{
|
if(!error){
|
||||||
|
|
||||||
detect_gradin->status = tampon[0];
|
detect_gradin->status = tampon[0];
|
||||||
detect_gradin->centre_x_mm = tampon[1] << 24 | tampon[2] << 16 | tampon[3] << 8 | tampon[4];
|
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];
|
detect_gradin->centre_y_mm = tampon[5] << 24 | tampon[6] << 16 | tampon[7] << 8 | tampon[8];
|
||||||
|
@ -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
|
/// @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];
|
unsigned char tampon2[14];
|
||||||
lec_Balise_1, lec_Balise_2, lec_Balise_3 = 0, 0, 0;
|
lec_Balise_1, lec_Balise_2, lec_Balise_3 = 0, 0, 0;
|
||||||
//(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée)
|
//(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée)
|
||||||
triangulation_reception->validite = false;
|
triangulation_reception->validite = false;
|
||||||
error = I2C_lire_registre(I2C_SLAVE_trian, 0, tampon2, 13); // si errror != de 0 alors erreur de communication
|
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;
|
Err_Tri_com =1;IndexErr = 1;lec_Balise_1=0;lec_Balise_2=0;lec_Balise_3=0;
|
||||||
affiche_erreur("Scan_Triangulation", "Erreur I2C");
|
error = I2C_lire_registre(I2C_SLAVE_trian, 0, tampon2, 13); // si errror != de 0 alors erreur de communication
|
||||||
if(blocking){
|
|
||||||
while(1);
|
|
||||||
}
|
}
|
||||||
return error;
|
|
||||||
}
|
|
||||||
else{Err_Tri_com =0;IndexErr = 0;}
|
|
||||||
if (error ==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_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] ;
|
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){
|
if(Position_actuelle_Y < PosLimNeg | Position_actuelle_Y > PosLimPos){
|
||||||
triangulation_reception->pos_y_mm = 9999;
|
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){
|
if(lec_Balise_1 == 1 && lec_Balise_2 == 1 && lec_Balise_3 == 1 && lec_Calcul_ok == 1 && error ==0){
|
||||||
triangulation_reception->validite = true;
|
triangulation_reception->validite = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return error;
|
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;
|
unsigned char donnee=0;
|
||||||
if(immobile){
|
if(immobile){
|
||||||
donnee = 1;
|
donnee = 1;
|
||||||
}
|
}
|
||||||
error = I2C_ecrire_registre(I2C_SLAVE_trian, 13, &donnee, 1); // si errror != de 0 alors erreur de communication
|
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");
|
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
|
||||||
|
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
|
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);
|
|
||||||
}
|
}
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user