Comptage des pas : OK
This commit is contained in:
parent
1c8e7efa7a
commit
73bfbecb66
87
main.c
87
main.c
@ -7,6 +7,7 @@
|
|||||||
#include "pico/time.h"
|
#include "pico/time.h"
|
||||||
#include "pico/multicore.h"
|
#include "pico/multicore.h"
|
||||||
#include "hardware/pwm.h"
|
#include "hardware/pwm.h"
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define PIN_STEP 0
|
#define PIN_STEP 0
|
||||||
#define PIN_DIR 1
|
#define PIN_DIR 1
|
||||||
@ -17,8 +18,9 @@
|
|||||||
#define PIN_CONTACTEUR_OUVERT 5
|
#define PIN_CONTACTEUR_OUVERT 5
|
||||||
#define PIN_CONTACTEUR_FERMÉ 6
|
#define PIN_CONTACTEUR_FERMÉ 6
|
||||||
|
|
||||||
#define SENS_BAS 0
|
#define SENS_BAS 1
|
||||||
#define SENS_HAUT 1
|
#define SENS_HAUT 2
|
||||||
|
#define SENS_NONE 3
|
||||||
|
|
||||||
|
|
||||||
bool bouton_Presser = false;
|
bool bouton_Presser = false;
|
||||||
@ -28,6 +30,10 @@ float v_consigne_tr_s=0;
|
|||||||
float acc_tr_s = 50;
|
float acc_tr_s = 50;
|
||||||
const float pas_par_tour = 200;
|
const float pas_par_tour = 200;
|
||||||
float temps_pas= 0.001;
|
float temps_pas= 0.001;
|
||||||
|
int pos_pas;
|
||||||
|
|
||||||
|
float vitesse_nominale_tr_s = 10;
|
||||||
|
uint sens_pas_a_pas=SENS_BAS;
|
||||||
|
|
||||||
struct contacteur_t{
|
struct contacteur_t{
|
||||||
uint gpio;
|
uint gpio;
|
||||||
@ -101,7 +107,8 @@ void affiche_pas_de_temps(){
|
|||||||
printf(">v_actuelle_tr_s:%f\n", v_actuelle_tr_s);
|
printf(">v_actuelle_tr_s:%f\n", v_actuelle_tr_s);
|
||||||
printf(">v_consigne_tr_s:%f\n", v_consigne_tr_s);
|
printf(">v_consigne_tr_s:%f\n", v_consigne_tr_s);
|
||||||
printf(">contacteur_bas:%d\n", contacteur_bas.pos_valide);
|
printf(">contacteur_bas:%d\n", contacteur_bas.pos_valide);
|
||||||
sleep_ms(1);
|
printf(">pos_pas:%d\n", pos_pas);
|
||||||
|
sleep_ms(20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,6 +126,8 @@ void pince_ferme(){
|
|||||||
while(contacteur_fermé.pos_valide){
|
while(contacteur_fermé.pos_valide){
|
||||||
contacteur_update(&contacteur_fermé);
|
contacteur_update(&contacteur_fermé);
|
||||||
}
|
}
|
||||||
|
pwm_set_chan_level(1, PWM_CHAN_B, 30000);
|
||||||
|
sleep_ms(200);
|
||||||
pwm_set_chan_level(1, PWM_CHAN_B, 0);
|
pwm_set_chan_level(1, PWM_CHAN_B, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,6 +136,23 @@ void pas_a_pas_stop(){
|
|||||||
gpio_put(PIN_ENABLE, 1);
|
gpio_put(PIN_ENABLE, 1);
|
||||||
gpio_set_dir(PIN_STEP, GPIO_IN);
|
gpio_set_dir(PIN_STEP, GPIO_IN);
|
||||||
v_consigne_tr_s = 0;
|
v_consigne_tr_s = 0;
|
||||||
|
sens_pas_a_pas=SENS_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pas_a_pas_descend(){
|
||||||
|
gpio_put(PIN_DIR, 0);
|
||||||
|
gpio_put(PIN_ENABLE, 0);
|
||||||
|
gpio_set_dir(PIN_STEP, GPIO_OUT);
|
||||||
|
v_consigne_tr_s = vitesse_nominale_tr_s;
|
||||||
|
sens_pas_a_pas=SENS_BAS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pas_a_pas_monte(){
|
||||||
|
gpio_put(PIN_DIR, 1);
|
||||||
|
gpio_put(PIN_ENABLE, 0);
|
||||||
|
gpio_set_dir(PIN_STEP, GPIO_OUT);
|
||||||
|
v_consigne_tr_s = vitesse_nominale_tr_s;
|
||||||
|
sens_pas_a_pas=SENS_HAUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
@ -162,12 +188,13 @@ void main(void)
|
|||||||
gpio_put(PIN_ENABLE, 1);
|
gpio_put(PIN_ENABLE, 1);
|
||||||
multicore_launch_core1(affiche_pas_de_temps);
|
multicore_launch_core1(affiche_pas_de_temps);
|
||||||
|
|
||||||
float vitesse_nominale_tr_s = 10;
|
|
||||||
|
|
||||||
//sleep_ms(3000);
|
//sleep_ms(3000);
|
||||||
//printf("kartoffen\n");
|
//printf("kartoffen\n");
|
||||||
const uint32_t my_delay=500;
|
const uint32_t my_delay=500;
|
||||||
uint sens_pas_a_pas=SENS_BAS;
|
bool consigne_pas_a_pas_active = false;
|
||||||
|
int consigne_pas_a_pas = 0;
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
contacteur_update(&contacteur_ouvert);
|
contacteur_update(&contacteur_ouvert);
|
||||||
@ -176,6 +203,14 @@ void main(void)
|
|||||||
|
|
||||||
if(sens_pas_a_pas==SENS_BAS && contacteur_bas.pos_valide == 1){
|
if(sens_pas_a_pas==SENS_BAS && contacteur_bas.pos_valide == 1){
|
||||||
pas_a_pas_stop();
|
pas_a_pas_stop();
|
||||||
|
pos_pas = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(consigne_pas_a_pas_active == true){
|
||||||
|
if (abs(pos_pas - consigne_pas_a_pas) < 10){
|
||||||
|
pas_a_pas_stop();
|
||||||
|
consigne_pas_a_pas_active = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
temps_pas = compute_time_step(temps_pas);
|
temps_pas = compute_time_step(temps_pas);
|
||||||
@ -183,28 +218,22 @@ void main(void)
|
|||||||
gpio_put(PIN_STEP, 1);
|
gpio_put(PIN_STEP, 1);
|
||||||
sleep_us(temps_pas * 1000000);
|
sleep_us(temps_pas * 1000000);
|
||||||
gpio_put(PIN_STEP, 0);
|
gpio_put(PIN_STEP, 0);
|
||||||
|
if(sens_pas_a_pas == SENS_HAUT){
|
||||||
|
pos_pas+= 2;
|
||||||
|
}else if(sens_pas_a_pas == SENS_BAS){
|
||||||
|
pos_pas-= 2;
|
||||||
|
}
|
||||||
|
|
||||||
int key = getchar_timeout_us(0); // get any pending key press but don't wait
|
int key = getchar_timeout_us(0); // get any pending key press but don't wait
|
||||||
if (key != PICO_ERROR_TIMEOUT) {
|
if (key != PICO_ERROR_TIMEOUT) {
|
||||||
if(key == 'u' || key == 'U'){
|
if(key == 'u' || key == 'U'){
|
||||||
gpio_put(PIN_DIR, 1);
|
pas_a_pas_monte();
|
||||||
gpio_put(PIN_ENABLE, 0);
|
|
||||||
gpio_set_dir(PIN_STEP, GPIO_OUT);
|
|
||||||
v_consigne_tr_s = vitesse_nominale_tr_s;
|
|
||||||
sens_pas_a_pas=SENS_HAUT;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if(key == 'd' || key == 'D'){
|
if(key == 'd' || key == 'D'){
|
||||||
gpio_put(PIN_DIR, 0);
|
pas_a_pas_descend();
|
||||||
gpio_put(PIN_ENABLE, 0);
|
|
||||||
gpio_set_dir(PIN_STEP, GPIO_OUT);
|
|
||||||
v_consigne_tr_s = vitesse_nominale_tr_s;
|
|
||||||
sens_pas_a_pas=SENS_BAS;
|
|
||||||
}
|
}
|
||||||
if(key == 's' || key == 'S'){
|
if(key == 's' || key == 'S'){
|
||||||
gpio_put(PIN_DIR, 0);
|
pas_a_pas_stop();
|
||||||
gpio_put(PIN_ENABLE, 1);
|
|
||||||
gpio_set_dir(PIN_STEP, GPIO_IN);
|
|
||||||
v_consigne_tr_s = 0;
|
|
||||||
}
|
}
|
||||||
if(key == 'o' || key == 'O'){
|
if(key == 'o' || key == 'O'){
|
||||||
pince_ouvre();
|
pince_ouvre();
|
||||||
@ -212,6 +241,24 @@ void main(void)
|
|||||||
if(key == 'f' || key == 'F'){
|
if(key == 'f' || key == 'F'){
|
||||||
pince_ferme();
|
pince_ferme();
|
||||||
}
|
}
|
||||||
|
if(key == '1'){
|
||||||
|
consigne_pas_a_pas=5000;
|
||||||
|
consigne_pas_a_pas_active=true;
|
||||||
|
if(pos_pas <consigne_pas_a_pas ){
|
||||||
|
pas_a_pas_monte();
|
||||||
|
}else{
|
||||||
|
pas_a_pas_descend();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(key == '2'){
|
||||||
|
consigne_pas_a_pas=15000;
|
||||||
|
consigne_pas_a_pas_active=true;
|
||||||
|
if(pos_pas <consigne_pas_a_pas ){
|
||||||
|
pas_a_pas_monte();
|
||||||
|
}else{
|
||||||
|
pas_a_pas_descend();
|
||||||
|
}
|
||||||
|
}
|
||||||
//printf("%c %d\n", key,key);
|
//printf("%c %d\n", key,key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user