2023-05-13 20:09:24 +00:00
|
|
|
#include "Strategie.h"
|
|
|
|
#include "Trajet.h"
|
|
|
|
#include "Evitement.h"
|
|
|
|
#include "Geometrie.h"
|
|
|
|
#include "Balise_VL53L1X.h"
|
|
|
|
|
2023-05-13 21:03:23 +00:00
|
|
|
enum etat_action_t Strategie_parcourir_trajet(struct trajectoire_t trajectoire, uint32_t step_ms, enum evitement_t evitement){
|
|
|
|
enum etat_action_t etat_action = ACTION_EN_COURS;
|
|
|
|
enum etat_trajet_t etat_trajet;
|
|
|
|
float angle_avancement;
|
2023-05-20 11:07:54 +00:00
|
|
|
static bool trajet_inverse = false;
|
2023-05-13 21:03:23 +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:
|
|
|
|
if(evitement != SANS_EVITEMENT){
|
|
|
|
angle_avancement = Trajet_get_orientation_avance();
|
|
|
|
distance_obstacle = Balise_VL53L1X_get_distance_obstacle_mm(angle_avancement);
|
|
|
|
Trajet_set_obstacle_mm(distance_obstacle);
|
|
|
|
}
|
|
|
|
|
2023-05-19 21:40:07 +00:00
|
|
|
if(Evitement_get_statu() == OBSTACLE_CONFIRME || Evitement_get_statu() == OBSTACLE_NON_CONFIRME){
|
2023-05-13 21:03:23 +00:00
|
|
|
switch(evitement){
|
|
|
|
case SANS_EVITEMENT:
|
|
|
|
//printf("Evitement lors trajet SANS_EVITEMENT: ERREUR\n");
|
|
|
|
break;
|
|
|
|
case PAUSE_DEVANT_OBSTACLE:
|
|
|
|
// Rien à faire ici
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARRET_DEVANT_OBSTACLE:
|
|
|
|
etat_parcourt = PARCOURS_INIT;
|
2023-05-19 14:43:33 +00:00
|
|
|
return ACTION_ECHEC;
|
2023-05-13 21:03:23 +00:00
|
|
|
|
|
|
|
case RETOUR_SI_OBSTABLE:
|
2023-05-20 11:07:54 +00:00
|
|
|
trajet_inverse = !trajet_inverse;
|
2023-05-13 21:03:23 +00:00
|
|
|
Trajet_inverse();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTOURNEMENT: // TODO
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
etat_trajet = Trajet_avance(step_ms/1000.);
|
|
|
|
if(etat_trajet == TRAJET_TERMINE){
|
2023-05-20 11:07:54 +00:00
|
|
|
if(trajet_inverse){
|
|
|
|
etat_action = ACTION_ECHEC;
|
|
|
|
}else{
|
|
|
|
etat_action = ACTION_TERMINEE;
|
|
|
|
}
|
2023-05-13 21:03:23 +00:00
|
|
|
etat_parcourt = PARCOURS_INIT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return etat_action;
|
2023-05-13 20:09:24 +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;
|
|
|
|
float angle_avancement;
|
|
|
|
|
|
|
|
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:
|
|
|
|
angle_avancement = Trajet_get_orientation_avance();
|
|
|
|
distance_obstacle = Balise_VL53L1X_get_distance_obstacle_mm(angle_avancement);
|
|
|
|
Trajet_set_obstacle_mm(distance_obstacle);
|
|
|
|
|
|
|
|
etat_trajet = Trajet_avance(step_ms/1000.);
|
|
|
|
if(etat_trajet == TRAJET_TERMINE){
|
|
|
|
Trajet_set_obstacle_mm(DISTANCE_INVALIDE);
|
|
|
|
etat_action = ACTION_TERMINEE;
|
|
|
|
etat_parcourt = PARCOURS_INIT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return etat_action;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
Trajet_set_obstacle_mm(distance_pas_obstacle);
|
|
|
|
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;
|
|
|
|
}
|