diff --git a/Cerveau/.gitignore b/Cerveau/.gitignore new file mode 100644 index 0000000..b9847fe --- /dev/null +++ b/Cerveau/.gitignore @@ -0,0 +1 @@ +Wifi_settings.ino diff --git a/Cerveau/Cerveau.ino b/Cerveau/Cerveau.ino index 3714860..ed13426 100644 --- a/Cerveau/Cerveau.ino +++ b/Cerveau/Cerveau.ino @@ -27,14 +27,16 @@ #define gst_server; +extern const char *ssid; +extern const char *password; + + struct triangulation_reception_t { int pos_x_mm, pos_y_mm; float angle_rad; bool validite; }; -const char* ssid = "riombotique"; -const char* password = "password"; // adresse du >Pi qui gere le serveur : 192.168.99.100 IPAddress local_IP(192, 168, 99, 101); IPAddress gateway(192, 168, 99, 1); @@ -187,7 +189,7 @@ void Initialisation_wifi(){ //Initialisation wifi //------------WIFI------------ //Initialisation wifi - WiFi.config(local_IP, gateway, subnet); + //WiFi.config(local_IP, gateway, subnet); WiFi.begin(ssid, password); int test_wifi = 0; while (WiFi.status() != WL_CONNECTED){ @@ -205,23 +207,27 @@ void Initialisation_wifi(){ M5.Lcd.print("Connecte au reseau ;-)"); M5.Lcd.setCursor(10,30); M5.Lcd.print(ssid); - } - else { - // le routeur riombotique n'a pas été trouvé - création d'un point d'accès - WiFi.mode(WIFI_OFF); - if (!WiFi.softAP("cerveau", "ilestsecret")) { - log_e("Soft AP creation failed."); - while(1); - } - IPAddress myIP = WiFi.softAPIP(); - M5.Lcd.clear(); - M5.Lcd.setCursor(10,10); - M5.Lcd.print("Creation Hotspot ;-)"); - M5.Lcd.setCursor(10,30); - M5.Lcd.print("cerveau 192.168.4.1"); M5.Lcd.setCursor(10,50); - M5.Lcd.print("mdp : ilestsecret"); + M5.Lcd.print(WiFi.localIP()); + delay(3000); + return; } + // le routeur riombotique n'a pas été trouvé - création d'un point d'accès + WiFi.config(local_IP, gateway, subnet); + WiFi.mode(WIFI_OFF); + if (!WiFi.softAP("cerveau", "ilestsecret")) { + log_e("Soft AP creation failed."); + while(1); + } + IPAddress myIP = WiFi.softAPIP(); + M5.Lcd.clear(); + M5.Lcd.setCursor(10,10); + M5.Lcd.print("Creation Hotspot ;-)"); + M5.Lcd.setCursor(10,30); + M5.Lcd.print("cerveau 192.168.4.1"); + M5.Lcd.setCursor(10,50); + M5.Lcd.print("mdp : ilestsecret"); + delay(1500); } @@ -388,8 +394,9 @@ void gestion_match(){ }while(fabs(detect_gradin.angle_rad / M_PI * 180) > 0.5); //index_Maitre = ATTENTE_ORDRE; //affichage_standard_init(); + */ break; - */ + } } @@ -497,10 +504,11 @@ enum etat_action_t gradin_approche(void){ GA_CHERCHE_GAUCHE, GA_CHERCHE_DROIT, GA_GOTO_LARGE, + GA_TOURNE_LARGE, GA_GOTO_PROCHE, GA_GOTO_PREND } statu_approche_gradin = GA_INIT; - static float angle_parcouru; + static float angle_parcouru, angle_mem; static int nb_erreur; int translation_x, translation_y; struct detect_gradin_t detect_gradin; @@ -521,9 +529,11 @@ enum etat_action_t gradin_approche(void){ if(detect_gradin.status == 2){ // On a trouvé ! statu_approche_gradin = GA_GOTO_LARGE; + angle_mem = detect_gradin.angle_rad; nb_erreur = 0; }else if(detect_gradin.status == 0){ // On a perdu la détection + while(deplacement_relatif(0, 0, -3. * M_PI / 180., 0) == ACTION_EN_COURS); statu_approche_gradin = GA_CHERCHE_DROIT; }else{ // On tourne à gauche de quelques degrés @@ -535,6 +545,7 @@ enum etat_action_t gradin_approche(void){ if(detect_gradin.status == 2){ // On a trouvé ! statu_approche_gradin = GA_GOTO_LARGE; + angle_mem = detect_gradin.angle_rad; nb_erreur = 0; }else if(detect_gradin.status == 0){ // On a perdu la détection @@ -555,9 +566,29 @@ enum etat_action_t gradin_approche(void){ while(1); } } - translation_x = detect_gradin.centre_y_mm - 400 * cos(detect_gradin.angle_rad); - translation_y = -400 * sin(detect_gradin.angle_rad); + translation_x = (detect_gradin.centre_y_mm + 150) * tan(detect_gradin.angle_rad); + translation_y = -(detect_gradin.centre_y_mm + 150) * sin(detect_gradin.angle_rad) - detect_gradin.centre_x_mm; + if(deplacement_relatif(translation_x, translation_y, 0, 0) == ACTION_TERMINEE){ + statu_approche_gradin = GA_TOURNE_LARGE; + } + break; + + case GA_TOURNE_LARGE: + if(deplacement_relatif(0, 0, -angle_mem, 0) == ACTION_TERMINEE){ + Detect_gradin(&detect_gradin); + if(detect_gradin.status != 2 || fabs(detect_gradin.angle_rad) > 0.009){ + statu_approche_gradin = GA_CHERCHE_GAUCHE; + }else{ + statu_approche_gradin = GA_GOTO_PROCHE; + } + + } + break; + + case GA_GOTO_PROCHE: + Detect_gradin(&detect_gradin); + if(deplacement_relatif((detect_gradin.centre_y_mm - 20), 0, 0, 0) == ACTION_TERMINEE){ statu_approche_gradin = GA_INIT; return ACTION_TERMINEE; } diff --git a/Cerveau/Com_chassis.h b/Cerveau/Com_chassis.h index 2bdc3d4..90e7c3e 100644 --- a/Cerveau/Com_chassis.h +++ b/Cerveau/Com_chassis.h @@ -14,7 +14,7 @@ struct chassis_emission_t { int vitesse, acceleration; }; -void Scan_chassis(struct chassis_reception_t * chassis_reception); +int Scan_chassis(struct chassis_reception_t * chassis_reception); void send_Chassis(struct chassis_emission_t * chassis_emission); void send_Chassis_RAZ(void); diff --git a/Cerveau/Com_chassis.ino b/Cerveau/Com_chassis.ino index 57d6766..e5eb8cb 100644 --- a/Cerveau/Com_chassis.ino +++ b/Cerveau/Com_chassis.ino @@ -4,7 +4,7 @@ /// @brief Lit l'état du chassis en I2C -void Scan_chassis(struct chassis_reception_t * chassis_reception){ +int Scan_chassis(struct chassis_reception_t * chassis_reception){ unsigned char tampon2[14]; //(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée) error = I2C_lire_registre(I2C_SLAVE_chassi, 0, tampon2, 12); @@ -19,6 +19,7 @@ void Scan_chassis(struct chassis_reception_t * chassis_reception){ Mvt_finit = (MOUVEMENT_FINI == tampon2[0]); chassis_reception->status = tampon2[0]; } + return error; } void send_Chassis(struct chassis_emission_t * chassis_emission){ diff --git a/Cerveau/ServerWeb.ino b/Cerveau/ServerWeb.ino index 5bfa271..7d64c03 100644 --- a/Cerveau/ServerWeb.ino +++ b/Cerveau/ServerWeb.ino @@ -57,6 +57,7 @@ WebServer server(80); void Web_init(){ server.begin(); server.on("/form", handleForm); + server.on("/statu", showStatus); } bool Web_nouveau_message(){ @@ -99,3 +100,27 @@ void handleForm() { Web_nouvelle_entree=1; } +void showStatus() { + char chassis[50], gradin[50], triangulation[50], detection_adversaire[50]; + char message_statu[500]; + const char message_statu_tmplt[] = "A simple form\ + \n

