From 3f77acd600b4d67b33c2bb90934a12fdf1bfd743 Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 26 Jan 2024 11:35:26 +0100 Subject: [PATCH 1/5] feat: 2nd in site test --- config.ini | 11 +++++++---- src/Program.cpp | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/config.ini b/config.ini index da29dee..133d750 100644 --- a/config.ini +++ b/config.ini @@ -22,7 +22,7 @@ build_flags = -D STEPER_ACC=200 ;-D STEPER_PAS=755.906 ; = 65mm -D STEPER_PAS=58 ; = 5mm - -D STEPER_SPEED=1000 ; 12000 + -D STEPER_SPEED=2700 ;1000 ; 2500 ;;;;;;;;;;;;;;;;;;;;;; ;;; App config ;;; ;;;;;;;;;;;;;;;;;;;;;; @@ -33,7 +33,10 @@ build_flags = ;;;;;;;;;;;;;;;;;;;;;; ;;; Servo config ;;; ;;;;;;;;;;;;;;;;;;;;;; - -D RIGHT_POS=18 - -D MIDDLE_POS=32 + -D RIGHT_POS=14 ;18 + -D MIDDLE_POS=30 ;32 -D LEFT_POS=52 - -D CONVOYER_LEN=150 ;mm + + + + -D CONVOYER_LEN=80 ;mm diff --git a/src/Program.cpp b/src/Program.cpp index 531af4e..a054b3c 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -78,6 +78,7 @@ Program::Program() { lcdScreen->add_log("Initialize M5LCD component...."); this->nfcReader = new NfcReader(NFC_ADDR); this->servo = new ServoMotorComponent(2, 1, 1); + this->servo->setDesiredPosition(Position::MIDDLE); this->grbl = new GRBL(STEPMOTOR_I2C_ADDR); Wire.begin(21, 22); grbl->init(STEPER_SPEED, STEPER_PAS, STEPER_ACC); @@ -156,4 +157,4 @@ void Program::loop() { this->grbl->mouveForward(5); } } -} \ No newline at end of file +} -- 2.47.1 From a105387c213ce7d9020286b853f7d250bba7d519 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 1 Feb 2024 11:28:03 +0100 Subject: [PATCH 2/5] add nfc reader lib --- lib/NfcReader/include/NfcReader.h | 67 +++++++++++++++++++++++++++ lib/NfcReader/include/TrameList.h | 29 ++++++++++++ lib/NfcReader/src/NfcReader.cpp | 75 +++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 lib/NfcReader/include/NfcReader.h create mode 100644 lib/NfcReader/include/TrameList.h create mode 100644 lib/NfcReader/src/NfcReader.cpp diff --git a/lib/NfcReader/include/NfcReader.h b/lib/NfcReader/include/NfcReader.h new file mode 100644 index 0000000..b341155 --- /dev/null +++ b/lib/NfcReader/include/NfcReader.h @@ -0,0 +1,67 @@ +#ifndef NFC_READER_H +#define NFC_READER_H + +#include +#include + +#include "TrameList.h" + +class NfcReader{ +public: + NfcReader(); + + /** + * @brief initialise le lecteur NFC + * + * @return true le lecteur NFC est initialisé + * @return false le lecteur NFC n'est pas initialisé (erreur) + */ + bool init(); + + /** + * @brief rafraichit les données du lecteur NFC + * + */ + void refresh(); + + /** + * @brief affiche la dernière trame lue + * + */ + void printTrame(); + + /** + * @brief retourne le nombre de tags lus + * + * @return int nombre de tags lus + */ + int getNbTags(); + +private: + + /** + * @brief convertit un nombre en hexadécimal (a 2 chiffres) + * + * @param number nombre à convertir + * @return String nombre converti + */ + String digitify(int number); + + /** + * @brief variable pair/impair pour le type de trame + * + */ + bool pair; + + /** + * @brief dernière trame lue + * + */ + std::vector* trame; + +}; + + + + +#endif diff --git a/lib/NfcReader/include/TrameList.h b/lib/NfcReader/include/TrameList.h new file mode 100644 index 0000000..9e412ae --- /dev/null +++ b/lib/NfcReader/include/TrameList.h @@ -0,0 +1,29 @@ +#ifndef TRAM_LIST_H +#define TRAM_LIST_H + +#include +#include + +const std::vector SEARCH_TRAM_0 = {0x05, 0x07, 0x01, 0x01, 0x01, 0x00, 0xEB, 0x5F}; + +const std::vector INIT_TRAM_0 = {0xFA, 0x05, 0x01, 0xC0, 0x5A, 0xDF}; +const std::vector INIT_TRAM_1 = {0xFA, 0x08, 0x01, 0x00, 0x01, 0x01, 0x01, 0xE1, 0x70}; +const std::vector INIT_TRAM_2 = {0xFA, 0x08, 0x01, 0x40, 0x01, 0x02, 0x01, 0x3E, 0x4C}; +const std::vector INIT_TRAM_3 = {0xFA, 0x08, 0x01, 0x00, 0x01, 0x03, 0x01, 0x51, 0x43}; +const std::vector INIT_TRAM_4 = {0xFA, 0x08, 0x01, 0x40, 0x01, 0x04, 0x01, 0xEE, 0x18}; +const std::vector INIT_TRAM_5 = {0xFA, 0x08, 0x01, 0x00, 0x01, 0x05, 0x01, 0x81, 0x17}; +const std::vector INIT_TRAM_6 = {0xFA, 0x08, 0x01, 0x40, 0x01, 0x06, 0x01, 0x5E, 0x2B}; +const std::vector INIT_TRAM_7 = {0xFA, 0x08, 0x01, 0x00, 0x01, 0x07, 0x01, 0x31, 0x24}; + +const std::vector REP_TRAM_0 = {0xFA, 0x05, 0x01, 0xE0, 0x58, 0xFE}; +const std::vector REP_TRAM_1 = {0xFA, 0x17, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x04, 0x00, 0x00, 0x03, 0x01, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95, 0x8A}; +const std::vector REP_TRAM_2 = {0xFA, 0x17, 0x01, 0x40, 0x01, 0x00, 0x00, 0x01, 0x00, 0x09, 0x00, 0xFF, 0x00, 0x10, 0x07, 0x13, 0x01, 0x0E, 0x08, 0x09, 0x0B, 0x00, 0x2D, 0x98}; +const std::vector REP_TRAM_3 = {0xFA, 0x17, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xE8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x43, 0x83, 0x00, 0x00, 0x00, 0x9A, 0xBF}; +const std::vector REP_TRAM_4 = {0xFA, 0x17, 0x01, 0x40, 0x01, 0x00, 0x00, 0x01, 0x04, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD7, 0x15}; +const std::vector REP_TRAM_5 = {0xFA, 0x17, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0A, 0x03, 0x0A, 0x00, 0xF6, 0xCD}; +const std::vector REP_TRAM_6 = {0xFA, 0x17, 0x01, 0x40, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xD4, 0x03}; +const std::vector REP_TRAM_7 = {0xFA, 0x17, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x52, 0xF6}; + +const std::vector READ_TRAM_0 = {0xFA, 0x24, 0x01, 0x00, 0x31, 0x02, 0x07, 0x0E, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x06, 0x00, 0x03, 0x00, 0xFF, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x5D, 0x74}; +const std::vector READ_TRAM_1 = {0xFA, 0x24, 0x01, 0x40, 0x31, 0x02, 0x07, 0x0E, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x06, 0x00, 0x03, 0x00, 0xFF, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x10, 0x45}; +#endif diff --git a/lib/NfcReader/src/NfcReader.cpp b/lib/NfcReader/src/NfcReader.cpp new file mode 100644 index 0000000..133b13e --- /dev/null +++ b/lib/NfcReader/src/NfcReader.cpp @@ -0,0 +1,75 @@ +#include "../include/NfcReader.h" + + +NfcReader::NfcReader(){ + Serial2.begin(115200,SERIAL_8N1,2,3);//TODO: mettre le port série en paramètre + this->pair = true; + this->trame = new std::vector(); +} + + +bool NfcReader::init(){ + const std::vector> INIT_TRAMES = {INIT_TRAM_0, INIT_TRAM_1, INIT_TRAM_2, INIT_TRAM_3, INIT_TRAM_4, INIT_TRAM_5, INIT_TRAM_6, INIT_TRAM_7}; + const std::vector> REP_TRAMES = {REP_TRAM_0, REP_TRAM_1, REP_TRAM_2, REP_TRAM_3, REP_TRAM_4, REP_TRAM_5, REP_TRAM_6, REP_TRAM_7}; + int repnb = 0; + for(std::vector i: INIT_TRAMES){ + for(byte j: i){ + Serial2.write(j); + } + while (Serial2.available() == 0); + while (Serial2.available() > 0){ + for(byte j: REP_TRAMES[repnb]){ + if(Serial2.read() != j){ + Serial.println("NFC reader init failed"); + return false; + } + } + } + repnb++; + } + return true; +} + +void NfcReader::refresh(){ + this->trame->clear(); + std::vector trame = READ_TRAM_0; + if (this->pair){ + trame = READ_TRAM_1; + } + this->pair = !this->pair; + + for(byte i: trame){ + Serial2.write(i); + } + while (Serial2.available() == 0); + while (Serial2.available() > 0){ + this->trame->push_back(Serial2.read()); + } +} + + +String NfcReader::digitify(int number){ + String sortie = ""; + + if(number <= 0xF){ + sortie += '0'; + sortie += String(number,HEX); + }else{ + sortie += String(number,HEX); + } + + return sortie; +} + + +void NfcReader::printTrame(){ + for(byte i: *this->trame){ + Serial.print(this->digitify(i)); + Serial.print(" "); + } + Serial.println(); +} + +int NfcReader::getNbTags(){ + return this->trame->at(8); +} -- 2.47.1 From 35ecce7d5d729d3d7ef3b5ddd3cb98da86d6cf51 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 1 Feb 2024 11:53:19 +0100 Subject: [PATCH 3/5] sync --- include/Program.h | 2 ++ .../include/{NfcReader.h => BigNfcReader.h} | 8 ++++---- .../src/{NfcReader.cpp => BigNfcReader.cpp} | 14 +++++++------- src/Program.cpp | 3 +++ 4 files changed, 16 insertions(+), 11 deletions(-) rename lib/NfcReader/include/{NfcReader.h => BigNfcReader.h} (91%) rename lib/NfcReader/src/{NfcReader.cpp => BigNfcReader.cpp} (87%) diff --git a/include/Program.h b/include/Program.h index 4d632c5..2f073d8 100644 --- a/include/Program.h +++ b/include/Program.h @@ -6,6 +6,7 @@ #include "ServoMotorComponent.h" #include "NfcReader.h" #include "GRBL.h" +#include "BigNfcReader.h" class Program { public: @@ -26,6 +27,7 @@ private: ServoMotorComponent *servo; NfcReader *nfcReader; GRBL *grbl; + BigNfcReader* outputReader; }; #endif diff --git a/lib/NfcReader/include/NfcReader.h b/lib/NfcReader/include/BigNfcReader.h similarity index 91% rename from lib/NfcReader/include/NfcReader.h rename to lib/NfcReader/include/BigNfcReader.h index b341155..287ecee 100644 --- a/lib/NfcReader/include/NfcReader.h +++ b/lib/NfcReader/include/BigNfcReader.h @@ -1,14 +1,14 @@ -#ifndef NFC_READER_H -#define NFC_READER_H +#ifndef BIG_NFC_READER_H +#define BIG_NFC_READER_H #include #include #include "TrameList.h" -class NfcReader{ +class BigNfcReader{ public: - NfcReader(); + BigNfcReader(); /** * @brief initialise le lecteur NFC diff --git a/lib/NfcReader/src/NfcReader.cpp b/lib/NfcReader/src/BigNfcReader.cpp similarity index 87% rename from lib/NfcReader/src/NfcReader.cpp rename to lib/NfcReader/src/BigNfcReader.cpp index 133b13e..02738bf 100644 --- a/lib/NfcReader/src/NfcReader.cpp +++ b/lib/NfcReader/src/BigNfcReader.cpp @@ -1,14 +1,14 @@ -#include "../include/NfcReader.h" +#include "../include/BigNfcReader.h" -NfcReader::NfcReader(){ +BigNfcReader::BigNfcReader(){ Serial2.begin(115200,SERIAL_8N1,2,3);//TODO: mettre le port série en paramètre this->pair = true; this->trame = new std::vector(); } -bool NfcReader::init(){ +bool BigNfcReader::init(){ const std::vector> INIT_TRAMES = {INIT_TRAM_0, INIT_TRAM_1, INIT_TRAM_2, INIT_TRAM_3, INIT_TRAM_4, INIT_TRAM_5, INIT_TRAM_6, INIT_TRAM_7}; const std::vector> REP_TRAMES = {REP_TRAM_0, REP_TRAM_1, REP_TRAM_2, REP_TRAM_3, REP_TRAM_4, REP_TRAM_5, REP_TRAM_6, REP_TRAM_7}; int repnb = 0; @@ -30,7 +30,7 @@ bool NfcReader::init(){ return true; } -void NfcReader::refresh(){ +void BigNfcReader::refresh(){ this->trame->clear(); std::vector trame = READ_TRAM_0; if (this->pair){ @@ -48,7 +48,7 @@ void NfcReader::refresh(){ } -String NfcReader::digitify(int number){ +String BigNfcReader::digitify(int number){ String sortie = ""; if(number <= 0xF){ @@ -62,7 +62,7 @@ String NfcReader::digitify(int number){ } -void NfcReader::printTrame(){ +void BigNfcReader::printTrame(){ for(byte i: *this->trame){ Serial.print(this->digitify(i)); Serial.print(" "); @@ -70,6 +70,6 @@ void NfcReader::printTrame(){ Serial.println(); } -int NfcReader::getNbTags(){ +int BigNfcReader::getNbTags(){ return this->trame->at(8); } diff --git a/src/Program.cpp b/src/Program.cpp index a054b3c..b932811 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -80,6 +80,7 @@ Program::Program() { this->servo = new ServoMotorComponent(2, 1, 1); this->servo->setDesiredPosition(Position::MIDDLE); this->grbl = new GRBL(STEPMOTOR_I2C_ADDR); + this->outputReader = new BigNfcReader(); Wire.begin(21, 22); grbl->init(STEPER_SPEED, STEPER_PAS, STEPER_ACC); struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD}; @@ -97,6 +98,8 @@ void Program::loop() { derniereExecution = maintenant; } this->servo->refresh(); + this->outputReader->refresh(); + Serial.printf("Output colis number : ", this->outputReader->getNbTags()); String nfcId = this->nfcReader->ReadNfc(); //si qqc -- 2.47.1 From 7b975bd9a9cb52b8f79419e43b02959bf39c853b Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 1 Feb 2024 15:38:04 +0100 Subject: [PATCH 4/5] add to mutch colis error --- lib/NfcReader/src/BigNfcReader.cpp | 2 +- src/Program.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/NfcReader/src/BigNfcReader.cpp b/lib/NfcReader/src/BigNfcReader.cpp index 02738bf..abbbf7c 100644 --- a/lib/NfcReader/src/BigNfcReader.cpp +++ b/lib/NfcReader/src/BigNfcReader.cpp @@ -2,7 +2,7 @@ BigNfcReader::BigNfcReader(){ - Serial2.begin(115200,SERIAL_8N1,2,3);//TODO: mettre le port série en paramètre + Serial2.begin(115200, SERIAL_8N1, 16, 17);//TODO: mettre le port série en paramètre this->pair = true; this->trame = new std::vector(); } diff --git a/src/Program.cpp b/src/Program.cpp index b932811..c01be89 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -80,7 +80,8 @@ Program::Program() { this->servo = new ServoMotorComponent(2, 1, 1); this->servo->setDesiredPosition(Position::MIDDLE); this->grbl = new GRBL(STEPMOTOR_I2C_ADDR); - this->outputReader = new BigNfcReader(); + this->outputReader = new BigNfcReader(); + this->outputReader->init(); Wire.begin(21, 22); grbl->init(STEPER_SPEED, STEPER_PAS, STEPER_ACC); struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD}; @@ -99,7 +100,12 @@ void Program::loop() { } this->servo->refresh(); this->outputReader->refresh(); - Serial.printf("Output colis number : ", this->outputReader->getNbTags()); + Serial.println(this->outputReader->getNbTags()); + + if(this->outputReader->getNbTags() >= 2){ + lcdScreen->set_nfc_message("To mutch colis number detected"); + return; + } String nfcId = this->nfcReader->ReadNfc(); //si qqc -- 2.47.1 From 9c11f6201971a943045384772f5d6191a8614b00 Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 2 Feb 2024 14:39:50 +0100 Subject: [PATCH 5/5] add timer for stepper --- config.ini | 1 + include/Program.h | 1 + src/Program.cpp | 7 +++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/config.ini b/config.ini index 133d750..6503517 100644 --- a/config.ini +++ b/config.ini @@ -23,6 +23,7 @@ build_flags = ;-D STEPER_PAS=755.906 ; = 65mm -D STEPER_PAS=58 ; = 5mm -D STEPER_SPEED=2700 ;1000 ; 2500 + -D GRBL_UPDATE=165 ;update time in ms ;;;;;;;;;;;;;;;;;;;;;; ;;; App config ;;; ;;;;;;;;;;;;;;;;;;;;;; diff --git a/include/Program.h b/include/Program.h index 2f073d8..ce4f803 100644 --- a/include/Program.h +++ b/include/Program.h @@ -28,6 +28,7 @@ private: NfcReader *nfcReader; GRBL *grbl; BigNfcReader* outputReader; + int grblUpdateTime; }; #endif diff --git a/src/Program.cpp b/src/Program.cpp index c01be89..0067723 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -82,6 +82,7 @@ Program::Program() { this->grbl = new GRBL(STEPMOTOR_I2C_ADDR); this->outputReader = new BigNfcReader(); this->outputReader->init(); + this->grblUpdateTime = 0; Wire.begin(21, 22); grbl->init(STEPER_SPEED, STEPER_PAS, STEPER_ACC); struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD}; @@ -100,7 +101,7 @@ void Program::loop() { } this->servo->refresh(); this->outputReader->refresh(); - Serial.println(this->outputReader->getNbTags()); + // Serial.println(this->outputReader->getNbTags()); if(this->outputReader->getNbTags() >= 2){ lcdScreen->set_nfc_message("To mutch colis number detected"); @@ -162,8 +163,10 @@ void Program::loop() { } this->grbl->mouveForward(CONVOYER_LEN); } else { - if(this->grbl->isIddle()){ + if(this->grbl->isIddle() || (maintenant - this->grblUpdateTime >= GRBL_UPDATE)){ + this->grblUpdateTime = maintenant; this->grbl->mouveForward(5); + Serial.print("pouet"); } } } -- 2.47.1