2022-09-23 17:43:45 +00:00
|
|
|
#include <stdio.h>
|
2022-11-28 19:49:55 +00:00
|
|
|
#include "pico/multicore.h"
|
2022-09-23 17:43:45 +00:00
|
|
|
#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-11-20 12:13:14 +00:00
|
|
|
#include "Moteurs.h"
|
2022-11-20 11:53:12 +00:00
|
|
|
#include "QEI.h"
|
2022-11-28 19:49:55 +00:00
|
|
|
#include "Asser_Moteurs.h"
|
2022-12-01 21:47:51 +00:00
|
|
|
#include "Localisation.h"
|
2022-12-05 20:59:20 +00:00
|
|
|
#include "Commande_vitesse.h"
|
|
|
|
#include "math.h"
|
2022-09-23 17:43:45 +00:00
|
|
|
|
|
|
|
const uint LED_PIN = 25;
|
2022-11-27 10:35:06 +00:00
|
|
|
const uint LED_PIN_ROUGE = 28;
|
|
|
|
const uint LED_PIN_NE_PAS_UTILISER = 22;
|
|
|
|
|
2022-09-23 17:43:45 +00:00
|
|
|
|
2022-10-15 19:13:52 +00:00
|
|
|
#define V_INIT -999.0
|
2022-11-20 11:53:12 +00:00
|
|
|
#define TEST_TIMEOUT_US 10000000
|
2022-10-15 19:13:52 +00:00
|
|
|
|
2022-11-18 14:44:34 +00:00
|
|
|
int mode_test();
|
|
|
|
int test_moteurs();
|
2022-11-27 10:35:06 +00:00
|
|
|
int test_QIE();
|
2022-12-01 21:47:51 +00:00
|
|
|
int test_QIE_mm();
|
2022-11-20 11:53:12 +00:00
|
|
|
int test_vitesse_moteur(enum t_moteur moteur);
|
2022-12-01 21:47:51 +00:00
|
|
|
int test_asser_moteur(void);
|
|
|
|
int test_localisation(void);
|
2022-11-30 19:26:16 +00:00
|
|
|
int test_avance(void);
|
2022-12-05 20:59:20 +00:00
|
|
|
int test_cde_vitesse_rotation();
|
|
|
|
int test_cde_vitesse_rectangle();
|
|
|
|
int test_cde_vitesse_cercle();
|
2022-11-18 14:44:34 +00:00
|
|
|
|
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-11-27 10:35:06 +00:00
|
|
|
gpio_init(LED_PIN_ROUGE);
|
|
|
|
gpio_set_dir(LED_PIN_ROUGE, GPIO_OUT);
|
|
|
|
gpio_put(LED_PIN_ROUGE, 1);
|
|
|
|
|
|
|
|
// Il fuat neutraliser cettte broche qui pourrait interférer avec
|
|
|
|
// la lecture des codeurs. (problème sur la carte électrique)...
|
|
|
|
gpio_init(LED_PIN_NE_PAS_UTILISER);
|
|
|
|
gpio_set_dir(LED_PIN_NE_PAS_UTILISER, GPIO_IN);
|
|
|
|
|
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();
|
2022-11-20 11:53:12 +00:00
|
|
|
Moteur_Init();
|
2022-11-27 10:35:06 +00:00
|
|
|
QEI_init();
|
2022-11-28 19:49:55 +00:00
|
|
|
AsserMoteur_Init();
|
2022-12-01 21:47:51 +00:00
|
|
|
Localisation_init();
|
2022-11-18 14:44:34 +00:00
|
|
|
|
|
|
|
while(mode_test());
|
|
|
|
|
2022-11-20 11:53:12 +00:00
|
|
|
Gyro_Init();
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-09-26 19:53:52 +00:00
|
|
|
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 13:51:52 +00:00
|
|
|
//printf("%#x, %#x\n", (double)temps_ms_old / 1000, vitesse_filtre_z);
|
|
|
|
|
|
|
|
//printf("%d, %d\n", temps_ms, (int32_t) (vitesse_filtre_z * 1000));
|
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-10-29 13:51:52 +00:00
|
|
|
struct t_angle_gyro_double m_gyro;
|
|
|
|
m_gyro = gyro_get_angle();
|
|
|
|
printf("%f, %f\n", (double)temps_ms / 1000, m_gyro.rot_z);
|
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
|
|
|
}
|
|
|
|
}
|
2022-11-18 14:44:34 +00:00
|
|
|
|
|
|
|
// Mode test : renvoie 0 pour quitter le mode test
|
|
|
|
int mode_test(){
|
2022-11-20 11:53:12 +00:00
|
|
|
static int iteration = 3;
|
2022-11-18 14:44:34 +00:00
|
|
|
printf("Appuyez sur une touche pour entrer en mode test :\n");
|
2022-12-01 21:47:51 +00:00
|
|
|
printf("A - pour asser_moteurs (rotation)\n");
|
2022-11-30 19:26:16 +00:00
|
|
|
printf("B - pour avance (asser_moteur)\n");
|
2022-11-27 10:35:06 +00:00
|
|
|
printf("C - pour les codeurs\n");
|
2022-12-01 21:47:51 +00:00
|
|
|
printf("D - pour les codeurs (somme en mm)\n");
|
2022-12-05 20:59:20 +00:00
|
|
|
printf("E - Commande en vitesse - rotation pure\n");
|
|
|
|
printf("F - Commande en vitesse - carré\n");
|
|
|
|
printf("G - Commande en vitesse - cercle\n");
|
2022-11-18 14:44:34 +00:00
|
|
|
printf("M - pour les moteurs\n");
|
2022-12-01 21:47:51 +00:00
|
|
|
printf("L - pour la localisation\n");
|
2022-11-20 11:53:12 +00:00
|
|
|
stdio_flush();
|
|
|
|
int rep = getchar_timeout_us(TEST_TIMEOUT_US);
|
|
|
|
stdio_flush();
|
2022-11-18 14:44:34 +00:00
|
|
|
switch (rep)
|
|
|
|
{
|
2022-11-28 19:49:55 +00:00
|
|
|
case 'a':
|
|
|
|
case 'A':
|
|
|
|
while(test_asser_moteur());
|
|
|
|
break;
|
2022-11-30 19:26:16 +00:00
|
|
|
case 'b':
|
|
|
|
case 'B':
|
|
|
|
while(test_avance());
|
|
|
|
break;
|
|
|
|
|
2022-11-27 10:35:06 +00:00
|
|
|
case 'C':
|
|
|
|
case 'c':
|
|
|
|
while(test_QIE());
|
|
|
|
break;
|
2022-12-01 21:47:51 +00:00
|
|
|
|
|
|
|
case 'D':
|
|
|
|
case 'd':
|
|
|
|
while(test_QIE_mm());
|
|
|
|
break;
|
2022-12-05 20:59:20 +00:00
|
|
|
|
|
|
|
case 'E':
|
|
|
|
case 'e':
|
|
|
|
while(test_cde_vitesse_rotation());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
case 'f':
|
|
|
|
while(test_cde_vitesse_rectangle());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'G':
|
|
|
|
case 'g':
|
|
|
|
while(test_cde_vitesse_cercle());
|
|
|
|
break;
|
2022-12-01 21:47:51 +00:00
|
|
|
|
2022-11-18 14:44:34 +00:00
|
|
|
case 'M':
|
2022-11-20 11:53:12 +00:00
|
|
|
case 'm':
|
2022-11-18 14:44:34 +00:00
|
|
|
/* code */
|
2022-11-20 11:53:12 +00:00
|
|
|
while(test_moteurs());
|
2022-11-18 14:44:34 +00:00
|
|
|
break;
|
2022-12-01 21:47:51 +00:00
|
|
|
case 'L':
|
|
|
|
case 'l':
|
|
|
|
/* code */
|
|
|
|
while(test_localisation());
|
|
|
|
break;
|
2022-11-18 14:44:34 +00:00
|
|
|
case PICO_ERROR_TIMEOUT:
|
2022-11-20 11:53:12 +00:00
|
|
|
iteration--;
|
|
|
|
if(iteration == 0){
|
|
|
|
printf("Sortie du mode test\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2022-11-18 14:44:34 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Commande inconnue\n");
|
|
|
|
break;
|
|
|
|
}
|
2022-11-20 11:53:12 +00:00
|
|
|
return 1;
|
2022-11-18 14:44:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-28 19:49:55 +00:00
|
|
|
|
2022-12-05 20:59:20 +00:00
|
|
|
int test_cde_vitesse_rotation(){
|
|
|
|
int lettre, _step_ms = 1;
|
|
|
|
double vitesse =90.0/2 * 3.14159 /180.0;
|
|
|
|
printf("Rotation du robot sur lui-même en 8 secondes\nVitesse : %f rad/s\n", vitesse);
|
|
|
|
|
|
|
|
commande_vitesse(0, 0, vitesse);
|
|
|
|
do{
|
|
|
|
QEI_update();
|
|
|
|
AsserMoteur_Gestion(_step_ms);
|
|
|
|
sleep_ms(_step_ms);
|
|
|
|
lettre = getchar_timeout_us(0);
|
|
|
|
}while(lettre == PICO_ERROR_TIMEOUT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_cde_vitesse_rectangle(){
|
|
|
|
int lettre, _step_ms = 1, temps_ms=0;
|
|
|
|
|
|
|
|
printf("déplacement en rectangle du robot : 500x200 mm, 100 mm/s\n");
|
|
|
|
do{
|
|
|
|
QEI_update();
|
|
|
|
AsserMoteur_Gestion(_step_ms);
|
|
|
|
|
|
|
|
if(temps_ms < 5000){
|
|
|
|
commande_vitesse(0, 100, 0);
|
|
|
|
}else if(temps_ms < 7000){
|
|
|
|
commande_vitesse(-100, 0, 0);
|
|
|
|
}else if(temps_ms < 12000){
|
|
|
|
commande_vitesse(0, -100, 0);
|
|
|
|
}else if(temps_ms < 14000){
|
|
|
|
commande_vitesse(100, 0, 0);
|
|
|
|
}else{
|
|
|
|
temps_ms = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep_ms(_step_ms);
|
|
|
|
temps_ms += _step_ms;
|
|
|
|
lettre = getchar_timeout_us(0);
|
|
|
|
}while(lettre == PICO_ERROR_TIMEOUT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_cde_vitesse_cercle(){
|
|
|
|
int lettre, _step_ms = 1, temps_ms=0;
|
|
|
|
uint64_t t_apres, t_avant;
|
|
|
|
|
|
|
|
printf("déplacement en cercle du robot : 100 mm/s\n");
|
|
|
|
do{
|
|
|
|
QEI_update();
|
|
|
|
AsserMoteur_Gestion(_step_ms);
|
|
|
|
commande_vitesse(cos((double)temps_ms / 1000.) * 200.0, sin((double)temps_ms /1000.) * 200.0, 0);
|
|
|
|
temps_ms += _step_ms;
|
|
|
|
sleep_ms(_step_ms);
|
|
|
|
|
|
|
|
|
|
|
|
lettre = getchar_timeout_us(0);
|
|
|
|
}while(lettre == PICO_ERROR_TIMEOUT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-30 19:26:16 +00:00
|
|
|
int test_avance(void){
|
|
|
|
int lettre;
|
|
|
|
int _step_ms = 1;
|
|
|
|
AsserMoteur_setConsigne_mm_s(MOTEUR_A, 500);
|
|
|
|
AsserMoteur_setConsigne_mm_s(MOTEUR_B, -500);
|
|
|
|
AsserMoteur_setConsigne_mm_s(MOTEUR_C, 0);
|
|
|
|
|
|
|
|
do{
|
|
|
|
QEI_update();
|
|
|
|
AsserMoteur_Gestion(_step_ms);
|
|
|
|
sleep_ms(_step_ms);
|
|
|
|
lettre = getchar_timeout_us(0);
|
|
|
|
|
|
|
|
}while(lettre == PICO_ERROR_TIMEOUT);
|
|
|
|
Moteur_SetVitesse(MOTEUR_A, 0);
|
|
|
|
Moteur_SetVitesse(MOTEUR_B, 0);
|
|
|
|
Moteur_SetVitesse(MOTEUR_C, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-28 19:49:55 +00:00
|
|
|
void test_asser_moteur_printf(){
|
|
|
|
int _step_ms = 1;
|
|
|
|
while(1){
|
|
|
|
printf("Vitesse A : %.0f, vitesse B : %.0f, vitesse C : %.0f\n", AsserMoteur_getVitesse_mm_s(MOTEUR_A, _step_ms),
|
|
|
|
AsserMoteur_getVitesse_mm_s(MOTEUR_B, _step_ms), AsserMoteur_getVitesse_mm_s(MOTEUR_C, _step_ms));
|
|
|
|
//sleep_ms(5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_asser_moteur(){
|
|
|
|
int lettre;
|
|
|
|
int _step_ms = 1;
|
|
|
|
printf("Asservissement des moteurs :\nAppuyez sur une touche pour quitter\n");
|
2022-12-05 20:59:20 +00:00
|
|
|
AsserMoteur_setConsigne_mm_s(MOTEUR_A, 100);
|
|
|
|
AsserMoteur_setConsigne_mm_s(MOTEUR_B, 100);
|
|
|
|
AsserMoteur_setConsigne_mm_s(MOTEUR_C, 100);
|
2022-11-28 19:49:55 +00:00
|
|
|
multicore_launch_core1(test_asser_moteur_printf);
|
|
|
|
do{
|
|
|
|
QEI_update();
|
|
|
|
AsserMoteur_Gestion(_step_ms);
|
|
|
|
sleep_ms(_step_ms);
|
|
|
|
//printf("Vitesse A : %d, codeur B : %d, codeur C : %d\n", QEI_get(QEI_A_NAME), QEI_get(QEI_B_NAME), QEI_get(QEI_C_NAME));
|
|
|
|
//printf("Vitesse A : %.0f, vitesse B : %.0f, vitesse C : %.0f\n", AsserMoteur_getVitesse_mm_s(MOTEUR_A, _step_ms),
|
|
|
|
// AsserMoteur_getVitesse_mm_s(MOTEUR_B, _step_ms), AsserMoteur_getVitesse_mm_s(MOTEUR_C, _step_ms));
|
|
|
|
lettre = getchar_timeout_us(0);
|
|
|
|
}while(lettre == PICO_ERROR_TIMEOUT);
|
2022-11-30 19:26:16 +00:00
|
|
|
Moteur_SetVitesse(MOTEUR_A, 0);
|
|
|
|
Moteur_SetVitesse(MOTEUR_B, 0);
|
|
|
|
Moteur_SetVitesse(MOTEUR_C, 0);
|
2022-11-28 19:49:55 +00:00
|
|
|
multicore_reset_core1();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-27 10:35:06 +00:00
|
|
|
int test_QIE(){
|
|
|
|
int lettre;
|
|
|
|
printf("Affichage des QEI :\nAppuyez sur une touche pour quitter\n");
|
|
|
|
do{
|
|
|
|
QEI_update();
|
2022-12-01 21:47:51 +00:00
|
|
|
printf("Codeur A : %d (%3.2f mm), codeur B : %d (%3.2f mm), codeur C : %d (%3.2f mm)\n",
|
|
|
|
QEI_get(QEI_A_NAME), QEI_get_mm(QEI_A_NAME),
|
|
|
|
QEI_get(QEI_B_NAME), QEI_get_mm(QEI_B_NAME),
|
|
|
|
QEI_get(QEI_C_NAME), QEI_get_mm(QEI_C_NAME));
|
|
|
|
sleep_ms(100);
|
|
|
|
|
|
|
|
lettre = getchar_timeout_us(0);
|
|
|
|
}while(lettre == PICO_ERROR_TIMEOUT);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_QIE_mm(){
|
|
|
|
int lettre;
|
|
|
|
printf("Affichage des QEI :\nAppuyez sur une touche pour quitter\n");
|
|
|
|
double a_mm=0, b_mm=0, c_mm=0;
|
|
|
|
do{
|
|
|
|
QEI_update();
|
|
|
|
a_mm += QEI_get_mm(QEI_A_NAME);
|
|
|
|
b_mm += QEI_get_mm(QEI_B_NAME);
|
|
|
|
c_mm += QEI_get_mm(QEI_C_NAME);
|
|
|
|
printf("Codeur A : %3.2f mm, codeur B : %3.2f mm, codeur C : %3.2f mm\n", a_mm, b_mm, c_mm);
|
2022-11-27 10:35:06 +00:00
|
|
|
sleep_ms(100);
|
|
|
|
|
|
|
|
lettre = getchar_timeout_us(0);
|
|
|
|
}while(lettre == PICO_ERROR_TIMEOUT);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-01 21:47:51 +00:00
|
|
|
int test_localisation(){
|
|
|
|
int lettre;
|
|
|
|
struct position_t position;
|
|
|
|
|
|
|
|
printf("Affichage de la position du robot.\nAppuyez sur une touche pour quitter\n");
|
|
|
|
do{
|
|
|
|
QEI_update();
|
|
|
|
Localisation_gestion();
|
|
|
|
position = Localisation_get();
|
|
|
|
printf("X: %f, Y: %f, angle: %f\n", position.x_mm, position.y_mm, position.angle_radian *180. / 3.141592654);
|
|
|
|
sleep_ms(100);
|
|
|
|
|
|
|
|
lettre = getchar_timeout_us(0);
|
|
|
|
}while(lettre == PICO_ERROR_TIMEOUT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-18 14:44:34 +00:00
|
|
|
int test_moteurs(){
|
2022-11-20 11:53:12 +00:00
|
|
|
int lettre_moteur;
|
|
|
|
|
2022-11-18 14:44:34 +00:00
|
|
|
printf("Indiquez le moteurs à tester (A, B ou C):\n");
|
2022-11-20 11:53:12 +00:00
|
|
|
do{
|
|
|
|
lettre_moteur = getchar_timeout_us(TEST_TIMEOUT_US);
|
2022-11-27 10:35:06 +00:00
|
|
|
stdio_flush();
|
2022-11-20 11:53:12 +00:00
|
|
|
}while(lettre_moteur == PICO_ERROR_TIMEOUT);
|
|
|
|
printf("Moteur choisi : %c %d %x\n", lettre_moteur, lettre_moteur, lettre_moteur);
|
|
|
|
|
|
|
|
switch (lettre_moteur)
|
|
|
|
{
|
|
|
|
case 'A':
|
|
|
|
case 'a':
|
|
|
|
while(test_vitesse_moteur(MOTEUR_A));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'B':
|
|
|
|
case 'b':
|
|
|
|
while(test_vitesse_moteur(MOTEUR_B));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
case 'c':
|
|
|
|
while(test_vitesse_moteur(MOTEUR_C));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Q':
|
|
|
|
case 'q':
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_vitesse_moteur(enum t_moteur moteur){
|
|
|
|
printf("Vitesse souhaitée :\n0 - 0%%\n1 - 10%%\n2 - 20%%\n...\n9 - 90%%\nA - 100%%\n");
|
|
|
|
|
|
|
|
int vitesse_moteur;
|
|
|
|
do{
|
|
|
|
vitesse_moteur = getchar_timeout_us(TEST_TIMEOUT_US);
|
2022-11-27 10:35:06 +00:00
|
|
|
stdio_flush();
|
2022-11-20 11:53:12 +00:00
|
|
|
}while(vitesse_moteur == PICO_ERROR_TIMEOUT);
|
|
|
|
|
|
|
|
switch (vitesse_moteur)
|
|
|
|
{
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
case '8':
|
|
|
|
case '9':
|
|
|
|
printf("Vitesse choisie : %c0%%\n", vitesse_moteur);
|
|
|
|
Moteur_SetVitesse(moteur, (vitesse_moteur - '0') * 32767.0 / 10.);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'A':
|
|
|
|
case 'a':
|
|
|
|
printf("Vitesse choisie : 100%%\n");
|
|
|
|
Moteur_SetVitesse(moteur, (int16_t) 32766.0);
|
|
|
|
break;
|
2022-11-30 19:26:16 +00:00
|
|
|
|
|
|
|
case 'b':
|
|
|
|
case 'B':
|
|
|
|
printf("Vitesse choisie : -50%%\n");
|
|
|
|
Moteur_SetVitesse(moteur, (int16_t) -32766.0/2);
|
|
|
|
break;
|
2022-11-20 11:53:12 +00:00
|
|
|
|
|
|
|
case 'q':
|
|
|
|
case 'Q':
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
2022-11-30 19:26:16 +00:00
|
|
|
}
|