Statu du robot

\n\ +

Chassis: %s

Gradin: %d

Triangulation: %d

Detection_adversaire: %d

"; + struct chassis_reception_t chassis_reception; + + statu_to_string(chassis, !Scan_chassis(&chassis_reception) ); + + sprintf(message_statu, message_statu_tmplt, chassis, 0, 0, 0); + server.send(200, "text/html", message_statu); + +} + +/// @brief convertir un statu boolean en message web. +/// @param statu 0 NOK, 1 OK +void statu_to_string(char * statu_str, bool statu){ + if(!statu){ + strcpy(statu_str, "NOK"); + }else{ + strcpy(statu_str, "OK"); + } +} diff --git a/Cerveau/Wifi_settings.ino.example b/Cerveau/Wifi_settings.ino.example new file mode 100644 index 0000000..a1430bc --- /dev/null +++ b/Cerveau/Wifi_settings.ino.example @@ -0,0 +1,3 @@ +const char *ssid = "Mon SSID"; +const char *password = "Ma clé WiFi"; + diff --git a/Readme.md b/Readme.md index 16e0274..1e7c2fd 100644 --- a/Readme.md +++ b/Readme.md @@ -1,3 +1,14 @@ +WiFi +==== + +Pour compiler le code du "Cerveau", il est nécessaire de copier le fichier Wifi_settings.ino.example en Wifi_settings.ino. +Vous pouvez ensuite éditer le fichier Wifi_settings pour indiquer les identifiants Wifi. + +Communication I2C +================= + +La documentation de notre protocole I2C est [disponible sous forme de PDF ici](Doc/Communication%20I2C.pdf). + Déplacement fonctionnel ======================= @@ -10,7 +21,3 @@ Vidéo réalisée le 24 février 2024, paramètres : - vitesse : 2000 - acceleration : 1500 -Communication I2C -================= - -La documentation de notre protocole I2C est [disponible sous forme de PDF ici](Doc/Communication%20I2C.pdf).