From 9c11f6201971a943045384772f5d6191a8614b00 Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 2 Feb 2024 14:39:50 +0100 Subject: [PATCH] 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"); } } }