2023-03-28 21:03:35 +00:00
|
|
|
#include "hardware/gpio.h"
|
|
|
|
#include "i2c_annexe.h"
|
2023-03-29 21:12:16 +00:00
|
|
|
#include "Asser_Position.h"
|
2023-04-01 08:40:30 +00:00
|
|
|
#include "Balise_VL53L1X.h"
|
2023-04-01 15:55:24 +00:00
|
|
|
#include "Commande_vitesse.h"
|
2023-03-28 21:03:35 +00:00
|
|
|
#include "Geometrie_robot.h"
|
2023-03-26 19:28:13 +00:00
|
|
|
#include "Localisation.h"
|
2023-03-28 21:03:35 +00:00
|
|
|
#include "Moteurs.h"
|
2023-03-26 19:28:13 +00:00
|
|
|
#include "Strategie_prise_cerises.h"
|
|
|
|
#include "Strategie.h"
|
|
|
|
#include "Trajet.h"
|
|
|
|
#include "math.h"
|
2023-03-26 14:56:34 +00:00
|
|
|
|
2023-03-28 21:03:35 +00:00
|
|
|
#define SEUIL_RECAL_DIST_MM 75
|
2023-04-13 17:43:35 +00:00
|
|
|
#define SEUIL_RECAL_ANGLE_RADIAN (5 * DEGRE_EN_RADIAN)
|
2023-04-01 13:29:54 +00:00
|
|
|
#define DISTANCE_OBSTACLE_CM 50
|
|
|
|
#define DISTANCE_PAS_OBSTACLE_MM 2000
|
2023-03-28 21:03:35 +00:00
|
|
|
|
2023-04-21 20:33:29 +00:00
|
|
|
// TODO: Peut-être à remetttre en variable locale après
|
2023-04-28 21:51:43 +00:00
|
|
|
float distance_obstacle;
|
2023-04-21 20:33:29 +00:00
|
|
|
|
2023-05-06 21:46:00 +00:00
|
|
|
enum etat_action_t lance_balles_dans_panier(enum couleur_t couleur, uint32_t step_ms);
|
2023-04-28 21:51:43 +00:00
|
|
|
enum etat_action_t calage_angle(enum longer_direction_t longer_direction, float x_mm, float y_mm, float angle_radian);
|
2023-03-28 21:03:35 +00:00
|
|
|
enum etat_action_t lance_balles(uint32_t step_ms);
|
|
|
|
|
2023-05-06 21:46:00 +00:00
|
|
|
enum etat_homologation_t etat_homologation=STRATEGIE_INIT;
|
|
|
|
|
|
|
|
|
|
|
|
void Strategie(enum couleur_t couleur, uint32_t step_ms){
|
|
|
|
|
|
|
|
float angle_fin;
|
|
|
|
float recal_pos_x, recal_pos_y;
|
|
|
|
enum longer_direction_t longer_direction;
|
|
|
|
enum etat_action_t etat_action;
|
|
|
|
enum etat_trajet_t etat_trajet;
|
|
|
|
|
|
|
|
struct trajectoire_t trajectoire;
|
|
|
|
|
|
|
|
static enum etat_strategie_t {
|
|
|
|
STRATEGIE_INIT,
|
|
|
|
ALLER_CERISE_BAS,
|
|
|
|
ATTRAPER_CERISE_BAS,
|
|
|
|
ALLER_CERISE_HAUT,
|
|
|
|
ATTRAPER_CERISE_HAUT,
|
|
|
|
ALLER_CERISE_GAUCHE,
|
|
|
|
ATTRAPER_CERISE_GAUCHE,
|
|
|
|
ALLER_CERISE_DROITE,
|
|
|
|
ATTRAPER_CERISE_DROITE,
|
|
|
|
ALLER_PANIER,
|
|
|
|
LANCER_PANIER,
|
|
|
|
}etat_strategie;
|
|
|
|
|
|
|
|
switch(etat_strategie){
|
|
|
|
case STRATEGIE_INIT:
|
|
|
|
if(couleur == COULEUR_BLEU){
|
|
|
|
Localisation_set(775., 109., (-60.+CORR_ANGLE_DEPART_DEGREE) * DEGRE_EN_RADIAN);
|
|
|
|
}else{
|
|
|
|
Localisation_set(2000 - 775., 109., (-60.+CORR_ANGLE_DEPART_DEGREE) * DEGRE_EN_RADIAN);
|
|
|
|
}
|
|
|
|
etat_strategie = ALLER_CERISE_BAS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALLER_CERISE_BAS:
|
|
|
|
|
|
|
|
if(couleur == COULEUR_BLEU){
|
|
|
|
angle_fin = 30. * DEGRE_EN_RADIAN;
|
|
|
|
}else{
|
|
|
|
angle_fin = -150. * DEGRE_EN_RADIAN;
|
|
|
|
}
|
|
|
|
|
|
|
|
Trajet_config(250, 500);
|
|
|
|
Trajectoire_droite(&trajectoire, Localisation_get().x_mm, Localisation_get().y_mm, 857, 156,
|
|
|
|
Localisation_get().angle_radian, angle_fin);
|
|
|
|
|
|
|
|
if(parcourt_trajet_simple_sans_evitement(trajectoire, step_ms) == TRAJET_TERMINE){
|
|
|
|
etat_strategie = ATTRAPER_CERISE_BAS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATTRAPER_CERISE_BAS:
|
|
|
|
recal_pos_y = RAYON_ROBOT;
|
|
|
|
if(couleur == COULEUR_BLEU){
|
|
|
|
longer_direction = LONGER_VERS_C;
|
|
|
|
recal_pos_x = 1000 - 15 - PETIT_RAYON_ROBOT_MM;
|
|
|
|
}else{
|
|
|
|
longer_direction = LONGER_VERS_A;
|
|
|
|
recal_pos_x = 1000 + 15 + PETIT_RAYON_ROBOT_MM;
|
|
|
|
}
|
|
|
|
|
|
|
|
etat_action = cerise_attraper_bordure(longer_direction, step_ms, recal_pos_x, recal_pos_y);
|
|
|
|
if(etat_action == ACTION_TERMINEE){
|
|
|
|
etat_strategie = ALLER_PANIER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALLER_PANIER:
|
|
|
|
Trajet_config(500, 500);
|
|
|
|
if(couleur == COULEUR_BLEU){
|
|
|
|
Trajectoire_bezier(&trajectoire,Localisation_get().x_mm, Localisation_get().y_mm,
|
|
|
|
485, Localisation_get().y_mm,
|
|
|
|
465, 857,
|
|
|
|
465,2830,
|
|
|
|
+30. * DEGRE_EN_RADIAN, +120. * DEGRE_EN_RADIAN);
|
|
|
|
}else{
|
|
|
|
Trajectoire_bezier(&trajectoire,Localisation_get().x_mm, Localisation_get().y_mm,
|
|
|
|
485, Localisation_get().y_mm,
|
|
|
|
2000-465, 857,
|
|
|
|
2000-465,2830,
|
|
|
|
-150. * DEGRE_EN_RADIAN, -240. * DEGRE_EN_RADIAN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parcourt_trajet_simple(trajectoire, step_ms) == ACTION_TERMINEE){
|
|
|
|
etat_strategie = LANCER_PANIER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LANCER_PANIER:
|
|
|
|
if(lance_balles_dans_panier(couleur, step_ms)== ACTION_TERMINEE){
|
|
|
|
etat_homologation = STRATEGIE_FIN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STRATEGIE_FIN:
|
|
|
|
i2c_annexe_desactive_propulseur();
|
|
|
|
commande_vitesse_stop();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-26 19:28:13 +00:00
|
|
|
|
|
|
|
void Homologation(uint32_t step_ms){
|
2023-03-28 21:03:35 +00:00
|
|
|
|
2023-03-26 19:28:13 +00:00
|
|
|
|
|
|
|
enum etat_action_t etat_action;
|
2023-03-27 18:40:10 +00:00
|
|
|
enum etat_trajet_t etat_trajet;
|
2023-03-26 19:28:13 +00:00
|
|
|
|
|
|
|
struct trajectoire_t trajectoire;
|
2023-03-26 14:56:34 +00:00
|
|
|
|
2023-05-06 21:46:00 +00:00
|
|
|
switch(etat_homologation){
|
2023-03-26 14:56:34 +00:00
|
|
|
case STRATEGIE_INIT:
|
2023-04-13 17:43:35 +00:00
|
|
|
Localisation_set(775., 109., (-60.+CORR_ANGLE_DEPART_DEGREE) * DEGRE_EN_RADIAN);
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_homologation = ATTENTE_TIRETTE;
|
2023-04-01 13:29:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ATTENTE_TIRETTE:
|
|
|
|
if(attente_tirette() == 0){
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_homologation = APPROCHE_CERISE_1_A;
|
2023-04-01 13:29:54 +00:00
|
|
|
}
|
2023-03-26 19:28:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case APPROCHE_CERISE_1_A:
|
|
|
|
Trajet_config(250, 500);
|
2023-04-13 17:43:35 +00:00
|
|
|
Trajectoire_droite(&trajectoire,775, 109, 857, 156, -60. * DEGRE_EN_RADIAN, 30. * DEGRE_EN_RADIAN);
|
2023-04-01 15:55:24 +00:00
|
|
|
if(parcourt_trajet_simple_sans_evitement(trajectoire, step_ms) == TRAJET_TERMINE){
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_homologation = ATTRAPE_CERISE_1;
|
2023-03-26 19:28:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATTRAPE_CERISE_1:
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_action = cerise_attraper_bordure(LONGER_VERS_C, step_ms, 1000-15-PETIT_RAYON_ROBOT_MM, RAYON_ROBOT);
|
2023-03-26 19:28:13 +00:00
|
|
|
if(etat_action == ACTION_TERMINEE){
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_homologation = APPROCHE_PANIER_1;
|
2023-03-26 19:28:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-03-28 21:03:35 +00:00
|
|
|
case APPROCHE_PANIER_1:
|
|
|
|
Trajet_config(500, 500);
|
2023-03-27 18:38:37 +00:00
|
|
|
Trajectoire_bezier(&trajectoire,Localisation_get().x_mm, Localisation_get().y_mm,
|
|
|
|
485, Localisation_get().y_mm,
|
|
|
|
465, 857,
|
|
|
|
465,2830,
|
2023-04-13 17:43:35 +00:00
|
|
|
+30. * DEGRE_EN_RADIAN, +120. * DEGRE_EN_RADIAN);
|
2023-03-28 21:03:35 +00:00
|
|
|
|
2023-03-29 21:12:16 +00:00
|
|
|
if(parcourt_trajet_simple(trajectoire, step_ms) == ACTION_TERMINEE){
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_homologation = CALAGE_PANIER_1;
|
2023-03-29 21:12:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-03-28 21:03:35 +00:00
|
|
|
case CALAGE_PANIER_1:
|
2023-04-13 17:43:35 +00:00
|
|
|
if(calage_angle(LONGER_VERS_A, RAYON_ROBOT, 3000 - (RAYON_ROBOT/(RACINE_DE_3/2.)), 120. *DEGRE_EN_RADIAN) == ACTION_TERMINEE){
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_homologation = RECULE_PANIER;
|
2023-03-28 21:03:35 +00:00
|
|
|
}
|
2023-03-27 18:38:37 +00:00
|
|
|
break;
|
|
|
|
|
2023-03-28 21:03:35 +00:00
|
|
|
case RECULE_PANIER:
|
|
|
|
Trajet_config(250, 500);
|
|
|
|
Trajectoire_droite(&trajectoire,Localisation_get().x_mm, Localisation_get().y_mm,
|
2023-03-29 21:12:16 +00:00
|
|
|
180, 3000 - (RAYON_ROBOT/(RACINE_DE_3/2)) - 80,
|
2023-04-13 17:43:35 +00:00
|
|
|
120. * DEGRE_EN_RADIAN, +270. * DEGRE_EN_RADIAN);
|
2023-03-28 21:03:35 +00:00
|
|
|
|
2023-04-01 15:55:24 +00:00
|
|
|
if(parcourt_trajet_simple_sans_evitement(trajectoire, step_ms) == ACTION_TERMINEE){
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_homologation = LANCE_DANS_PANIER;
|
2023-03-27 18:38:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-03-28 21:03:35 +00:00
|
|
|
case LANCE_DANS_PANIER:
|
2023-03-29 21:12:16 +00:00
|
|
|
Asser_Position_maintien();
|
2023-03-28 21:03:35 +00:00
|
|
|
if(lance_balles(step_ms) == ACTION_TERMINEE){
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_homologation = STRATEGIE_FIN;
|
2023-04-01 15:55:24 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APPROCHE_CERISE_2:
|
|
|
|
Trajet_config(250, 500);
|
|
|
|
Trajectoire_droite(&trajectoire,Localisation_get().x_mm, Localisation_get().y_mm,
|
|
|
|
830, 3000 - 156,
|
2023-04-13 17:43:35 +00:00
|
|
|
Localisation_get().angle_radian, 30. * DEGRE_EN_RADIAN);
|
2023-04-01 15:55:24 +00:00
|
|
|
|
|
|
|
if(parcourt_trajet_simple_sans_evitement(trajectoire, step_ms) == ACTION_TERMINEE){
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_homologation = STRATEGIE_FIN;
|
2023-03-28 21:03:35 +00:00
|
|
|
}
|
|
|
|
break;
|
2023-04-01 14:44:08 +00:00
|
|
|
|
2023-04-01 15:55:24 +00:00
|
|
|
case ATTRAPPE_CERISE_2:
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_action = cerise_attraper_bordure(LONGER_VERS_A, step_ms, 1000-15-PETIT_RAYON_ROBOT_MM, 3000-RAYON_ROBOT);
|
2023-04-01 15:55:24 +00:00
|
|
|
if(etat_action == ACTION_TERMINEE){
|
2023-05-06 21:46:00 +00:00
|
|
|
etat_homologation = APPROCHE_PANIER_2;
|
2023-04-01 15:55:24 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-04-01 15:03:56 +00:00
|
|
|
|
|
|
|
case STRATEGIE_FIN:
|
|
|
|
i2c_annexe_desactive_propulseur();
|
2023-04-01 15:55:24 +00:00
|
|
|
commande_vitesse_stop();
|
2023-04-01 15:03:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-03-28 21:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-06 21:46:00 +00:00
|
|
|
enum etat_action_t lance_balles_dans_panier(enum couleur_t couleur, uint32_t step_ms){
|
|
|
|
static enum {
|
|
|
|
CALAGE_PANIER_1,
|
|
|
|
RECULE_PANIER,
|
|
|
|
LANCE_DANS_PANIER,
|
|
|
|
}etat_lance_balles_dans_panier;
|
|
|
|
float recal_pos_x, recal_pos_y;
|
|
|
|
enum longer_direction_t longer_direction;
|
|
|
|
float point_x, point_y;
|
|
|
|
|
|
|
|
enum etat_action_t etat_action = ACTION_EN_COURS;
|
|
|
|
|
|
|
|
struct trajectoire_t trajectoire;
|
|
|
|
|
|
|
|
switch(etat_lance_balles_dans_panier){
|
|
|
|
case CALAGE_PANIER_1:
|
|
|
|
if(couleur == COULEUR_BLEU){
|
|
|
|
recal_pos_x = RAYON_ROBOT;
|
|
|
|
longer_direction = LONGER_VERS_A;
|
|
|
|
}else{
|
|
|
|
recal_pos_x = 2000- RAYON_ROBOT;
|
|
|
|
longer_direction = LONGER_VERS_C;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(calage_angle(longer_direction, recal_pos_x, 3000 - (RAYON_ROBOT/(RACINE_DE_3/2.)), 120. *DEGRE_EN_RADIAN) == ACTION_TERMINEE){
|
|
|
|
etat_lance_balles_dans_panier = RECULE_PANIER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECULE_PANIER:
|
|
|
|
Trajet_config(250, 500);
|
|
|
|
if(couleur == COULEUR_BLEU){
|
|
|
|
point_x = 180;
|
|
|
|
point_y = 3000 - (RAYON_ROBOT/(RACINE_DE_3/2)) - 80;
|
|
|
|
}else{
|
|
|
|
point_x = 1735;
|
|
|
|
point_y = 3000 - (RAYON_ROBOT/(RACINE_DE_3/2)) - 80;
|
|
|
|
}
|
|
|
|
Trajectoire_droite(&trajectoire, Localisation_get().x_mm, Localisation_get().y_mm,
|
|
|
|
point_x, point_y,
|
|
|
|
120. * DEGRE_EN_RADIAN, +270. * DEGRE_EN_RADIAN);
|
|
|
|
|
|
|
|
if(parcourt_trajet_simple_sans_evitement(trajectoire, step_ms) == ACTION_TERMINEE){
|
|
|
|
etat_lance_balles_dans_panier = LANCE_DANS_PANIER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LANCE_DANS_PANIER:
|
|
|
|
Asser_Position_maintien();
|
|
|
|
if(lance_balles(step_ms) == ACTION_TERMINEE){
|
|
|
|
etat_action=ACTION_TERMINEE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return etat_action;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-28 21:03:35 +00:00
|
|
|
/// @brief Active le propulseur, ouvre la porte, attend qql secondes.
|
|
|
|
/// @param step_ms : pas de temps.
|
|
|
|
/// @return ACTION_EN_COURS ou ACTION_TERMINEE
|
|
|
|
enum etat_action_t lance_balles(uint32_t step_ms){
|
|
|
|
enum etat_action_t etat_action = ACTION_EN_COURS;
|
2023-04-01 15:55:24 +00:00
|
|
|
static uint32_t tempo_ms;
|
2023-04-23 14:36:08 +00:00
|
|
|
static uint32_t nb_iteration;
|
2023-03-28 21:03:35 +00:00
|
|
|
|
|
|
|
static enum{
|
|
|
|
LANCE_PROPULSEUR_ON,
|
|
|
|
LANCE_TEMPO_PROP_ON,
|
|
|
|
LANCE_PORTE_OUVERTE,
|
2023-04-24 20:43:21 +00:00
|
|
|
LANCE_OUVERTURE_INITIALE,
|
2023-03-28 21:03:35 +00:00
|
|
|
} etat_lance_balle = LANCE_PROPULSEUR_ON;
|
|
|
|
|
|
|
|
switch(etat_lance_balle){
|
|
|
|
case LANCE_PROPULSEUR_ON:
|
|
|
|
i2c_annexe_active_propulseur();
|
2023-04-01 15:55:24 +00:00
|
|
|
tempo_ms = 1000;
|
2023-04-23 14:36:08 +00:00
|
|
|
nb_iteration=0;
|
2023-04-24 20:43:21 +00:00
|
|
|
etat_lance_balle = LANCE_OUVERTURE_INITIALE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LANCE_OUVERTURE_INITIALE:
|
|
|
|
if(temporisation_terminee(&tempo_ms, step_ms)){
|
|
|
|
i2c_annexe_ouvre_porte();
|
|
|
|
etat_lance_balle = LANCE_PORTE_OUVERTE;
|
|
|
|
tempo_ms = 250;
|
|
|
|
}
|
2023-03-28 21:03:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LANCE_TEMPO_PROP_ON:
|
2023-04-24 20:43:21 +00:00
|
|
|
if(temporisation_terminee(&tempo_ms, step_ms)){
|
|
|
|
i2c_annexe_ouvre_porte();
|
2023-04-23 14:36:08 +00:00
|
|
|
nb_iteration++;
|
|
|
|
if(nb_iteration > 10){
|
2023-04-24 20:43:21 +00:00
|
|
|
nb_iteration=0;
|
2023-04-23 14:36:08 +00:00
|
|
|
etat_action = ACTION_TERMINEE;
|
|
|
|
etat_lance_balle = LANCE_PROPULSEUR_ON;
|
|
|
|
i2c_annexe_desactive_propulseur();
|
|
|
|
}else{
|
|
|
|
etat_lance_balle = LANCE_PORTE_OUVERTE;
|
2023-04-24 20:43:21 +00:00
|
|
|
tempo_ms = 150;
|
2023-04-23 14:36:08 +00:00
|
|
|
}
|
2023-03-28 21:03:35 +00:00
|
|
|
}
|
2023-03-26 19:28:13 +00:00
|
|
|
break;
|
2023-03-28 21:03:35 +00:00
|
|
|
|
|
|
|
case LANCE_PORTE_OUVERTE:
|
2023-04-24 20:43:21 +00:00
|
|
|
if(temporisation_terminee(&tempo_ms, step_ms)){
|
|
|
|
i2c_annexe_mi_ferme_porte();
|
2023-04-23 14:36:08 +00:00
|
|
|
etat_lance_balle = LANCE_TEMPO_PROP_ON;
|
2023-05-06 21:46:00 +00:00
|
|
|
tempo_ms = 750;
|
2023-03-28 21:03:35 +00:00
|
|
|
}
|
|
|
|
break;
|
2023-04-23 14:36:08 +00:00
|
|
|
|
2023-03-28 21:03:35 +00:00
|
|
|
}
|
|
|
|
return etat_action;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Envoie le robot se caler dans l'angle en face de lui, recale la localisation
|
2023-04-28 21:51:43 +00:00
|
|
|
enum etat_action_t calage_angle(enum longer_direction_t longer_direction, float x_mm, float y_mm, float angle_radian){
|
2023-03-28 21:03:35 +00:00
|
|
|
enum etat_action_t etat_action = ACTION_EN_COURS;
|
|
|
|
struct position_t position;
|
|
|
|
|
|
|
|
avance_puis_longe_bordure(longer_direction);
|
|
|
|
if( ((longer_direction == LONGER_VERS_A) && (i2c_annexe_get_contacteur_butee_A() == CONTACTEUR_ACTIF) ) ||
|
|
|
|
((longer_direction == LONGER_VERS_C) && (i2c_annexe_get_contacteur_butee_C() == CONTACTEUR_ACTIF) ) ){
|
|
|
|
etat_action = ACTION_TERMINEE;
|
|
|
|
|
|
|
|
position = Localisation_get();
|
|
|
|
if(fabs(position.x_mm - x_mm) < SEUIL_RECAL_DIST_MM){
|
|
|
|
Localisation_set_x(x_mm);
|
|
|
|
}
|
|
|
|
if(fabs(position.y_mm - y_mm) < SEUIL_RECAL_DIST_MM){
|
|
|
|
Localisation_set_y(y_mm);
|
|
|
|
}
|
|
|
|
if(fabs(position.angle_radian - angle_radian) < SEUIL_RECAL_ANGLE_RADIAN){
|
|
|
|
Localisation_set_angle(angle_radian);
|
|
|
|
}
|
2023-03-26 14:56:34 +00:00
|
|
|
}
|
2023-03-28 21:03:35 +00:00
|
|
|
return etat_action;
|
2023-03-27 18:40:10 +00:00
|
|
|
}
|
2023-03-28 21:03:35 +00:00
|
|
|
|
|
|
|
enum etat_action_t parcourt_trajet_simple(struct trajectoire_t trajectoire, uint32_t step_ms){
|
|
|
|
enum etat_action_t etat_action = ACTION_EN_COURS;
|
|
|
|
enum etat_trajet_t etat_trajet;
|
2023-04-28 21:51:43 +00:00
|
|
|
float angle_avancement;
|
2023-04-21 20:33:29 +00:00
|
|
|
|
2023-03-28 21:03:35 +00:00
|
|
|
static enum {
|
|
|
|
PARCOURS_INIT,
|
|
|
|
PARCOURS_AVANCE,
|
|
|
|
} etat_parcourt=PARCOURS_INIT;
|
|
|
|
|
|
|
|
switch (etat_parcourt){
|
|
|
|
case PARCOURS_INIT:
|
|
|
|
Trajet_debut_trajectoire(trajectoire);
|
|
|
|
etat_parcourt = PARCOURS_AVANCE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PARCOURS_AVANCE:
|
2023-04-21 20:33:29 +00:00
|
|
|
angle_avancement = Trajet_get_orientation_avance();
|
|
|
|
distance_obstacle = Balise_VL53L1X_get_distance_obstacle_mm(angle_avancement);
|
|
|
|
Trajet_set_obstacle_mm(distance_obstacle);
|
2023-05-06 21:46:00 +00:00
|
|
|
|
2023-03-28 21:03:35 +00:00
|
|
|
etat_trajet = Trajet_avance(step_ms/1000.);
|
|
|
|
if(etat_trajet == TRAJET_TERMINE){
|
2023-04-21 20:33:29 +00:00
|
|
|
Trajet_set_obstacle_mm(DISTANCE_INVALIDE);
|
2023-03-28 21:03:35 +00:00
|
|
|
etat_action = ACTION_TERMINEE;
|
|
|
|
etat_parcourt = PARCOURS_INIT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return etat_action;
|
|
|
|
}
|
|
|
|
|
2023-04-01 15:55:24 +00:00
|
|
|
enum etat_action_t parcourt_trajet_simple_sans_evitement(struct trajectoire_t trajectoire, uint32_t step_ms){
|
|
|
|
enum etat_action_t etat_action = ACTION_EN_COURS;
|
|
|
|
enum etat_trajet_t etat_trajet;
|
|
|
|
static enum {
|
|
|
|
PARCOURS_INIT,
|
|
|
|
PARCOURS_AVANCE,
|
|
|
|
} etat_parcourt=PARCOURS_INIT;
|
|
|
|
|
|
|
|
switch (etat_parcourt){
|
|
|
|
case PARCOURS_INIT:
|
|
|
|
Trajet_debut_trajectoire(trajectoire);
|
2023-04-21 20:33:29 +00:00
|
|
|
Trajet_set_obstacle_mm(distance_pas_obstacle);
|
2023-04-01 15:55:24 +00:00
|
|
|
etat_parcourt = PARCOURS_AVANCE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PARCOURS_AVANCE:
|
|
|
|
etat_trajet = Trajet_avance(step_ms/1000.);
|
|
|
|
if(etat_trajet == TRAJET_TERMINE){
|
|
|
|
etat_action = ACTION_TERMINEE;
|
|
|
|
etat_parcourt = PARCOURS_INIT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return etat_action;
|
|
|
|
}
|
|
|
|
|
2023-03-28 21:03:35 +00:00
|
|
|
/// @brief Renvoi 1 si on doit attendre le déclenchement de la tirette
|
|
|
|
uint attente_tirette(void){
|
2023-04-01 13:29:54 +00:00
|
|
|
return !gpio_get(TIRETTE);
|
2023-03-28 21:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Renvoi COULEUR_VERT ou COULEUR_BLEU
|
|
|
|
enum couleur_t lire_couleur(void){
|
|
|
|
if (gpio_get(COULEUR))
|
|
|
|
return COULEUR_VERT;
|
|
|
|
return COULEUR_BLEU;
|
|
|
|
|
2023-04-13 17:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Décremente la temps de step_ms, renvoie 1 si la temporisation est écoulée
|
|
|
|
/// @param tempo_ms
|
|
|
|
/// @param step_ms
|
|
|
|
/// @return 1 si la temporisation est écoulée, 0 sinon.
|
|
|
|
int temporisation_terminee(uint32_t * tempo_ms, uint32_t step_ms){
|
|
|
|
if(*tempo_ms < step_ms){
|
|
|
|
return 1;
|
|
|
|
}else{
|
|
|
|
*tempo_ms -= step_ms;
|
|
|
|
return 0;
|
|
|
|
}
|
2023-03-28 21:03:35 +00:00
|
|
|
}
|