From 5217514e7b91c6d921b8dd38b9fd3f21e4514e8a Mon Sep 17 00:00:00 2001 From: Benjamin GERVY Date: Tue, 21 Nov 2023 18:00:55 +0100 Subject: [PATCH 1/6] Update teensycontrol.ino changement de temps avant que le moteur ne se replace --- teensycontrol/teensycontrol.ino | 35 ++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/teensycontrol/teensycontrol.ino b/teensycontrol/teensycontrol.ino index c5511e3..a764be4 100644 --- a/teensycontrol/teensycontrol.ino +++ b/teensycontrol/teensycontrol.ino @@ -3,8 +3,13 @@ #include "processing.h" #include // Include the Metro library -Metro displayMissedStep = Metro(100); // 100ms -Metro moveMissedStep = Metro(2000); // 2s +//int timeElapsedBeforeAdaptPositionFromProcessing; +int timeElapsedBeforeAdaptPosition = 8000; +int missedStepInterval; + +Metro displayMissedStep = Metro(30); // 30ms +Metro moveMissedStep = Metro(timeElapsedBeforeAdaptPosition); // 1seconde + #define PROCESSING // Uncomment this line to use proccessing, comment this line if you want to use serial demo. #define AUTORETURN // Uncomment this line to use auto return feature, comment to desactivate the feature. @@ -17,20 +22,21 @@ void setup() { initProcessing(); #else printSerialCommandsAvailable(); -#endif +#endif } void loop() { - if (displayMissedStep.check()) { toggleLed(); - if (checkMissedStep(false)) { + +// if (checkMissedStep(false)) { #ifdef PROCESSING displayAllCountSerial1(); + checkMissedStep(false); #else displayAllCountSerial(); #endif - } +// } } if (moveMissedStep.check()) { @@ -41,8 +47,23 @@ void loop() { #ifdef PROCESSING processingControl(); + + /* + if ( PCTer[5] != missedStepInterval ) { + moveMissedStep.interval(PCTer[5]); + missedStepInterval = PCTer[5]; + } + */ + + // timeElapsedBeforeAdaptPosition= timeElapsedBeforeAdaptPositionFromProcessing; + + if ( timeElapsedBeforeAdaptPosition != missedStepInterval ) { + moveMissedStep.interval(timeElapsedBeforeAdaptPosition); + missedStepInterval = timeElapsedBeforeAdaptPosition; + } + #else readSerial(); #endif run(); -} +} \ No newline at end of file From 3cb01b98e4bc90a2a69300896fc8fc6f100f4cfd Mon Sep 17 00:00:00 2001 From: Benjamin GERVY Date: Tue, 21 Nov 2023 18:01:34 +0100 Subject: [PATCH 2/6] Update com.cpp --- teensycontrol/com.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/teensycontrol/com.cpp b/teensycontrol/com.cpp index a05f333..7d0f55d 100644 --- a/teensycontrol/com.cpp +++ b/teensycontrol/com.cpp @@ -3,7 +3,7 @@ void initCom() { Serial.begin(115200); - Serial1.begin(1000000); + Serial1.begin(115200); } void printSerialCommandsAvailable() { @@ -176,4 +176,4 @@ void printCmdValVal( String cmd, int32_t val1, int32_t val2) { Serial.print(" "); Serial.print(val2); Serial.print("\n"); -} +} \ No newline at end of file From 542338c36a12d75862613ed262a625273090ce87 Mon Sep 17 00:00:00 2001 From: Benjamin GERVY Date: Tue, 21 Nov 2023 18:04:27 +0100 Subject: [PATCH 3/6] Update com.h --- teensycontrol/com.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/teensycontrol/com.h b/teensycontrol/com.h index 1cfb6d7..07d21e6 100644 --- a/teensycontrol/com.h +++ b/teensycontrol/com.h @@ -11,4 +11,4 @@ void parseSerialBuffer(); void printCmdVal( String cmd, int32_t val); void printCmdValVal( String cmd, int32_t val1, int32_t val2); -#endif +#endif \ No newline at end of file From 1cbb9594412083f7c18780e3faa3ca346b6645bc Mon Sep 17 00:00:00 2001 From: Benjamin GERVY Date: Tue, 21 Nov 2023 18:06:00 +0100 Subject: [PATCH 4/6] Update processing.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit //int missedStepInterval; je ne sais pas où on met la variable globale --- teensycontrol/processing.cpp | 88 ++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/teensycontrol/processing.cpp b/teensycontrol/processing.cpp index b1bba3c..be2fb08 100644 --- a/teensycontrol/processing.cpp +++ b/teensycontrol/processing.cpp @@ -1,5 +1,6 @@ #include "processing.h" + // Receive with start- and end-markers combined with parsing const byte numChars = 200; char receivedChars[numChars]; @@ -9,6 +10,15 @@ char tempChars[numChars]; // temporary array for use when parsing char messageFromPC[numChars] = { 0 }; //or 5 doesn't change anything #define NBDATA 10 + +int timeElasped; + +//int missedStepInterval; + +int timeElapsedBeforeAdaptPositionFromProcessing; + + + int integerFromPC[NBDATA] = { 0 }; int PC[NBDATA] = { 0 }; int PCTer[NBDATA] = { 0 }; @@ -44,6 +54,9 @@ int16_t computeDeltaPosition(uint8_t n) { oldPositionAbsolue[n] = positionAbsolue; return resultat; } +void doReboot() { // reset Teensy + SCB_AIRCR = 0x05FA0004; +} void initProcessing() { for (uint8_t i = 0; i < NBDATA; i++) { @@ -52,16 +65,87 @@ void initProcessing() { int tourTest = 6400 * 0; + timeElapsedBeforeAdaptPositionFromProcessing=8000; + for (uint8_t i = 0; i < NBMOTORS; i++) { PC[i] = tourTest * 1; // premier devant moi } PCTer[2] = -3; //noJoe method of Processng data conversion + + PCTer[4] = 1; // driver actived (LOW + PCTer[1] = 0; // driver disable (HIGH } void processingControl() { + + if (PCTer[1] > 0) + { + digitalWrite(EN[0], LOW); + } + + if (PCTer[1] < 1) + { + digitalWrite(EN[0], HIGH); + } + + if (PCTer[4] > 0) + { + digitalWrite(EN[NBMOTORS-1], LOW); // + digitalWrite(EN[NBMOTORS-2], LOW); + digitalWrite(EN[NBMOTORS-3], LOW); + digitalWrite(EN[NBMOTORS-4], LOW); + digitalWrite(EN[NBMOTORS-5], LOW); + } + if (PCTer[4] < 1) + { + digitalWrite(EN[NBMOTORS-1], HIGH); // + digitalWrite(EN[NBMOTORS-2], HIGH); + digitalWrite(EN[NBMOTORS-3], HIGH); + digitalWrite(EN[NBMOTORS-4], HIGH); + digitalWrite(EN[NBMOTORS-5], HIGH); + } + + timeElapsedBeforeAdaptPositionFromProcessing = PCTer[5]; + + // timeElapsedBeforeAdaptPosition= timeElapsedBeforeAdaptPositionFromProcessing; + + +/* + if ( PCTer[5] != missedStepInterval ) { + moveMissedStep.interval(PCTer[5]); + missedStepInterval = PCTer[5]; + } + */ + + //------------ Bellow method to avoiding motor go back to zero when i restart Processing. It doesn't work + + // load 0 to all motor. Erase position datas + if (PCTer[3] >= 2) { + for (uint8_t i = 0; i < NBDATA; i++) { + PC[i]=0; + processingPosition[i] = PC[i]; + positionX[i]=processingPosition[i]; + + } + doReboot(); + } + +/* + if (PCTer[3] >= 2) { + for (uint8_t i = 0; i < NBDATA; i++) { + PC[i]=0; + processingPosition[i] = PC[i]; + + + } + doReboot(); + } + + // Maybe it is better to find something else in Processing + */ recvWithStartEndMarkers(); // recevoir chaine de character et disperse en unité if (newData == true) { strcpy(tempChars, receivedChars); @@ -88,6 +172,10 @@ void processingControl() { } writeTargets(); } + + + + } void recvWithStartEndMarkers() { From bc0befdaa76185d717f2255faaacb908626dfff4 Mon Sep 17 00:00:00 2001 From: Benjamin GERVY Date: Tue, 21 Nov 2023 18:14:16 +0100 Subject: [PATCH 5/6] Update teensycontrol.ino comment integrer missedStepInterval? --- teensycontrol/teensycontrol.ino | 60 ++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/teensycontrol/teensycontrol.ino b/teensycontrol/teensycontrol.ino index a764be4..d1761bb 100644 --- a/teensycontrol/teensycontrol.ino +++ b/teensycontrol/teensycontrol.ino @@ -1,20 +1,20 @@ #include "io.h" #include "com.h" #include "processing.h" -#include // Include the Metro library +#include // Include the Metro library -//int timeElapsedBeforeAdaptPositionFromProcessing; +// int timeElapsedBeforeAdaptPositionFromProcessing; int timeElapsedBeforeAdaptPosition = 8000; int missedStepInterval; -Metro displayMissedStep = Metro(30); // 30ms -Metro moveMissedStep = Metro(timeElapsedBeforeAdaptPosition); // 1seconde +Metro displayMissedStep = Metro(30); // 30ms +Metro moveMissedStep = Metro(timeElapsedBeforeAdaptPosition); // 1seconde +#define PROCESSING // Uncomment this line to use proccessing, comment this line if you want to use serial demo. +#define AUTORETURN // Uncomment this line to use auto return feature, comment to desactivate the feature. -#define PROCESSING // Uncomment this line to use proccessing, comment this line if you want to use serial demo. -#define AUTORETURN // Uncomment this line to use auto return feature, comment to desactivate the feature. - -void setup() { +void setup() +{ initIo(); initCom(); initSteppers(); @@ -22,24 +22,27 @@ void setup() { initProcessing(); #else printSerialCommandsAvailable(); -#endif +#endif } -void loop() { - if (displayMissedStep.check()) { +void loop() +{ + if (displayMissedStep.check()) + { toggleLed(); - -// if (checkMissedStep(false)) { + +// if (checkMissedStep(false)) { // permet d'avoir les positions tous le temps sur le port serie1 #ifdef PROCESSING - displayAllCountSerial1(); - checkMissedStep(false); + displayAllCountSerial1(); + checkMissedStep(false); #else - displayAllCountSerial(); + displayAllCountSerial(); #endif -// } + // } } - if (moveMissedStep.check()) { + if (moveMissedStep.check()) + { #ifdef AUTORETURN checkMissedStep(true); #endif @@ -47,21 +50,22 @@ void loop() { #ifdef PROCESSING processingControl(); - + /* if ( PCTer[5] != missedStepInterval ) { moveMissedStep.interval(PCTer[5]); - missedStepInterval = PCTer[5]; - } - */ + missedStepInterval = PCTer[5]; + } + */ + + // timeElapsedBeforeAdaptPosition= timeElapsedBeforeAdaptPositionFromProcessing; - // timeElapsedBeforeAdaptPosition= timeElapsedBeforeAdaptPositionFromProcessing; + if (timeElapsedBeforeAdaptPosition != missedStepInterval) + { + moveMissedStep.interval(timeElapsedBeforeAdaptPosition); + missedStepInterval = timeElapsedBeforeAdaptPosition; + } - if ( timeElapsedBeforeAdaptPosition != missedStepInterval ) { - moveMissedStep.interval(timeElapsedBeforeAdaptPosition); - missedStepInterval = timeElapsedBeforeAdaptPosition; - } - #else readSerial(); #endif From 66335bd963b85935e07729597a6da3056824a337 Mon Sep 17 00:00:00 2001 From: Benjamin GERVY Date: Thu, 23 Nov 2023 19:39:19 +0100 Subject: [PATCH 6/6] Update processing.cpp --- teensycontrol/processing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/teensycontrol/processing.cpp b/teensycontrol/processing.cpp index be2fb08..52433b4 100644 --- a/teensycontrol/processing.cpp +++ b/teensycontrol/processing.cpp @@ -31,7 +31,7 @@ int startStop = 0; float floatFromPC = 0.0; // not used for the moment boolean newData = false; -//==================================================================== CHECK NUMBEROF ROUND AND GOOD MOVEMENT +//==================================================================== CHECK NUMBER OF ROUND AND GOOD MOVEMENT #define TX_SIZE 512 uint8_t tx_buffer[TX_SIZE];