ouverture et fermeture de la pince, problème de faux positifs
This commit is contained in:
parent
4461d8de50
commit
e20a7708d7
@ -16,6 +16,7 @@ add_executable(Modele_RPiPico
|
||||
|
||||
target_link_libraries(Modele_RPiPico
|
||||
hardware_uart
|
||||
hardware_pwm
|
||||
pico_stdlib
|
||||
pico_multicore
|
||||
)
|
||||
|
||||
73
main.c
73
main.c
@ -5,9 +5,17 @@
|
||||
*/
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "hardware/pwm.h"
|
||||
#include <stdio.h>
|
||||
#define PIN_STEP 19
|
||||
#define PIN_DIR 18
|
||||
#define PIN_STEP 0
|
||||
#define PIN_DIR 1
|
||||
#define PIN_ENABLE 2
|
||||
#define PIN_CC_PWM 3
|
||||
#define PIN_CC_DIR 4
|
||||
#define PIN_CONTACTEUR_BAS 7
|
||||
#define PIN_CONTACTEUR_OUVERT 5
|
||||
#define PIN_CONTACTEUR_FERMÉ 6
|
||||
|
||||
|
||||
bool bouton_Presser = false;
|
||||
|
||||
@ -51,21 +59,73 @@ void affiche_pas_de_temps(){
|
||||
}
|
||||
}
|
||||
|
||||
void pince_ouvre(){
|
||||
gpio_put(PIN_CC_DIR, 1);
|
||||
pwm_set_chan_level(1, PWM_CHAN_B, 16000);
|
||||
while(gpio_get(PIN_CONTACTEUR_OUVERT));
|
||||
pwm_set_chan_level(1, PWM_CHAN_B, 0);
|
||||
}
|
||||
void pince_ferme(){
|
||||
gpio_put(PIN_CC_DIR, 0);
|
||||
pwm_set_chan_level(1, PWM_CHAN_B, 16000);
|
||||
while(gpio_get(PIN_CONTACTEUR_FERMÉ));
|
||||
pwm_set_chan_level(1, PWM_CHAN_B, 0);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
stdio_init_all();
|
||||
|
||||
// Moteur CC
|
||||
gpio_set_function(PIN_CC_PWM, GPIO_FUNC_PWM);
|
||||
pwm_set_wrap(1, (uint16_t)65535);
|
||||
pwm_set_chan_level(1, PWM_CHAN_B, 0);
|
||||
pwm_set_enabled(1, true);
|
||||
gpio_init(PIN_CC_DIR);
|
||||
gpio_set_dir(PIN_CC_DIR, GPIO_OUT);
|
||||
gpio_put(PIN_CC_DIR, 1);
|
||||
|
||||
|
||||
|
||||
// Contacteurs
|
||||
gpio_init(PIN_CONTACTEUR_BAS);
|
||||
gpio_init(PIN_CONTACTEUR_FERMÉ);
|
||||
gpio_init(PIN_CONTACTEUR_OUVERT);
|
||||
|
||||
gpio_pull_down(PIN_CONTACTEUR_BAS);
|
||||
gpio_pull_down(PIN_CONTACTEUR_FERMÉ);
|
||||
gpio_pull_down(PIN_CONTACTEUR_OUVERT);
|
||||
|
||||
gpio_set_dir(PIN_CONTACTEUR_BAS, GPIO_IN);
|
||||
gpio_set_dir(PIN_CONTACTEUR_FERMÉ, GPIO_IN);
|
||||
gpio_set_dir(PIN_CONTACTEUR_OUVERT, GPIO_IN);
|
||||
|
||||
pince_ferme();
|
||||
|
||||
|
||||
// Pas à pas
|
||||
gpio_init(PIN_STEP);
|
||||
gpio_init(PIN_DIR);
|
||||
gpio_init(PIN_ENABLE);
|
||||
gpio_set_dir(PIN_STEP, GPIO_IN);
|
||||
gpio_set_dir(PIN_DIR, GPIO_OUT);
|
||||
multicore_launch_core1(affiche_pas_de_temps);
|
||||
gpio_set_dir(PIN_ENABLE, GPIO_OUT);
|
||||
gpio_put(PIN_ENABLE, 1);
|
||||
//multicore_launch_core1(affiche_pas_de_temps);
|
||||
|
||||
float vitesse_nominale_tr_s = 10;
|
||||
|
||||
sleep_ms(3000);
|
||||
printf("kartoffen\n");
|
||||
//sleep_ms(3000);
|
||||
//printf("kartoffen\n");
|
||||
const uint32_t my_delay=500;
|
||||
|
||||
while(1){
|
||||
printf(">C_ouvert:%d\n", gpio_get(PIN_CONTACTEUR_OUVERT));
|
||||
printf(">C_ferme:%d\n", gpio_get(PIN_CONTACTEUR_FERMÉ));
|
||||
printf(">C_bas:%d\n", gpio_get(PIN_CONTACTEUR_BAS));
|
||||
|
||||
sleep_ms(50);
|
||||
}
|
||||
|
||||
while(1){
|
||||
temps_pas = compute_time_step(temps_pas);
|
||||
@ -78,17 +138,20 @@ void main(void)
|
||||
if (key != PICO_ERROR_TIMEOUT) {
|
||||
if(key == 'u' || key == 'U'){
|
||||
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;
|
||||
|
||||
}
|
||||
if(key == 'd' || key == 'D'){
|
||||
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;
|
||||
}
|
||||
if(key == 's' || key == 'S'){
|
||||
gpio_put(PIN_DIR, 0);
|
||||
gpio_put(PIN_ENABLE, 1);
|
||||
gpio_set_dir(PIN_STEP, GPIO_IN);
|
||||
v_consigne_tr_s = 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user