4 niveaux
This commit is contained in:
File diff suppressed because it is too large
Load Diff
187
43.md
Normal file
187
43.md
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
#include "main.hpp"
|
||||||
|
#include "autom.cpp"
|
||||||
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
int marche_precedent = 0;
|
||||||
|
int marche_frontmontant = 0;
|
||||||
|
|
||||||
|
int arret_precedent = 1;
|
||||||
|
int arret_frontdescedant = 0;
|
||||||
|
|
||||||
|
int bouton_precedent[8];
|
||||||
|
int bouton_frontmontant[8];
|
||||||
|
int bouton_frontdescendant[8];
|
||||||
|
|
||||||
|
int cycle = 0;
|
||||||
|
long unsigned tempo = 0;
|
||||||
|
|
||||||
|
int compteur[4];
|
||||||
|
|
||||||
|
int sens = 1;
|
||||||
|
|
||||||
|
int ci = 0;
|
||||||
|
int mode_auto = 0;
|
||||||
|
int mode_manu = 0;
|
||||||
|
int etape = 0;
|
||||||
|
int etape_2 = 0;
|
||||||
|
|
||||||
|
int c7_frontdescendant = 0;
|
||||||
|
int c7_precedent = 0;
|
||||||
|
|
||||||
|
int moteur_plusutilise();
|
||||||
|
int moteur_moinsutilise();
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
mqtt_open(&client);
|
||||||
|
|
||||||
|
std::atomic<bool> running{true};
|
||||||
|
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
mqtt_close();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void process() {
|
||||||
|
|
||||||
|
// Détection des fronts
|
||||||
|
// front montant (état courant supérieur à l'état précédent)
|
||||||
|
// front descendant (état courant inférieur à l'état précédent)
|
||||||
|
// ****************************************************************
|
||||||
|
marche_frontmontant = marche > marche_precedent;
|
||||||
|
arret_frontdescedant = arret < arret_precedent;
|
||||||
|
|
||||||
|
for(int i = 0; i < 8 ; i++) {
|
||||||
|
bouton_frontmontant[i] = bouton[i] > bouton_precedent[i];
|
||||||
|
bouton_frontdescendant[i] = bouton[i] < bouton_precedent[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ****************************************************************
|
||||||
|
VOTRE PROGRAMME COMMENCE ICI
|
||||||
|
**************************************************************** */
|
||||||
|
|
||||||
|
if (etape == 0 && capteur[1] == 0) {
|
||||||
|
etape = 10;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Etape 10 : 1 moteur allumé
|
||||||
|
if (etape == 10 && capteur[1] == 0 && millis() >= tempo + 2000)
|
||||||
|
{
|
||||||
|
etape = 12;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (etape == 11 && capteur[2] == 1 && millis() >= tempo + 2000)
|
||||||
|
{
|
||||||
|
etape = 0;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Etape 12 : 2 moteurs allumés
|
||||||
|
if (etape == 12 && capteur[1] == 0 && millis() >= tempo + 2000)
|
||||||
|
{
|
||||||
|
etape = 14;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
if (etape == 12 && capteur[2] == 1)
|
||||||
|
{
|
||||||
|
etape = 11;
|
||||||
|
}
|
||||||
|
if (etape == 13 && capteur[2] == 1 && millis() >= tempo + 2000)
|
||||||
|
{
|
||||||
|
etape = 11;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Etape 14 : 3 moteurs allumés
|
||||||
|
if (etape == 14 && capteur[1] == 0 && millis() >= tempo + 2000)
|
||||||
|
{
|
||||||
|
etape = 16;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
if (etape == 14 && capteur[2] == 1) {
|
||||||
|
etape = 13;
|
||||||
|
}
|
||||||
|
if (etape == 15 && capteur[2] == 1 && millis() >= tempo + 2000)
|
||||||
|
{
|
||||||
|
etape = 13;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Etape 13 : 4 moteurs allumés
|
||||||
|
if (etape == 16 && capteur[2] == 1)
|
||||||
|
{
|
||||||
|
etape = 15;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
int moteur_precedent[4];
|
||||||
|
for (int i = 0 ; i < 4 ; i++) {
|
||||||
|
moteur_precedent[i] = moteur[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
moteur[0] = (etape == 10 || etape == 11 || etape == 12 || etape == 13 || etape == 14 || etape == 15 || etape == 16);
|
||||||
|
moteur[1] = (etape == 12 || etape == 13 || etape == 14 || etape == 15 || etape == 16);
|
||||||
|
moteur[2] = (etape == 14 || etape == 15 || etape == 16);
|
||||||
|
moteur[3] = (etape == 16);
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (moteur[i] > moteur_precedent[i])
|
||||||
|
{
|
||||||
|
compteur[i] = compteur[i] + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << compteur[0] << " " << compteur[1] << " "
|
||||||
|
<< compteur[2] << " " << compteur[3] << std::endl;
|
||||||
|
|
||||||
|
sortie[10] = etape;
|
||||||
|
|
||||||
|
// Prêt pour un nouveau cycle
|
||||||
|
// L'état courant devient l'état précédent
|
||||||
|
marche_precedent = marche;
|
||||||
|
arret_precedent = arret;
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
bouton_precedent[i] = bouton[i];
|
||||||
|
}
|
||||||
|
c7_precedent = capteur[7];
|
||||||
|
}
|
||||||
|
|
||||||
|
int moteur_plusutilise() {
|
||||||
|
int index = -1;
|
||||||
|
int max = 0;
|
||||||
|
|
||||||
|
for (int i = 0 ; i < 4 ; i++) {
|
||||||
|
if (compteur[i] > max) {
|
||||||
|
max = compteur[i];
|
||||||
|
index = i; // Lequel est le maximum
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
int moteur_moinsutilise() {
|
||||||
|
int index = -1;
|
||||||
|
int min = INT32_MAX;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (compteur[i] < min)
|
||||||
|
{
|
||||||
|
min = compteur[i];
|
||||||
|
index = i; // Lequel est le maximum
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
24
autom.cpp
24
autom.cpp
@@ -57,7 +57,7 @@ int i0, i1, i2, i3, i4, i5, i6, i7;
|
|||||||
int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
|
int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
|
||||||
int m0, m1, m2, m3;
|
int m0, m1, m2, m3;
|
||||||
int v0;
|
int v0;
|
||||||
int p0;
|
int p0, p1, p2, p3;
|
||||||
|
|
||||||
int a0, a1, a2, a3, a4, a5, a6, a7;
|
int a0, a1, a2, a3, a4, a5, a6, a7;
|
||||||
int c0, c1, c2, c3, c4, c5, c6, c7;
|
int c0, c1, c2, c3, c4, c5, c6, c7;
|
||||||
@@ -192,8 +192,28 @@ public:
|
|||||||
if (j.contains("v0") && j["v0"].is_number())
|
if (j.contains("v0") && j["v0"].is_number())
|
||||||
v0 = j["v0"].get<int>();
|
v0 = j["v0"].get<int>();
|
||||||
|
|
||||||
if (j.contains("p0") && j["p0"].is_number())
|
if (j.contains("p0") && j["p0"].is_number()) {
|
||||||
p0 = j["p0"].get<int>();
|
p0 = j["p0"].get<int>();
|
||||||
|
niveau[0] = j["p0"].get<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j.contains("p1") && j["p1"].is_number())
|
||||||
|
{
|
||||||
|
p1 = j["p1"].get<int>();
|
||||||
|
niveau[1] = j["p1"].get<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j.contains("p2") && j["p2"].is_number())
|
||||||
|
{
|
||||||
|
p2 = j["p2"].get<int>();
|
||||||
|
niveau[2] = j["p2"].get<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j.contains("p3") && j["p3"].is_number())
|
||||||
|
{
|
||||||
|
p3 = j["p3"].get<int>();
|
||||||
|
niveau[3] = j["p3"].get<int>();
|
||||||
|
}
|
||||||
|
|
||||||
process();
|
process();
|
||||||
mqtt_send(&client);
|
mqtt_send(&client);
|
||||||
|
|||||||
77
main.cpp
77
main.cpp
@@ -15,7 +15,9 @@ int bouton_frontdescendant[8];
|
|||||||
|
|
||||||
int cycle = 0;
|
int cycle = 0;
|
||||||
long unsigned tempo = 0;
|
long unsigned tempo = 0;
|
||||||
int compteur = 0;
|
|
||||||
|
int compteur[4];
|
||||||
|
|
||||||
int sens = 1;
|
int sens = 1;
|
||||||
|
|
||||||
int ci = 0;
|
int ci = 0;
|
||||||
@@ -27,6 +29,7 @@ int etape_2 = 0;
|
|||||||
int c7_frontdescendant = 0;
|
int c7_frontdescendant = 0;
|
||||||
int c7_precedent = 0;
|
int c7_precedent = 0;
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
mqtt_open(&client);
|
mqtt_open(&client);
|
||||||
@@ -42,7 +45,8 @@ int main()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void process() {
|
void process()
|
||||||
|
{
|
||||||
|
|
||||||
// Détection des fronts
|
// Détection des fronts
|
||||||
// front montant (état courant supérieur à l'état précédent)
|
// front montant (état courant supérieur à l'état précédent)
|
||||||
@@ -50,25 +54,80 @@ void process() {
|
|||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
marche_frontmontant = marche > marche_precedent;
|
marche_frontmontant = marche > marche_precedent;
|
||||||
arret_frontdescedant = arret < arret_precedent;
|
arret_frontdescedant = arret < arret_precedent;
|
||||||
for(int i = 0; i < 8 ; i++) {
|
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
bouton_frontmontant[i] = bouton[i] > bouton_precedent[i];
|
bouton_frontmontant[i] = bouton[i] > bouton_precedent[i];
|
||||||
bouton_frontdescendant[i] = bouton[i] < bouton_precedent[i];
|
bouton_frontdescendant[i] = bouton[i] < bouton_precedent[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ****************************************************************
|
/* ****************************************************************
|
||||||
|
VOTRE PROGRAMME COMMENCE ICI
|
||||||
**************************************************************** */
|
**************************************************************** */
|
||||||
|
|
||||||
m0 = i0;
|
if (etape == 0 && capteur[1] == 0) {
|
||||||
m1 = i1;
|
etape = 10;
|
||||||
m2 = i2;
|
tempo = millis();
|
||||||
m3 = i3;
|
}
|
||||||
|
|
||||||
|
// Etape 10 : 1 moteur allumé
|
||||||
|
if (etape == 10 && capteur[1] == 0 && millis() >= tempo + 2000) {
|
||||||
|
etape = 12;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (etape == 10 && capteur[2] == 1 && millis() >= tempo + 2000) {
|
||||||
|
etape = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Etape 12 : 2 moteur allumés
|
||||||
|
if (etape == 12 && capteur[1] == 0 && millis() >= tempo + 2000) {
|
||||||
|
etape = 14;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (etape == 12 && capteur[2] == 1 && millis() >= tempo + 2000) {
|
||||||
|
etape = 10;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Etape 14 : 3 moteur allumés
|
||||||
|
if (etape == 14 && capteur[1] == 0 && millis() >= tempo + 2000) {
|
||||||
|
etape = 16;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (etape == 14 && capteur[2] == 1 && millis() >= tempo + 2000) {
|
||||||
|
etape = 12;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Etape 16 : 4 moteur allumés
|
||||||
|
if (etape == 16 && capteur[2] == 1) {
|
||||||
|
etape = 14;
|
||||||
|
tempo = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ****************************************************************
|
||||||
|
LES ACTIONS
|
||||||
|
**************************************************************** */
|
||||||
|
moteur[0] = (etape == 10 || etape == 12 || etape == 14 || etape == 16);
|
||||||
|
moteur[1] = (etape == 12 || etape == 14 || etape == 16);
|
||||||
|
moteur[2] = (etape == 14 || etape == 16);
|
||||||
|
moteur[3] = (etape == 16);
|
||||||
|
|
||||||
|
/* ****************************************************************
|
||||||
|
VOTRE PROGRAMME S'ARRETE ICI
|
||||||
|
**************************************************************** */
|
||||||
|
|
||||||
|
sortie[10] = etape;
|
||||||
|
|
||||||
// Prêt pour un nouveau cycle
|
// Prêt pour un nouveau cycle
|
||||||
// L'état courant devient l'état précédent
|
// L'état courant devient l'état précédent
|
||||||
marche_precedent = marche;
|
marche_precedent = marche;
|
||||||
arret_precedent = arret;
|
arret_precedent = arret;
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
bouton_precedent[i] = bouton[i];
|
bouton_precedent[i] = bouton[i];
|
||||||
}
|
}
|
||||||
c7_precedent = capteur[7];
|
c7_precedent = capteur[7];
|
||||||
|
|||||||
Reference in New Issue
Block a user