Asservissement en position fonctionnel
This commit is contained in:
		
							parent
							
								
									ca8bce87f4
								
							
						
					
					
						commit
						67a49c57cb
					
				
							
								
								
									
										43
									
								
								Asser_Position.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								Asser_Position.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | ||||
| #include "Localisation.h" | ||||
| #include "Commande_vitesse.h" | ||||
| #include "math.h" | ||||
| 
 | ||||
| #define GAIN_P_POSITION 50 | ||||
| #define GAIN_P_ORIENTATION 500 | ||||
| 
 | ||||
| struct position_t position_maintien; | ||||
| 
 | ||||
| /// @brief Asservissement de la position du robot. Les gains sont déterminés pour des positions très proches du robot
 | ||||
| /// C'est à la consigne d'être défini avant pour être atteignable.
 | ||||
| /// Nécessite l'appel des fonctions QEI_update(); Localisation_gestion(); AsserMoteur_Gestion(_step_ms);
 | ||||
| /// @param position_consigne : position à atteindre dans le référentiel de la table.
 | ||||
| void Asser_Position(struct position_t position_consigne){ | ||||
|     float delta_avance_mm; | ||||
|     float avance_mm_s, rotation_radian_s; | ||||
|     float delta_x_mm, delta_y_mm, delta_orientation_radian; | ||||
|     struct position_t position_actuelle; | ||||
| 
 | ||||
|     position_actuelle = Localisation_get(); | ||||
| 
 | ||||
|     // Calcul de l'erreur
 | ||||
|     delta_x_mm = position_consigne.x_mm - position_actuelle.x_mm; | ||||
|     delta_y_mm = position_consigne.y_mm - position_actuelle.y_mm; | ||||
|     delta_avance_mm = sqrtf(delta_x_mm * delta_x_mm + delta_y_mm * delta_y_mm); | ||||
|     delta_orientation_radian = atan2f(delta_y_mm, delta_x_mm) - position_actuelle.angle_radian; | ||||
| 
 | ||||
|     // Asservissement
 | ||||
|     avance_mm_s = delta_avance_mm * GAIN_P_POSITION; | ||||
|     rotation_radian_s = delta_orientation_radian * GAIN_P_ORIENTATION; | ||||
|      | ||||
|     // Commande en vitesse
 | ||||
|     commande_vitesse(avance_mm_s, rotation_radian_s); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| void Asser_Position_set_Pos_Maintien(struct position_t position){ | ||||
|     position_maintien=position; | ||||
| } | ||||
| 
 | ||||
| void Asser_Position_maintien(){ | ||||
|     Asser_Position(position_maintien); | ||||
| } | ||||
							
								
								
									
										4
									
								
								Asser_Position.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								Asser_Position.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| #include "Geometrie.h" | ||||
| void Asser_Position(struct position_t position_consigne); | ||||
| void Asser_Position_set_Pos_Maintien(struct position_t position); | ||||
| void Asser_Position_maintien(); | ||||
| @ -11,6 +11,7 @@ set(PICO_EXAMPLES_PATH ${PROJECT_SOURCE_DIR}) | ||||
| pico_sdk_init() | ||||
| 
 | ||||
| add_executable(Mon_Projet | ||||
|   Asser_Position.c | ||||
|   Asser_Moteurs.c | ||||
|   Commande_vitesse.c | ||||
|   Geometrie.c | ||||
|  | ||||
							
								
								
									
										8
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								main.c
									
									
									
									
									
								
							| @ -7,6 +7,7 @@ | ||||
| #include "pico/multicore.h" | ||||
| #include "hardware/adc.h" | ||||
| #include "hardware/pwm.h" | ||||
| #include "Asser_Position.h" | ||||
| #include "Asser_Moteurs.h" | ||||
| #include "Localisation.h" | ||||
| #include "Commande_vitesse.h" | ||||
| @ -40,6 +41,8 @@ void main(void) | ||||
| 	identifiant_init(); | ||||
| 	Localisation_init(); | ||||
| 	uint32_t temps_ms = Temps_get_temps_ms(); | ||||
| 	struct position_t position_robot={.x_mm=0, .y_mm=0, .angle_radian=0}; | ||||
| 	float vitesse_mm_s=100; | ||||
| 	 | ||||
| 
 | ||||
| 	gpio_init(LED1PIN); | ||||
| @ -49,8 +52,6 @@ void main(void) | ||||
| 	 | ||||
| 	multicore_launch_core1(affichage); | ||||
| 	 | ||||
| 	commande_vitesse(100 , 1.); | ||||
| 
 | ||||
| 
 | ||||
| 	while(1){ | ||||
| 		 | ||||
| @ -58,6 +59,9 @@ void main(void) | ||||
| 			temps_ms = Temps_get_temps_ms(); | ||||
| 			if(temps_ms % step_ms == 0){ | ||||
| 				QEI_update(); | ||||
| 				position_robot.x_mm += temps_ms * vitesse_mm_s / 1000.; | ||||
| 				position_robot.y_mm += temps_ms * vitesse_mm_s / 1000.; | ||||
| 				Asser_Position(position_robot); | ||||
| 				AsserMoteur_Gestion(step_ms); | ||||
| 				Localisation_gestion(); | ||||
| 			} | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user