2023-10-22 16:48:14 +00:00
|
|
|
/*****
|
|
|
|
* Copyright (c) 2023 - Poivron Robotique
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
#include "pico/stdlib.h"
|
2024-04-27 19:21:41 +00:00
|
|
|
#include "pico/multicore.h"
|
2024-04-28 19:03:01 +00:00
|
|
|
#include "hardware/adc.h"
|
2024-03-22 21:30:37 +00:00
|
|
|
#include "hardware/pwm.h"
|
2024-04-28 20:35:20 +00:00
|
|
|
#include "Asser_Position.h"
|
2024-04-27 19:21:41 +00:00
|
|
|
#include "Asser_Moteurs.h"
|
2024-04-28 19:58:09 +00:00
|
|
|
#include "Localisation.h"
|
2024-04-28 20:12:47 +00:00
|
|
|
#include "Commande_vitesse.h"
|
2024-04-27 19:21:41 +00:00
|
|
|
#include "Moteurs.h"
|
|
|
|
#include "Temps.h"
|
2023-10-22 16:48:14 +00:00
|
|
|
#include <stdio.h>
|
2024-03-15 22:45:05 +00:00
|
|
|
#include "QEI.h"
|
2023-10-22 16:48:14 +00:00
|
|
|
|
2024-03-22 21:30:37 +00:00
|
|
|
#define LED1PIN 20
|
|
|
|
|
2024-04-27 19:21:41 +00:00
|
|
|
void affichage(void);
|
2024-04-28 19:03:01 +00:00
|
|
|
void tension_batterie_init(void);
|
|
|
|
uint16_t tension_batterie_lire(void);
|
|
|
|
|
|
|
|
void identifiant_init(void);
|
|
|
|
uint identifiant_lire(void);
|
|
|
|
|
|
|
|
uint32_t step_ms=1;
|
|
|
|
float distance1_mm=0, distance2_mm=0;
|
2024-03-22 21:30:37 +00:00
|
|
|
|
2023-10-22 16:48:14 +00:00
|
|
|
void main(void)
|
|
|
|
{
|
2024-03-22 21:30:37 +00:00
|
|
|
int ledpower = 500;
|
2024-04-28 19:03:01 +00:00
|
|
|
|
2024-03-22 21:30:37 +00:00
|
|
|
|
2024-04-27 19:21:41 +00:00
|
|
|
|
2023-10-22 16:48:14 +00:00
|
|
|
stdio_init_all();
|
2024-04-27 19:21:41 +00:00
|
|
|
AsserMoteur_Init();
|
|
|
|
Temps_init();
|
2024-04-28 19:03:01 +00:00
|
|
|
tension_batterie_init();
|
|
|
|
identifiant_init();
|
2024-04-28 19:58:09 +00:00
|
|
|
Localisation_init();
|
2024-04-27 19:21:41 +00:00
|
|
|
uint32_t temps_ms = Temps_get_temps_ms();
|
2024-04-28 20:35:20 +00:00
|
|
|
struct position_t position_robot={.x_mm=0, .y_mm=0, .angle_radian=0};
|
|
|
|
float vitesse_mm_s=100;
|
2024-04-28 19:03:01 +00:00
|
|
|
|
2024-03-22 21:30:37 +00:00
|
|
|
|
|
|
|
gpio_init(LED1PIN);
|
2024-04-28 19:03:01 +00:00
|
|
|
gpio_set_dir(LED1PIN, GPIO_OUT );
|
2024-03-22 21:30:37 +00:00
|
|
|
gpio_put(LED1PIN, 1);
|
2024-04-27 19:21:41 +00:00
|
|
|
|
2024-04-28 19:03:01 +00:00
|
|
|
|
2024-04-27 19:21:41 +00:00
|
|
|
multicore_launch_core1(affichage);
|
2024-04-28 20:12:47 +00:00
|
|
|
|
2024-03-22 21:30:37 +00:00
|
|
|
|
2023-10-22 16:48:14 +00:00
|
|
|
while(1){
|
2024-04-27 19:21:41 +00:00
|
|
|
|
|
|
|
if(temps_ms != Temps_get_temps_ms()){
|
|
|
|
temps_ms = Temps_get_temps_ms();
|
2024-04-28 19:03:01 +00:00
|
|
|
if(temps_ms % step_ms == 0){
|
|
|
|
QEI_update();
|
2024-04-28 20:35:20 +00:00
|
|
|
position_robot.x_mm += temps_ms * vitesse_mm_s / 1000.;
|
|
|
|
position_robot.y_mm += temps_ms * vitesse_mm_s / 1000.;
|
|
|
|
Asser_Position(position_robot);
|
2024-04-28 19:03:01 +00:00
|
|
|
AsserMoteur_Gestion(step_ms);
|
2024-04-28 19:58:09 +00:00
|
|
|
Localisation_gestion();
|
2024-04-28 19:03:01 +00:00
|
|
|
}
|
2024-04-27 19:21:41 +00:00
|
|
|
if(temps_ms % 100 == 0){
|
2024-04-28 19:03:01 +00:00
|
|
|
identifiant_lire();
|
2024-04-27 19:21:41 +00:00
|
|
|
//printf(">c1:%d\n>c2:%d\n", QEI_get(QEI_A_NAME), QEI_get(QEI_B_NAME) );
|
|
|
|
}
|
|
|
|
}
|
2024-03-22 21:30:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-27 19:21:41 +00:00
|
|
|
void affichage(void){
|
|
|
|
while(1){
|
2024-04-28 19:03:01 +00:00
|
|
|
printf(">c1_mm:%f\n>c2_mm:%f\n", QEI_get_mm(QEI_A_NAME), QEI_get_mm(QEI_B_NAME) );
|
2024-04-27 19:21:41 +00:00
|
|
|
|
2024-04-28 19:03:01 +00:00
|
|
|
/*printf(">m1:%f\n>m2:%f\n", AsserMoteur_getVitesse_mm_s(MOTEUR_A, step_ms), AsserMoteur_getVitesse_mm_s(MOTEUR_B, step_ms) );
|
|
|
|
printf(">m1_c:%f\n>m2_c:%f\n", AsserMoteur_getConsigne_mm_s(MOTEUR_A), AsserMoteur_getConsigne_mm_s(MOTEUR_B) );*/
|
2024-04-28 19:58:09 +00:00
|
|
|
printf(">pos_x:%.1f\n>pos_y:%.1f\n>pos_angle:%.1f\n", Localisation_get().x_mm, Localisation_get().y_mm, Localisation_get().angle_radian);
|
2024-04-27 19:21:41 +00:00
|
|
|
sleep_ms(100);
|
2023-10-22 16:48:14 +00:00
|
|
|
}
|
2024-04-28 19:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tension_batterie_init(void){
|
|
|
|
adc_init();
|
|
|
|
adc_gpio_init(28); // Analog_2
|
|
|
|
adc_select_input(2);
|
|
|
|
adc_run(1); // Free running mode
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t tension_batterie_lire(){
|
|
|
|
uint16_t result = (uint16_t) adc_hw->result;
|
|
|
|
const float conversion_factor = 3.3f / (1 << 12);
|
|
|
|
float v_bat = result * conversion_factor * 11.;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void identifiant_init(){
|
|
|
|
gpio_init(21);
|
|
|
|
gpio_init(22);
|
|
|
|
gpio_init(26);
|
|
|
|
gpio_pull_up(21);
|
|
|
|
gpio_pull_up(22);
|
|
|
|
gpio_pull_up(26);
|
|
|
|
gpio_set_dir(21, GPIO_IN);
|
|
|
|
gpio_set_dir(22, GPIO_IN);
|
|
|
|
gpio_set_dir(26, GPIO_IN);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief !! Arg la GPIO 26 ne répond pas !
|
|
|
|
/// @return
|
|
|
|
uint identifiant_lire(){
|
|
|
|
return (gpio_get(21) << 2)+ (gpio_get(22) << 1) + gpio_get(26);
|
2024-04-27 19:21:41 +00:00
|
|
|
}
|