Correction rotation + ajout fonction PWM dans AsserMoteur

This commit is contained in:
Samuel 2026-07-22 22:01:00 +02:00
parent d1f7efe398
commit 5b2edfcfd1
6 changed files with 34 additions and 7 deletions

View File

@ -1,5 +1,6 @@
#include <stdint.h> #include <stdint.h>
#include "Asser_Moteurs.h" #include "Asser_Moteurs.h"
#include "Moteurs.h"
#include "Plateforme.h" #include "Plateforme.h"
#define NB_MOTEURS 2 #define NB_MOTEURS 2
@ -18,6 +19,29 @@ void AsserMoteur_Init(){
} }
} }
/// @brief Défini une commande PMW pour le moteur indiqué.
/// @param moteur : Moteur à commande
/// @param vitesse : Vitesse entre -32767 et 32767
void AsserMoteur_commande_PWM(enum t_moteur moteur, int16_t commande_PWM){
Moteur_SetVitesse(moteur, commande_PWM);
asser_actif[moteur] = 0;
}
void AsserMoteur_moteur_off(enum t_moteur moteur){
Moteur_SetVitesse(moteur, 0);
asser_actif[moteur] = 0;
}
void AsserMoteur_moteurs_off(){
for(enum t_moteur moteur=MOTEUR_A; moteur<NB_MOTEURS; moteur++ ){
Moteur_SetVitesse(moteur, 0);
asser_actif[moteur] = 0;
}
}
/// @brief Défini une consigne de vitesse pour le moteur indiqué. /// @brief Défini une consigne de vitesse pour le moteur indiqué.
/// @param moteur : Moteur à asservir /// @param moteur : Moteur à asservir
/// @param _consigne_mm_s : consigne de vitesse en mm/s /// @param _consigne_mm_s : consigne de vitesse en mm/s

View File

@ -1,10 +1,13 @@
#include "Moteurs.h"
#include "QEI.h" #include "QEI.h"
#include "Moteurs.h"
uint32_t AsserMoteur_RobotImmobile(int step_ms); uint32_t AsserMoteur_RobotImmobile(int step_ms);
void AsserMoteur_setConsigne_mm_s(enum t_moteur moteur, float consigne_mm_s); void AsserMoteur_setConsigne_mm_s(enum t_moteur moteur, float consigne_mm_s);
float AsserMoteur_getConsigne_mm_s(enum t_moteur moteur); float AsserMoteur_getConsigne_mm_s(enum t_moteur moteur);
float AsserMoteur_getVitesse_mm_s(enum t_moteur moteur, int step_ms); float AsserMoteur_getVitesse_mm_s(enum t_moteur moteur, int step_ms);
void AsserMoteur_commande_PWM(enum t_moteur moteur, int16_t commande_PWM);
void AsserMoteur_moteur_off(enum t_moteur moteur);
void AsserMoteur_moteurs_off();
void AsserMoteur_Gestion(int step_ms); void AsserMoteur_Gestion(int step_ms);
void AsserMoteur_Init(void); void AsserMoteur_Init(void);
void AsserMoteurs_stop(void); void AsserMoteurs_stop(void);

View File

@ -3,6 +3,7 @@
#include "Asser_Moteurs.h" #include "Asser_Moteurs.h"
#include "Rotation.h"
#include "Trajet.h" #include "Trajet.h"
enum evitement_t{ enum evitement_t{

View File

@ -27,7 +27,7 @@
// Codeurs // Codeurs
#define PIN_QEI_CODEUR_A 11 #define PIN_QEI_CODEUR_A 11
#define PIN_QEI_CODEUR_B 2 #define PIN_QEI_CODEUR_B 2
#define IMPULSION_PAR_MM_50_1 (12.45f) #define IMPULSION_PAR_MM_50_1 (14.15f)
#define IMPULSION_PAR_MM_30_1 (7.47f) #define IMPULSION_PAR_MM_30_1 (7.47f)
#define IMPULSION_PAR_MM IMPULSION_PAR_MM_50_1 #define IMPULSION_PAR_MM IMPULSION_PAR_MM_50_1
// Asservissement en position // Asservissement en position

View File

@ -41,7 +41,7 @@ Dans le fichier CMakeLists.txt, ajouter le dossier du sub module:
add_subdirectory(Module_deplacement_robot_differentiel) add_subdirectory(Module_deplacement_robot_differentiel)
Dans le fichier CMakeLists.txt, ajouter la bibliothèque RP2040_Servomoteur : Dans le fichier CMakeLists.txt, ajouter la bibliothèque Deplacement_Robot_differentiel :
target_link_libraries(Modele_RPiPico target_link_libraries(Modele_RPiPico
... ...

View File

@ -17,8 +17,8 @@ void rotation_init(float angle_cible){
struct position_t position = Localisation_get(); struct position_t position = Localisation_get();
rotation_angle_cible = Geometrie_get_angle_optimal(position.angle_radian, angle_cible); rotation_angle_cible = Geometrie_get_angle_optimal(position.angle_radian, angle_cible);
rotation_vitesse_rad_s = 0; rotation_vitesse_rad_s = 0;
rotation_vitesse_max_rad_s = 5; rotation_vitesse_max_rad_s = 2;
rotation_acceleration_rad_ss = 25; rotation_acceleration_rad_ss = 4;
if(rotation_angle_cible - position.angle_radian > 0){ if(rotation_angle_cible - position.angle_radian > 0){
rotation_angle_sens = 1; rotation_angle_sens = 1;
@ -41,13 +41,12 @@ void rotation_set_vitesse(float vitesse_rad_s){
enum etat_trajet_t rotation_gestion(float pas_de_temps_s){ enum etat_trajet_t rotation_gestion(float pas_de_temps_s){
struct position_t position = Localisation_get(); struct position_t position = Localisation_get();
rotation_vitesse_rad_s = Rotation_calcul_vitesse(position.angle_radian, pas_de_temps_s); rotation_vitesse_rad_s = Rotation_calcul_vitesse(position.angle_radian, pas_de_temps_s);
rotation_set_vitesse(rotation_vitesse_rad_s);
if (rotation_angle_sens == 1 ){ if (rotation_angle_sens == 1 ){
rotation_set_vitesse(rotation_vitesse_rad_s);
if (position.angle_radian > rotation_angle_cible){ if (position.angle_radian > rotation_angle_cible){
return TRAJET_TERMINE; return TRAJET_TERMINE;
} }
}else{ }else{
if (position.angle_radian < rotation_angle_cible){ if (position.angle_radian < rotation_angle_cible){
return TRAJET_TERMINE; return TRAJET_TERMINE;