peuplement des fonctions pid & dépalcement du setup
This commit is contained in:
parent
195bd314bd
commit
6ae2fc21d3
|
@ -12,4 +12,6 @@
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = nodemcu-32s
|
board = nodemcu-32s
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps = madhephaestus/ESP32Servo@^0.9.0
|
lib_deps =
|
||||||
|
madhephaestus/ESP32Servo@^0.9.0
|
||||||
|
br3ttb/PID@^1.2.1
|
||||||
|
|
73
src/main.cpp
73
src/main.cpp
|
@ -4,6 +4,7 @@
|
||||||
#include "SD.h"
|
#include "SD.h"
|
||||||
#include "SPI.h"
|
#include "SPI.h"
|
||||||
#include "RTClib.h"
|
#include "RTClib.h"
|
||||||
|
#include <PID_v1.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
// #include "pcnt.h" // https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/include/driver/driver/pcnt.h
|
// #include "pcnt.h" // https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/include/driver/driver/pcnt.h
|
||||||
#include "driver/pcnt.h"
|
#include "driver/pcnt.h"
|
||||||
|
@ -18,6 +19,15 @@
|
||||||
#define PCNT_INPUT_SIG_IO 4 // Pulse Input GPIO
|
#define PCNT_INPUT_SIG_IO 4 // Pulse Input GPIO
|
||||||
#define PCNT_INPUT_CTRL_IO 5 // Control GPIO HIGH=count up, LOW=count down
|
#define PCNT_INPUT_CTRL_IO 5 // Control GPIO HIGH=count up, LOW=count down
|
||||||
|
|
||||||
|
//PID
|
||||||
|
#define PIN_INPUT 0 //entrée physique perso?
|
||||||
|
#define PIN_OUTPUT 3// sortie physique perso?
|
||||||
|
//PID Define Variables we'll be connecting to
|
||||||
|
double Setpoint, Input, Output;
|
||||||
|
//PID Specify the links and initial tuning parameters
|
||||||
|
double Kp=2, Ki=5, Kd=1;
|
||||||
|
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
|
||||||
|
|
||||||
int numero_capteur = 0; // numéro de série du capteur
|
int numero_capteur = 0; // numéro de série du capteur
|
||||||
int bouton_wifi = 7; // pin du bouton wifi
|
int bouton_wifi = 7; // pin du bouton wifi
|
||||||
bool sem_wifi; //semaphore du minuteur du bouton wifi
|
bool sem_wifi; //semaphore du minuteur du bouton wifi
|
||||||
|
@ -92,6 +102,18 @@ void start_compteur() {
|
||||||
//pcnt_counter_resume(PCNT_TEST_UNIT);
|
//pcnt_counter_resume(PCNT_TEST_UNIT);
|
||||||
pcnt_get_counter_value(PCNT_TEST_UNIT, &pulsations);
|
pcnt_get_counter_value(PCNT_TEST_UNIT, &pulsations);
|
||||||
}
|
}
|
||||||
|
void pid () {
|
||||||
|
Input = analogRead(PIN_INPUT);
|
||||||
|
myPID.Compute();
|
||||||
|
analogWrite(PIN_OUTPUT, Output);
|
||||||
|
}
|
||||||
|
void pidsetup() {
|
||||||
|
//initialize the variables we're linked to
|
||||||
|
Input = analogRead(PIN_INPUT);
|
||||||
|
Setpoint = 100;
|
||||||
|
//turn the PID on
|
||||||
|
myPID.SetMode(AUTOMATIC);
|
||||||
|
}
|
||||||
|
|
||||||
void sd_init(){
|
void sd_init(){
|
||||||
if (!SD.begin(broche_CS)) {
|
if (!SD.begin(broche_CS)) {
|
||||||
|
@ -131,42 +153,12 @@ void rtc_init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
|
||||||
// serial
|
|
||||||
Serial.begin(115200);
|
|
||||||
// wifi
|
|
||||||
pinMode(bouton_wifi, INPUT);
|
|
||||||
sem_wifi = false; // initialaisation du sémaphore
|
|
||||||
// moteur
|
|
||||||
moteur.attach(pinMoteur);
|
|
||||||
start_moteur();
|
|
||||||
// compteur de pulsations
|
|
||||||
sem_compteur = false; // initialisation du sémaphore
|
|
||||||
pinMode(pulsePin,INPUT_PULLUP);
|
|
||||||
start_compteur();
|
|
||||||
// lecteur de carte SD
|
|
||||||
sd_init ();
|
|
||||||
// RTC
|
|
||||||
rtc_init();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//void stop_compteur {
|
//void stop_compteur {
|
||||||
|
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//void start_wifiAP {
|
//void start_wifiAP {
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void pid() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void stop_moteur() {
|
void stop_moteur() {
|
||||||
moteur.writeMicroseconds(1500);
|
moteur.writeMicroseconds(1500);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
@ -217,6 +209,27 @@ void vigie () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// serial just for feedback
|
||||||
|
Serial.begin(115200);
|
||||||
|
// wifi
|
||||||
|
pinMode(bouton_wifi, INPUT);
|
||||||
|
sem_wifi = false; // initialisation du sémaphore
|
||||||
|
// moteur
|
||||||
|
moteur.attach(pinMoteur);
|
||||||
|
start_moteur();
|
||||||
|
// compteur de pulsations
|
||||||
|
sem_compteur = false; // initialisation du sémaphore
|
||||||
|
pinMode(pulsePin,INPUT_PULLUP);
|
||||||
|
start_compteur();
|
||||||
|
// lecteur de carte SD
|
||||||
|
sd_init ();
|
||||||
|
// RTC
|
||||||
|
rtc_init();
|
||||||
|
//PID
|
||||||
|
pidsetup();
|
||||||
|
}
|
||||||
|
|
||||||
void loop (){
|
void loop (){
|
||||||
// vigie ();
|
// vigie ();
|
||||||
//pid ();
|
//pid ();
|
||||||
|
|
Loading…
Reference in a new issue