From 189101b849e4395954a315382d1f9599c5d49558 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 1 May 2024 09:23:28 +0200 Subject: [PATCH] =?UTF-8?q?Tentative=20de=20pr=C3=A9-homologation=20:=20ma?= =?UTF-8?q?rquer=20des=20points?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Strategie_2024_plante.c | 79 ++++++++++++++-- Strategie_2024_plante.h | 5 +- Strategie_2024_pots.c | 21 +++-- Strategie_2024_pots.h | 3 + Test_i2c.c | 6 +- Test_strategie_2024.c | 194 ++++++++++++++++++++++++++++++++++++++-- 6 files changed, 281 insertions(+), 27 deletions(-) diff --git a/Strategie_2024_plante.c b/Strategie_2024_plante.c index 2a35382..08610bb 100644 --- a/Strategie_2024_plante.c +++ b/Strategie_2024_plante.c @@ -3,12 +3,14 @@ #include "Geometrie_robot.h" #include "Localisation.h" #include "i2c_annexe.h" -#include "math.h" +#include #include #define ASSER_ANGLE_GAIN_PLANTE_P 1.5 #define ASSER_DISTANCE_GAIN_PLANTE_P 10 +#define RAYON_ZONE_PLANTE_MM 180 + struct position_t liste_zone_plante[]= { {.x_mm = 1500, .y_mm = 1500 }, @@ -30,26 +32,75 @@ enum etat_action_t Strat_2024_aller_zone_plante(enum zone_plante_t zone_plante, angle = atan2f(position_zone_plante.y_mm - position_robot.y_mm, position_zone_plante.x_mm - position_robot.x_mm); return Strategie_tourner_a(angle - ANGLE_PINCE, step_ms); } +/// @brief Indique si la plante se trouve dans la zone de récole (en comptant une marge) +/// @param position_plante : position de la plante +/// @param zone_plante : ID de la zone dans laquelle on pense trouver la plante +/// @return 1 si la plante est dans la zone, 0 si le robot ne trouve pas la plante ou qu'elle est hors zone. +bool est_dans_zone(struct position_t position_plante, enum zone_plante_t zone_plante){ + struct position_t position_zone_plante; + float distance_plante_zone; -enum etat_action_t Strat_2024_aller_a_plante(void){ + position_zone_plante = liste_zone_plante[zone_plante]; + + distance_plante_zone = sqrtf( powf(position_zone_plante.x_mm - position_zone_plante.x_mm, 2) + + powf(position_zone_plante.y_mm - position_zone_plante.y_mm, 2)); + + if(distance_plante_zone < RAYON_ZONE_PLANTE_MM){ + return 1; + } + return 0; +} + +/// @brief Déplace le robot vers une plante, vérifie que la plante est bien dans la zone plante qu'on vise +/// @param zone_plante : ID de la zone dans laquelle on pense trouver la plante +/// @return ACTION_SUCCESS si le robot est prêt à attraper la plante, ACTION_ECHEC si la plante +enum etat_action_t Strat_2024_aller_a_plante(enum zone_plante_t zone_plante){ static enum { SAAP_INIT_DETECTION, SAAP_ASSERV } etat_aller_a_plante = SAAP_INIT_DETECTION; enum validite_vl53l8_t validite; - float angle, distance, commande_vitesse_plante; - static int tempo; + float angle_rad, distance_mm, commande_vitesse_plante; + static int tempo_ms; + static bool entree_dans_zone; switch(etat_aller_a_plante){ case SAAP_INIT_DETECTION: i2c_annexe_set_mode_VL53L8(VL53L8_PLANTE); + tempo_ms = 2000; + entree_dans_zone=false; etat_aller_a_plante = SAAP_ASSERV; break; case SAAP_ASSERV: - i2c_annexe_get_VL53L8(&validite, &angle, &distance); + i2c_annexe_get_VL53L8(&validite, &angle_rad, &distance_mm); if(validite == VL53L8_PLANTE){ - commande_vitesse_plante = (distance - 70) * ASSER_DISTANCE_GAIN_PLANTE_P; + tempo_ms = 2000; + // 1 on s'assure que la plante est dans la zone qu'on recherche ! + if(zone_plante != ZONE_PLANTE_AUCUNE){ + // Cas où on checher une plante dans une zone + struct position_t position_robot, position_plante; + bool robot_dans_zone; + position_robot = Localisation_get(); + position_robot.angle_radian += ANGLE_PINCE + angle_rad; + position_plante = Geometrie_deplace(position_robot, distance_mm); + if( !est_dans_zone(position_plante, zone_plante)){ + return ACTION_ECHEC; + } + robot_dans_zone = est_dans_zone(Localisation_get(), zone_plante); + if(entree_dans_zone == true){ + if(robot_dans_zone == false){ + // Le robot est sorti de la zone + return ACTION_ECHEC; + } + } + if(robot_dans_zone == true){ + entree_dans_zone = true; + } + } + + // 2 on s'assure qu'il n'y a pas de robot en face (TODO) + commande_vitesse_plante = (distance_mm - 70) * ASSER_DISTANCE_GAIN_PLANTE_P; if(commande_vitesse_plante > 300){ commande_vitesse_plante = 300; } @@ -61,8 +112,12 @@ enum etat_action_t Strat_2024_aller_a_plante(void){ } commande_vitesse(cosf(ANGLE_PINCE) * commande_vitesse_plante , - sinf(ANGLE_PINCE) * commande_vitesse_plante , angle * ASSER_ANGLE_GAIN_PLANTE_P); + sinf(ANGLE_PINCE) * commande_vitesse_plante , angle_rad * ASSER_ANGLE_GAIN_PLANTE_P); }else{ + tempo_ms--; + if(tempo_ms <= 0){ + return ACTION_ECHEC; + } } break; } @@ -74,7 +129,7 @@ enum etat_action_t Strat_2024_aller_a_plante(void){ /// @param step_ms /// @param bras_depose_pot : PLANTE_BRAS_1 ou PLANTE_BRAS_6 /// @return ACTION_EN_COURS ou ACTION_TERMINEE -enum etat_action_t Strat_2024_plante_dans_pot(uint step_ms, uint bras_depose_pot){ +enum etat_action_t Strat_2024_plante_dans_pot(uint step_ms, uint bras_depose_pot, enum zone_plante_t zone_plante){ static enum{ PDP_ALLER_PLANTE, PDP_PRE_PRISE_PLANTE, @@ -90,7 +145,7 @@ enum etat_action_t Strat_2024_plante_dans_pot(uint step_ms, uint bras_depose_pot switch (etat_plante_dans_pot) { case PDP_ALLER_PLANTE: - if (Strat_2024_aller_a_plante() == ACTION_TERMINEE){ + if (Strat_2024_aller_a_plante(zone_plante) == ACTION_TERMINEE){ etat_plante_dans_pot=PDP_PRE_PRISE_PLANTE; } break; @@ -152,6 +207,12 @@ enum etat_action_t Strat_2024_plante_dans_pot(uint step_ms, uint bras_depose_pot tempo_ms--; if(tempo_ms <= 0){ etat_plante_dans_pot=PDP_ALLER_PLANTE; + if(bras_depose_pot == PLANTE_BRAS_1){ + i2c_annexe_actionneur_pot(0, BRAS_HAUT, DOIGT_TIENT); + }else{ + i2c_annexe_actionneur_pot(5, BRAS_HAUT, DOIGT_TIENT); + } + return ACTION_TERMINEE; } default: diff --git a/Strategie_2024_plante.h b/Strategie_2024_plante.h index 15a8e16..fd3faa2 100644 --- a/Strategie_2024_plante.h +++ b/Strategie_2024_plante.h @@ -7,8 +7,9 @@ enum zone_plante_t{ ZONE_PLANTE_4=3, ZONE_PLANTE_5=4, ZONE_PLANTE_6=5, + ZONE_PLANTE_AUCUNE=99 }; enum etat_action_t Strat_2024_aller_zone_plante(enum zone_plante_t zone_plante, uint32_t step_ms); -enum etat_action_t Strat_2024_aller_a_plante(); -enum etat_action_t Strat_2024_plante_dans_pot(uint step_ms, uint bras_depose_pot); +enum etat_action_t Strat_2024_aller_a_plante(enum zone_plante_t zone_plante); +enum etat_action_t Strat_2024_plante_dans_pot(uint step_ms, uint bras_depose_pot, enum zone_plante_t zone_plante); diff --git a/Strategie_2024_pots.c b/Strategie_2024_pots.c index 74ff47a..b7f6407 100644 --- a/Strategie_2024_pots.c +++ b/Strategie_2024_pots.c @@ -6,8 +6,7 @@ #include "i2c_annexe.h" #include "Localisation.h" -#define DISTANCE_APPROCHE_POT_MM 300. -#define DISTANCE_ATTRAPE_POT_MM 185. + float angle_bras[6] = { @@ -19,6 +18,16 @@ float angle_bras[6] = -120 * DEGRE_EN_RADIAN }; +float angle_bras_correction[6] = +{ + 0 * DEGRE_EN_RADIAN, + 0 * DEGRE_EN_RADIAN, + 0 * DEGRE_EN_RADIAN, + 0, + 0 * DEGRE_EN_RADIAN, + 7 * DEGRE_EN_RADIAN +}; + enum etat_bras_t{ BRAS_LIBRE, BRAS_OCCUPE, @@ -68,12 +77,12 @@ struct position_t groupe_pot_get_pot(unsigned int groupe_pot, unsigned int num_p } /// @brief A Affiner -/// @param -/// @return +/// @return numéro du bras libre (entre 0 et 5) +int ordre_bras[NB_BRAS]={5, 0, 1, 2, 3, 4}; int get_bras_libre(void){ for (int i=0; i