2022-12-19 18:04:24 +00:00
|
|
|
#include "gyro.h"
|
2022-12-01 21:47:51 +00:00
|
|
|
#include "Localisation.h"
|
|
|
|
#include "QEI.h"
|
|
|
|
#include "math.h"
|
2022-12-04 16:51:21 +00:00
|
|
|
#include "Geometrie_robot.h"
|
2022-12-19 18:04:24 +00:00
|
|
|
#include "Robot_config.h"
|
2022-12-01 21:47:51 +00:00
|
|
|
|
|
|
|
struct position_t position;
|
|
|
|
|
|
|
|
void Localisation_init(){
|
|
|
|
position.x_mm = 0;
|
|
|
|
position.y_mm = 0;
|
|
|
|
position.angle_radian = 0;
|
|
|
|
}
|
|
|
|
|
2023-04-28 21:51:43 +00:00
|
|
|
void Localisation_set(float x_mm, float y_mm, float angle_radian){
|
2023-03-26 14:56:34 +00:00
|
|
|
position.x_mm = x_mm;
|
|
|
|
position.y_mm = y_mm;
|
|
|
|
position.angle_radian = angle_radian;
|
2023-03-29 21:11:04 +00:00
|
|
|
gyro_set_angle_radian(angle_radian);
|
2023-03-26 14:56:34 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 21:51:43 +00:00
|
|
|
void Localisation_set_x(float x_mm){
|
2023-03-26 14:56:34 +00:00
|
|
|
position.x_mm = x_mm;
|
|
|
|
}
|
|
|
|
|
2023-04-28 21:51:43 +00:00
|
|
|
void Localisation_set_y(float y_mm){
|
2023-03-26 14:56:34 +00:00
|
|
|
position.y_mm = y_mm;
|
|
|
|
}
|
|
|
|
|
2023-04-28 21:51:43 +00:00
|
|
|
void Localisation_set_angle(float angle_radian){
|
2023-03-26 14:56:34 +00:00
|
|
|
position.angle_radian = angle_radian;
|
|
|
|
}
|
|
|
|
|
2022-12-01 21:47:51 +00:00
|
|
|
void Localisation_gestion(){
|
2023-04-28 21:51:43 +00:00
|
|
|
struct t_angle_gyro_float angle_gyro;
|
2022-12-01 21:47:51 +00:00
|
|
|
// Voir http://poivron-robotique.fr/Robot-holonome-localisation-partie-2.html
|
2023-04-28 21:51:43 +00:00
|
|
|
float distance_roue_a_mm = QEI_get_mm(QEI_A_NAME);
|
|
|
|
float distance_roue_b_mm = QEI_get_mm(QEI_B_NAME);
|
|
|
|
float distance_roue_c_mm = QEI_get_mm(QEI_C_NAME);
|
|
|
|
float delta_x_ref_robot, delta_y_ref_robot;
|
2022-12-01 21:47:51 +00:00
|
|
|
|
2023-04-28 21:51:43 +00:00
|
|
|
float old_orientation_radian = position.angle_radian;
|
2023-02-19 16:56:45 +00:00
|
|
|
|
2022-12-01 21:47:51 +00:00
|
|
|
delta_x_ref_robot = (distance_roue_a_mm + distance_roue_b_mm - 2 * distance_roue_c_mm) / 3.0;
|
|
|
|
delta_y_ref_robot = (-distance_roue_a_mm + distance_roue_b_mm) * RACINE_DE_3 / 3.0;
|
|
|
|
|
2022-12-19 18:04:24 +00:00
|
|
|
if(get_position_avec_gyroscope()){
|
|
|
|
angle_gyro = gyro_get_angle_degres();
|
|
|
|
position.angle_radian = angle_gyro.rot_z / 180. * M_PI ;
|
|
|
|
}else{
|
|
|
|
position.angle_radian += - ( distance_roue_a_mm + distance_roue_b_mm + distance_roue_c_mm) / (3 * DISTANCE_ROUES_CENTRE_MM);
|
|
|
|
}
|
2022-12-01 21:47:51 +00:00
|
|
|
|
2023-02-19 16:56:45 +00:00
|
|
|
// Projection dans le référentiel de la table
|
2023-04-28 21:51:43 +00:00
|
|
|
position.x_mm += delta_x_ref_robot * cosf(position.angle_radian) - delta_y_ref_robot * sinf(position.angle_radian);
|
|
|
|
position.y_mm += delta_x_ref_robot * sinf(position.angle_radian) + delta_y_ref_robot * cosf(position.angle_radian);
|
2022-12-01 21:47:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct position_t Localisation_get(void){
|
|
|
|
return position;
|
|
|
|
}
|