Ça marche 2025
This commit is contained in:
parent
080e154459
commit
8392148a16
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -3,6 +3,7 @@
|
||||
"stdlib.h": "c",
|
||||
"stdio.h": "c",
|
||||
"i2c_slave.h": "c",
|
||||
"i2c.h": "c"
|
||||
"i2c.h": "c",
|
||||
"moteur.h": "c"
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ add_executable(Mon_Projet
|
||||
i2c_slave.c
|
||||
communication.c
|
||||
moteur.c
|
||||
Servomoteur.c
|
||||
)
|
||||
|
||||
target_include_directories(Mon_Projet PRIVATE Mon_Projet_ULD_API/inc/)
|
||||
|
88
Servomoteur.c
Normal file
88
Servomoteur.c
Normal file
@ -0,0 +1,88 @@
|
||||
#include "moteur.h"
|
||||
|
||||
// Define pins servo
|
||||
#define SERVO1_PIN 20
|
||||
#define SERVO2_PIN 21
|
||||
|
||||
// S0 : 26 - PWM 5 - Chan A
|
||||
// S1 : 22 - PWM 3 - Chan A
|
||||
// S2 : 21 - PWM 2 - Chan B
|
||||
// S3 : 20 - PWM 2 - Chan A
|
||||
// S4 : 27 - PWM 5 - Chan B
|
||||
|
||||
void Servomoteur_init(){
|
||||
// Set wrap of pwm slice
|
||||
pwm_set_wrap(2, 25000);
|
||||
pwm_set_wrap(3, 25000);
|
||||
pwm_set_wrap(5, 25000);
|
||||
|
||||
// Set clock div for this pwm slice
|
||||
pwm_set_clkdiv(2, 100);
|
||||
pwm_set_clkdiv(3, 100);
|
||||
pwm_set_clkdiv(5, 100);
|
||||
|
||||
// Enable pwm slice
|
||||
pwm_set_enabled(2, true);
|
||||
pwm_set_enabled(3, true);
|
||||
pwm_set_enabled(5, true);
|
||||
|
||||
// Set channel level
|
||||
pwm_set_chan_level(2, PWM_CHAN_A, 2800); // S3 - Ouvert : 1700 - Fermé : 2800
|
||||
pwm_set_chan_level(2, PWM_CHAN_B, 2650); // S2 - Ouvert : 1500 - Fermé : 2650
|
||||
pwm_set_chan_level(3, PWM_CHAN_A, 2300); // S1 - 2300 Pousse, 1500 Neutre
|
||||
pwm_set_chan_level(5, PWM_CHAN_A, 900); // S0 - Dépose 900 - 1750
|
||||
pwm_set_chan_level(5, PWM_CHAN_B, 1500); // S4 - Ouvert 2700 - Fermé : 1500
|
||||
|
||||
|
||||
// Init pin for the servos
|
||||
gpio_init(SERVO1_PIN);
|
||||
gpio_init(SERVO2_PIN);
|
||||
gpio_init(22);
|
||||
gpio_init(26);
|
||||
gpio_init(27);
|
||||
gpio_set_function(SERVO1_PIN, GPIO_FUNC_PWM);
|
||||
gpio_set_function(SERVO2_PIN, GPIO_FUNC_PWM);
|
||||
gpio_set_function(22, GPIO_FUNC_PWM);
|
||||
gpio_set_function(26, GPIO_FUNC_PWM);
|
||||
gpio_set_function(27, GPIO_FUNC_PWM);
|
||||
|
||||
// Edit 17/01/2024
|
||||
// Réglage servomoteurs en 25000 * 100
|
||||
// Pince
|
||||
// Pot : 1700
|
||||
// Plante : 1970
|
||||
// Ouvert : 1000
|
||||
// Ascenseur
|
||||
// Haut : 2550
|
||||
// Bas : 1550
|
||||
// Lâche plante : 2050
|
||||
// Lâche pot jardinière : 1950
|
||||
}
|
||||
|
||||
void Servo_pince_tient(){
|
||||
pwm_set_chan_level(2, PWM_CHAN_A, 2800);
|
||||
pwm_set_chan_level(5, PWM_CHAN_B, 1500);
|
||||
pwm_set_chan_level(2, PWM_CHAN_B, 2650);
|
||||
}
|
||||
|
||||
void Servo_pince_lache(){
|
||||
pwm_set_chan_level(2, PWM_CHAN_A, 1700);
|
||||
pwm_set_chan_level(5, PWM_CHAN_B, 2700);
|
||||
pwm_set_chan_level(2, PWM_CHAN_B, 1500);
|
||||
}
|
||||
|
||||
void Servo_came_pousse(){
|
||||
pwm_set_chan_level(3, PWM_CHAN_A, 2300); // S1 - 2300 Pousse, 1500 Neutre
|
||||
}
|
||||
|
||||
void Servo_came_neutre(){
|
||||
pwm_set_chan_level(3, PWM_CHAN_A, 1500); // S1 - 2300 Pousse, 1500 Neutre
|
||||
}
|
||||
|
||||
void Servo_deplie_banderole(){
|
||||
pwm_set_chan_level(5, PWM_CHAN_A, 900); // S0 - Dépose 900 - neutre 1750
|
||||
}
|
||||
|
||||
void Servo_plie_banderole(){
|
||||
pwm_set_chan_level(5, PWM_CHAN_A, 1750); // S0 - Dépose 900 - neutre 1750
|
||||
}
|
9
Servomoteur.h
Normal file
9
Servomoteur.h
Normal file
@ -0,0 +1,9 @@
|
||||
void Servomoteur_init();
|
||||
void Servo_pince_tient();
|
||||
void Servo_pince_lache();
|
||||
|
||||
void Servo_came_pousse();
|
||||
void Servo_came_neutre();
|
||||
|
||||
void Servo_deplie_banderole();
|
||||
void Servo_plie_banderole();
|
17
main.c
17
main.c
@ -1,6 +1,7 @@
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/adc.h"
|
||||
#include "communication.h"
|
||||
#include "Servomoteur.h"
|
||||
#include <stdio.h>
|
||||
#include "moteur.h"
|
||||
|
||||
@ -22,6 +23,7 @@ void main(void)
|
||||
// Init "all"
|
||||
stdio_init_all();
|
||||
Init_motion_motor();
|
||||
Servomoteur_init();
|
||||
communication_init();
|
||||
|
||||
gpio_init(PIN_LED_VERTE);
|
||||
@ -49,16 +51,17 @@ void main(void)
|
||||
vitesse_angle = reception[2] - 128;
|
||||
|
||||
switch(reception[3]){
|
||||
case 0: Servo_pince_ouverte(); break;
|
||||
case 1: Servo_pince_plante(); break;
|
||||
case 2: Servo_pince_pot(); break;
|
||||
case 0: Servo_pince_tient(); break;
|
||||
case 1: Servo_pince_lache(); break;
|
||||
}
|
||||
|
||||
switch(reception[4]){
|
||||
case 0: Servo_ascenseur_bas(); break;
|
||||
case 1: Servo_ascenseur_haut(); break;
|
||||
case 2: Servo_ascenseur_lache_pot_jardiniere(); break;
|
||||
case 3: Servo_ascenseur_lache_plante(); break;
|
||||
case 0: Servo_plie_banderole(); break;
|
||||
case 1: Servo_deplie_banderole(); break;
|
||||
}
|
||||
switch(reception[5]){
|
||||
case 0: Servo_came_pousse(); break;
|
||||
case 1: Servo_came_neutre(); break;
|
||||
}
|
||||
|
||||
}
|
||||
|
72
moteur.c
72
moteur.c
@ -14,10 +14,6 @@
|
||||
#define MOTEUR4_PIN_SENS2 9
|
||||
#define MOTEUR4_PIN_ACTIVATION 3
|
||||
|
||||
// Define pins servo
|
||||
#define SERVO1_PIN 20
|
||||
#define SERVO2_PIN 21
|
||||
|
||||
// Init all motion motors pins
|
||||
void Init_motion_motor(void)
|
||||
{
|
||||
@ -75,65 +71,9 @@ void Init_motion_motor(void)
|
||||
pwm_set_chan_level(1, PWM_CHAN_A, 0);
|
||||
pwm_set_chan_level(1, PWM_CHAN_B, 0);
|
||||
|
||||
// Servo Init
|
||||
|
||||
|
||||
// Init pin for the servos
|
||||
gpio_init(SERVO1_PIN);
|
||||
gpio_init(SERVO2_PIN);
|
||||
gpio_set_function(SERVO1_PIN, GPIO_FUNC_PWM);
|
||||
gpio_set_function(SERVO2_PIN, GPIO_FUNC_PWM);
|
||||
|
||||
// Set wrap of pwm slice
|
||||
pwm_set_wrap(2, 25000);
|
||||
|
||||
// Set clock div for this pwm slice
|
||||
pwm_set_clkdiv(2, 100);
|
||||
|
||||
// Enable pwm slice
|
||||
pwm_set_enabled(2, true);
|
||||
|
||||
// Set channel level
|
||||
pwm_set_chan_level(2, PWM_CHAN_A, 1950); // Ascenseur
|
||||
pwm_set_chan_level(2, PWM_CHAN_B, 1000); // Pince
|
||||
// Edit 17/01/2024
|
||||
// Réglage servomoteurs en 25000 * 100
|
||||
// Pince
|
||||
// Pot : 1700
|
||||
// Plante : 1970
|
||||
// Ouvert : 1000
|
||||
// Ascenseur
|
||||
// Haut : 2550
|
||||
// Bas : 1550
|
||||
// Lâche plante : 2050
|
||||
// Lâche pot jardinière : 1950
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Servo_ascenseur_haut(){
|
||||
pwm_set_chan_level(2, PWM_CHAN_A, 2550);
|
||||
}
|
||||
void Servo_ascenseur_bas(){
|
||||
pwm_set_chan_level(2, PWM_CHAN_A, 1550);
|
||||
}
|
||||
void Servo_ascenseur_lache_plante(){
|
||||
pwm_set_chan_level(2, PWM_CHAN_A, 2050);
|
||||
}
|
||||
void Servo_ascenseur_lache_pot_jardiniere(){
|
||||
pwm_set_chan_level(2, PWM_CHAN_A, 1950);
|
||||
}
|
||||
|
||||
void Servo_pince_ouverte(){
|
||||
pwm_set_chan_level(2, PWM_CHAN_B, 1000);
|
||||
}
|
||||
void Servo_pince_pot(){
|
||||
pwm_set_chan_level(2, PWM_CHAN_B, 1700);
|
||||
}
|
||||
void Servo_pince_plante(){
|
||||
pwm_set_chan_level(2, PWM_CHAN_B, 1950);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -231,16 +171,16 @@ void Motor3_speed(int speed)
|
||||
void Motor4_forward(int speed)
|
||||
{
|
||||
pwm_set_chan_level(1, PWM_CHAN_B, speed);
|
||||
gpio_put(MOTEUR4_PIN_SENS1, 0);
|
||||
gpio_put(MOTEUR4_PIN_SENS2, 1);
|
||||
gpio_put(MOTEUR4_PIN_SENS1, 1);
|
||||
gpio_put(MOTEUR4_PIN_SENS2, 0);
|
||||
}
|
||||
|
||||
// Set motor 4 speed backward
|
||||
void Motor4_backward(int speed)
|
||||
{
|
||||
pwm_set_chan_level(1, PWM_CHAN_B, speed);
|
||||
gpio_put(MOTEUR4_PIN_SENS1, 1);
|
||||
gpio_put(MOTEUR4_PIN_SENS2, 0);
|
||||
gpio_put(MOTEUR4_PIN_SENS1, 0);
|
||||
gpio_put(MOTEUR4_PIN_SENS2, 1);
|
||||
}
|
||||
|
||||
// Set motor 4 speed and direction (negative value : backward / positive value : forward)
|
||||
|
7
moteur.h
7
moteur.h
@ -15,10 +15,3 @@ void Motor2_forward(int speed);
|
||||
void Motor3_backward(int speed);
|
||||
void Motor4_speed(int speed);
|
||||
|
||||
void Servo_ascenseur_haut();
|
||||
void Servo_ascenseur_bas();
|
||||
void Servo_ascenseur_lache_plante();
|
||||
void Servo_ascenseur_lache_pot_jardiniere();
|
||||
void Servo_pince_ouverte();
|
||||
void Servo_pince_pot();
|
||||
void Servo_pince_plante();
|
Loading…
Reference in New Issue
Block a user