2022-09-23 17:43:45 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "pico/stdlib.h"
|
|
|
|
#include "hardware/gpio.h"
|
|
|
|
#include "pico/binary_info.h"
|
|
|
|
|
2022-09-23 20:09:40 +00:00
|
|
|
#include "gyro.h"
|
2022-09-26 19:53:52 +00:00
|
|
|
#include "Temps.h"
|
2022-10-15 19:13:52 +00:00
|
|
|
#include "spi_nb.h"
|
|
|
|
#include "Servomoteur.h"
|
2022-09-23 17:43:45 +00:00
|
|
|
|
|
|
|
const uint LED_PIN = 25;
|
|
|
|
|
2022-10-15 19:13:52 +00:00
|
|
|
#define V_INIT -999.0
|
|
|
|
|
2022-09-23 17:43:45 +00:00
|
|
|
int main() {
|
|
|
|
bi_decl(bi_program_description("This is a test binary."));
|
|
|
|
bi_decl(bi_1pin_with_name(LED_PIN, "On-board LED"));
|
2022-10-15 19:13:52 +00:00
|
|
|
double vitesse_filtre_x=V_INIT, vitesse_filtre_y=V_INIT, vitesse_filtre_z=V_INIT;
|
|
|
|
struct t_angle_gyro_double angle_gyro;
|
2022-09-23 17:43:45 +00:00
|
|
|
|
2022-10-15 19:13:52 +00:00
|
|
|
uint32_t temps_ms = 0, temps_ms_old;
|
2022-09-26 19:53:52 +00:00
|
|
|
|
2022-09-23 17:43:45 +00:00
|
|
|
stdio_init_all();
|
|
|
|
|
|
|
|
gpio_init(LED_PIN);
|
|
|
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
|
|
|
gpio_put(LED_PIN, 1);
|
|
|
|
|
2022-09-24 09:38:55 +00:00
|
|
|
sleep_ms(3000);
|
2022-10-15 19:13:52 +00:00
|
|
|
Servomoteur_Init();
|
|
|
|
//puts("Debut");
|
|
|
|
//spi_test();
|
2022-09-23 20:09:40 +00:00
|
|
|
|
2022-10-15 19:13:52 +00:00
|
|
|
//while(1);
|
2022-09-26 19:53:52 +00:00
|
|
|
Temps_init();
|
|
|
|
Gyro_Init();
|
|
|
|
temps_ms = Temps_get_temps_ms();
|
2022-10-15 19:13:52 +00:00
|
|
|
temps_ms_old = temps_ms;
|
2022-09-23 17:43:45 +00:00
|
|
|
while (1) {
|
2022-10-29 11:48:44 +00:00
|
|
|
u_int16_t step_ms = 2;
|
|
|
|
float coef_filtre = 1-0.8;
|
2022-10-15 19:13:52 +00:00
|
|
|
|
2022-10-29 11:48:44 +00:00
|
|
|
while(temps_ms == Temps_get_temps_ms());
|
|
|
|
temps_ms = Temps_get_temps_ms();
|
|
|
|
temps_ms_old = temps_ms;
|
2022-09-26 19:53:52 +00:00
|
|
|
|
|
|
|
// Tous les pas de step_ms
|
2022-10-29 11:48:44 +00:00
|
|
|
if(!(temps_ms % step_ms)){
|
2022-09-26 19:53:52 +00:00
|
|
|
Gyro_Read(step_ms);
|
2022-10-28 21:35:26 +00:00
|
|
|
|
2022-10-15 19:13:52 +00:00
|
|
|
//gyro_affiche(gyro_get_vitesse(), "Angle :");
|
|
|
|
// Filtre
|
|
|
|
angle_gyro = gyro_get_vitesse();
|
|
|
|
if(vitesse_filtre_x == V_INIT){
|
|
|
|
vitesse_filtre_x = angle_gyro.rot_x;
|
|
|
|
vitesse_filtre_y = angle_gyro.rot_y;
|
|
|
|
vitesse_filtre_z = angle_gyro.rot_z;
|
|
|
|
}else{
|
|
|
|
vitesse_filtre_x = vitesse_filtre_x * (1-coef_filtre) + angle_gyro.rot_x * coef_filtre;
|
|
|
|
vitesse_filtre_y = vitesse_filtre_y * (1-coef_filtre) + angle_gyro.rot_y * coef_filtre;
|
|
|
|
vitesse_filtre_z = vitesse_filtre_z * (1-coef_filtre) + angle_gyro.rot_z * coef_filtre;
|
|
|
|
}
|
|
|
|
|
2022-10-29 11:48:44 +00:00
|
|
|
printf("%f, %f\n", (double)temps_ms_old / 1000, vitesse_filtre_z);
|
2022-10-15 19:13:52 +00:00
|
|
|
//gyro_affiche(angle_gyro, "Vitesse (°/s),");
|
2022-10-28 21:35:26 +00:00
|
|
|
|
2022-10-15 19:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Toutes les 50 ms
|
|
|
|
if((Temps_get_temps_ms() % 50) == 0){
|
2022-09-26 19:53:52 +00:00
|
|
|
|
|
|
|
}
|
2022-09-28 16:46:45 +00:00
|
|
|
|
|
|
|
// Toutes les 500 ms
|
2022-09-26 19:53:52 +00:00
|
|
|
if((Temps_get_temps_ms() % 500) == 0){
|
2022-10-15 19:13:52 +00:00
|
|
|
//gyro_affiche(gyro_get_angle(), "Angle :");
|
|
|
|
}
|
|
|
|
// Toutes les secondes
|
|
|
|
if((Temps_get_temps_ms() % 500) == 0){
|
|
|
|
//gyro_get_temp();
|
2022-09-26 19:53:52 +00:00
|
|
|
}
|
2022-09-23 17:43:45 +00:00
|
|
|
}
|
|
|
|
}
|