From d8f0bb07be101e5634db3fd1b9f8028f015e61eb Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 18 Jan 2024 19:16:23 +0100 Subject: [PATCH 1/7] =?UTF-8?q?add=20id=C3=A9e=20d'algo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Program.h | 17 +++++++++++++++- src/Program.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/include/Program.h b/include/Program.h index b4f30bb..949efc8 100644 --- a/include/Program.h +++ b/include/Program.h @@ -1,9 +1,11 @@ #ifndef PROGRAM_H #define PROGRAM_H -#include "Arduino.h" #include "DolibarrClient.h" +#include "GRBL.h" +#include #include +#include class Program { public: @@ -16,8 +18,21 @@ public: * Program WarehouseGUI loop */ void loop(); + private: + DolibarrClient *client; + + /** + * @brief stepper motor controller + */ + GRBL* grbl; + + /** + * @brief stack des UUID lue + * + */ + std::vector* NfcIDs; }; #endif diff --git a/src/Program.cpp b/src/Program.cpp index 8454899..45e9961 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -21,9 +21,59 @@ Program::Program() { struct DolibarrConfig dolibarr = {DOLIBARR_URL, DOLIBARR_API_TOKEN}; initialize_wifi(wifi_c); this->client = new DolibarrClient(dolibarr); + + // initialisation GRBL + this->grbl = new GRBL(STEPMOTOR_I2C_ADDR); + Wire.begin(21, 22); + grbl->init(STEPER_SPEED, STEPER_PAS, STEPER_ACC); } void Program::loop() { + if(this->grbl->) + this->grbl->mouveForward(5); //TODO: réglé pour qu'il avance de la bonne distance + String nfcIn = "0"; // TODO: si le lecteur envoie qqc + //TODO: refrech servo + if(nfcIn !="0"){ + //envoyer sur dolibard + this->NfcIDs->push_back(nfcIn); + } + if(this->NfcIDs->size() > 0){ + + } + + //alog V1 + //je lis la valeur NFC + //si qqc + //je demande a dolibard ou j'envoie + //j'envoie au servo la commande + //j'avance le moteur jusqu'a X (a definir) + //si rien j'avance le moteur (5mm) + + + //idée algo v1.5 (ajou petite gestion d'erreur) + //alog V1 + //je lis la valeur NFC + //si qqc + //je demande a dolibard ou j'envoie + //j'envoie au servo la commande + //j'avance le moteur jusqu'a X (a definir) + //si rien j'avance le moteur (5mm) + //si le lecteur de sortie voi pas de colis + //on affiche une erreur de colis non lue + //si un seul colis + //on dit que le colis est bien trié (avec porte de sortie) + //si il y a 2 colis (ou plus) + //on affiche une erreur de bourrage + + + + //idée algo v2 + //utiliser une pile + //utiliser le 2nd lecteur pour vidé la pile + //gestion d'erreur complete avec celle du dessus plus celle de la pile + + + } -- 2.47.1 From b96088c4eb631b49b2801109e148900b5423e472 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 18 Jan 2024 19:32:02 +0100 Subject: [PATCH 2/7] cleanup --- include/Program.h | 8 +------- src/Program.cpp | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/include/Program.h b/include/Program.h index 949efc8..033fd3a 100644 --- a/include/Program.h +++ b/include/Program.h @@ -5,7 +5,7 @@ #include "GRBL.h" #include #include -#include +// #include class Program { public: @@ -27,12 +27,6 @@ private: * @brief stepper motor controller */ GRBL* grbl; - - /** - * @brief stack des UUID lue - * - */ - std::vector* NfcIDs; }; #endif diff --git a/src/Program.cpp b/src/Program.cpp index 45e9961..918b53a 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -29,17 +29,17 @@ Program::Program() { } void Program::loop() { - if(this->grbl->) - this->grbl->mouveForward(5); //TODO: réglé pour qu'il avance de la bonne distance - String nfcIn = "0"; // TODO: si le lecteur envoie qqc - //TODO: refrech servo - if(nfcIn !="0"){ - //envoyer sur dolibard - this->NfcIDs->push_back(nfcIn); - } - if(this->NfcIDs->size() > 0){ + // if(this->grbl->) + // this->grbl->mouveForward(5); //TODO: réglé pour qu'il avance de la bonne distance + // String nfcIn = "0"; // TODO: si le lecteur envoie qqc + // //TODO: refrech servo + // if(nfcIn !="0"){ + // //envoyer sur dolibard + // this->NfcIDs->push_back(nfcIn); + // } + // if(this->NfcIDs->size() > 0){ + // } - } //alog V1 //je lis la valeur NFC -- 2.47.1 From 8bdd4a9be2cf9cf9c0da14b65b052d104c36eb00 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 18 Jan 2024 21:00:36 +0100 Subject: [PATCH 3/7] add convoyer len and nfc i2C addr --- config.ini | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config.ini b/config.ini index 21dd53e..91af6d4 100644 --- a/config.ini +++ b/config.ini @@ -15,6 +15,8 @@ build_flags = ; DO NOT TOUCH --- END -D WAITING_WIFI_DELAY=1000 + -D CONVOYER_LEN=150 ;mm + ;;;;;;;;;;;;;;;;;;;;;; ;;; stepper config ;;; ;;;;;;;;;;;;;;;;;;;;;; @@ -23,3 +25,6 @@ build_flags = ;-D STEPER_PAS=755.906 ; = 65mm -D STEPER_PAS=58 ; = 5mm -D STEPER_SPEED=1000 ; 12000 + + + -D NFC_ADDR=0x28 -- 2.47.1 From 76ebc00763772ad04e22eb66c68ad7715573fd8b Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 18 Jan 2024 21:01:02 +0100 Subject: [PATCH 4/7] add is idle condition on RGBL lib --- lib/GRBL/include/GRBL.h | 2 ++ lib/GRBL/src/GRBL.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/GRBL/include/GRBL.h b/lib/GRBL/include/GRBL.h index 769cc14..acd3ed4 100644 --- a/lib/GRBL/include/GRBL.h +++ b/lib/GRBL/include/GRBL.h @@ -8,6 +8,7 @@ class iGRBL{ public: virtual void init(int speed, double pas, int accel, String mode = "distance") = 0; virtual void mouveForward(int mm) = 0; + virtual bool isIddle() = 0; }; class GRBL : public iGRBL{ @@ -15,6 +16,7 @@ public: GRBL(int grblAddr); void init(int speed, double pas, int accel, String mode = "distance") override; void mouveForward(int mm = 5) override; + bool isIddle() override; private: Module_GRBL* grbl; }; diff --git a/lib/GRBL/src/GRBL.cpp b/lib/GRBL/src/GRBL.cpp index f71f61d..a674180 100644 --- a/lib/GRBL/src/GRBL.cpp +++ b/lib/GRBL/src/GRBL.cpp @@ -32,3 +32,13 @@ void GRBL::mouveForward(int mm){ sprintf(s, "G1 X%d", mm); this->grbl->sendGcode(s); } + +bool GRBL::isIddle(){ + bool sortie = false; + + if(this->grbl->readStatus().indexOf("IDLE") != -1){ + sortie = true; + } + + return sortie; +} -- 2.47.1 From 463e71fe1077b2ce7ffd05ecaae0b27b235223da Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 18 Jan 2024 21:01:53 +0100 Subject: [PATCH 5/7] rename nfc reader --- lib/NFC/src/NfcReader.cpp | 7 +++---- lib/NFC/src/{NfcReader.hpp => NfcReader.h} | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) rename lib/NFC/src/{NfcReader.hpp => NfcReader.h} (82%) diff --git a/lib/NFC/src/NfcReader.cpp b/lib/NFC/src/NfcReader.cpp index 23ea403..e019406 100644 --- a/lib/NFC/src/NfcReader.cpp +++ b/lib/NFC/src/NfcReader.cpp @@ -5,7 +5,7 @@ ** NfcReader */ -#include "NfcReader.hpp" +#include "NfcReader.h" NfcReader::NfcReader(int i2c_adress) { @@ -20,7 +20,6 @@ String NfcReader::ReadNfc() this->uid.clear(); if (!this->mfrc522->PICC_IsNewCardPresent() || !this->mfrc522->PICC_ReadCardSerial()) { - delay(200); return "0"; } for (unsigned int i = 0; i < this->mfrc522->uid.size; i++) { @@ -28,8 +27,8 @@ String NfcReader::ReadNfc() this->uid += '0'; this->uid += String(this->mfrc522->uid.uidByte[i], HEX); } else { - this->uid += String(this->mfrc522->uid.uidByte[i], HEX); + this->uid += String(this->mfrc522->uid.uidByte[i], HEX); } } return (this->uid); -} \ No newline at end of file +} diff --git a/lib/NFC/src/NfcReader.hpp b/lib/NFC/src/NfcReader.h similarity index 82% rename from lib/NFC/src/NfcReader.hpp rename to lib/NFC/src/NfcReader.h index aab376f..6fdd89b 100644 --- a/lib/NFC/src/NfcReader.hpp +++ b/lib/NFC/src/NfcReader.h @@ -5,8 +5,8 @@ ** NfcReader */ -#ifndef NFCREADER_HPP_ -#define NFCREADER_HPP_ +#ifndef NFCREADER_H +#define NFCREADER_H #include #include "MFRC522_I2C.h" @@ -25,4 +25,4 @@ class NfcReader { String uid; }; -#endif /* !NFCREADER_HPP_ */ +#endif /* !NFCREADER_H */ -- 2.47.1 From 04474bfb948e1603badcf951347c5edff291f816 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 18 Jan 2024 21:02:11 +0100 Subject: [PATCH 6/7] add main algo V1 with mock --- include/Program.h | 7 +++++++ src/Program.cpp | 34 +++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/Program.h b/include/Program.h index 033fd3a..05580e5 100644 --- a/include/Program.h +++ b/include/Program.h @@ -3,6 +3,7 @@ #include "DolibarrClient.h" #include "GRBL.h" +#include "NfcReader.h" #include #include // #include @@ -27,6 +28,12 @@ private: * @brief stepper motor controller */ GRBL* grbl; + + /** + * @brief nfc reader + * + */ + NfcReader* NFC; }; #endif diff --git a/src/Program.cpp b/src/Program.cpp index 918b53a..9feaee6 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -26,6 +26,8 @@ Program::Program() { this->grbl = new GRBL(STEPMOTOR_I2C_ADDR); Wire.begin(21, 22); grbl->init(STEPER_SPEED, STEPER_PAS, STEPER_ACC); + + this->NFC = new NfcReader(NFC_ADDR); } void Program::loop() { @@ -40,18 +42,36 @@ void Program::loop() { // if(this->NfcIDs->size() > 0){ // } - - //alog V1 + //algo V1 //je lis la valeur NFC + String nfcId = this->NFC->ReadNfc(); //si qqc + if(nfcId != "0"){ + //j'arrète le stepper + //this->grbl->stop(); //FIXME: implemente + //j'affiche le tag lue + Serial.print("new colis in comming : "); + Serial.println(nfcId); //je demande a dolibard ou j'envoie + Serial.println("Demande a dolibard"); + delay(500);// TODO: remove mock //j'envoie au servo la commande + Serial.print("Servo : "); + Serial.println("Droite"); + delay(500);// TODO: remove mock //j'avance le moteur jusqu'a X (a definir) - //si rien j'avance le moteur (5mm) - + this->grbl->mouveForward(CONVOYER_LEN); + }else{ + //si rien + //je check si le stepper est en iddle + if(this->grbl->isIddle()){ + //si oui j'avance de 5 mm + this->grbl->mouveForward(5); + } + } + //j'update la position du servo //idée algo v1.5 (ajou petite gestion d'erreur) - //alog V1 //je lis la valeur NFC //si qqc //je demande a dolibard ou j'envoie @@ -65,15 +85,11 @@ void Program::loop() { //si il y a 2 colis (ou plus) //on affiche une erreur de bourrage - - //idée algo v2 //utiliser une pile //utiliser le 2nd lecteur pour vidé la pile //gestion d'erreur complete avec celle du dessus plus celle de la pile - - } -- 2.47.1 From 29c41b6ccc51b13b315b22454824c0790b5781c9 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 18 Jan 2024 21:06:14 +0100 Subject: [PATCH 7/7] add some affichage idea --- src/Program.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Program.cpp b/src/Program.cpp index 9feaee6..337dd86 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -70,6 +70,14 @@ void Program::loop() { } } //j'update la position du servo + //this->servo->refresh(); + //idée affichage: + // waitting packet + // new packet detected : ID + // check to dolibarr + // DOLIBARR ID found stockage in progress + // stoage done + // ERR DOLIBARR ID not found //idée algo v1.5 (ajou petite gestion d'erreur) //je lis la valeur NFC -- 2.47.1