Acceleration progressive
This commit is contained in:
parent
3763484a13
commit
4461d8de50
59
main.c
59
main.c
@ -4,11 +4,54 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/multicore.h"
|
||||
#include <stdio.h>
|
||||
#define PIN_STEP 19
|
||||
#define PIN_DIR 18
|
||||
|
||||
bool bouton_Presser = false;
|
||||
|
||||
float v_actuelle_tr_s=0;
|
||||
float v_consigne_tr_s=0;
|
||||
float acc_tr_s = 50;
|
||||
const float pas_par_tour = 200;
|
||||
float temps_pas= 0.001;
|
||||
|
||||
/// @brief calcule le pas de temps suivant
|
||||
/// @param
|
||||
/// @return
|
||||
float compute_time_step(float temps_pas_s){
|
||||
if(v_actuelle_tr_s != v_consigne_tr_s){
|
||||
// On ajoute l'accélération
|
||||
v_actuelle_tr_s += acc_tr_s * temps_pas_s;
|
||||
//printf(">vit:%f\n", v_actuelle_tr_s);
|
||||
// On vérifie qu'on a pas dépassé la vitesse consigne
|
||||
if(v_actuelle_tr_s > v_consigne_tr_s){
|
||||
v_actuelle_tr_s = v_consigne_tr_s;
|
||||
}
|
||||
}
|
||||
//printf(">vit_2:%f\n", v_actuelle_tr_s);
|
||||
float temps_tr, temps_pas;
|
||||
if(v_actuelle_tr_s != 0){
|
||||
temps_tr = 1 / v_actuelle_tr_s; // 100
|
||||
temps_pas = temps_tr / pas_par_tour; // 5
|
||||
if(temps_pas > 0.001)
|
||||
temps_pas = 0.001;
|
||||
return temps_pas;
|
||||
}
|
||||
return 0.001;
|
||||
}
|
||||
|
||||
void affiche_pas_de_temps(){
|
||||
while(1){
|
||||
printf(">temps_pas:%f\n", temps_pas * 1000000);
|
||||
printf(">v_actuelle_tr_s:%f\n", v_actuelle_tr_s);
|
||||
printf(">v_consigne_tr_s:%f\n", v_consigne_tr_s);
|
||||
sleep_ms(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
stdio_init_all();
|
||||
@ -16,30 +59,40 @@ void main(void)
|
||||
gpio_init(PIN_DIR);
|
||||
gpio_set_dir(PIN_STEP, GPIO_IN);
|
||||
gpio_set_dir(PIN_DIR, GPIO_OUT);
|
||||
multicore_launch_core1(affiche_pas_de_temps);
|
||||
|
||||
float vitesse_nominale_tr_s = 10;
|
||||
|
||||
sleep_ms(3000);
|
||||
printf("kartoffen\n");
|
||||
const uint32_t my_delay=500;
|
||||
|
||||
while(1){
|
||||
sleep_us(my_delay);
|
||||
temps_pas = compute_time_step(temps_pas);
|
||||
//printf(">t_pas:%f\n", temps_pas);
|
||||
sleep_us(temps_pas * 1000000);
|
||||
gpio_put(PIN_STEP, 1);
|
||||
sleep_us(my_delay);
|
||||
sleep_us(temps_pas * 1000000);
|
||||
gpio_put(PIN_STEP, 0);
|
||||
int key = getchar_timeout_us(0); // get any pending key press but don't wait
|
||||
if (key != PICO_ERROR_TIMEOUT) {
|
||||
if(key == 'u' || key == 'U'){
|
||||
gpio_put(PIN_DIR, 0);
|
||||
gpio_set_dir(PIN_STEP, GPIO_OUT);
|
||||
v_consigne_tr_s = vitesse_nominale_tr_s;
|
||||
|
||||
}
|
||||
if(key == 'd' || key == 'D'){
|
||||
gpio_put(PIN_DIR, 1);
|
||||
gpio_set_dir(PIN_STEP, GPIO_OUT);
|
||||
v_consigne_tr_s = vitesse_nominale_tr_s;
|
||||
}
|
||||
if(key == 's' || key == 'S'){
|
||||
gpio_put(PIN_DIR, 0);
|
||||
gpio_set_dir(PIN_STEP, GPIO_IN);
|
||||
v_consigne_tr_s = 0;
|
||||
}
|
||||
printf("%c %d\n", key,key);
|
||||
//printf("%c %d\n", key,key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user