From 8d26a52415c5195281c84ca07297d201dd3f83d9 Mon Sep 17 00:00:00 2001 From: ameisso Date: Sat, 13 Jan 2024 20:57:07 +0100 Subject: [PATCH 1/6] New : getters for acceleration and desceleration --- src/ESP_FlexyStepper.cpp | 32 ++++++++++++++++++++++++++++++++ src/ESP_FlexyStepper.h | 8 ++++++++ 2 files changed, 40 insertions(+) diff --git a/src/ESP_FlexyStepper.cpp b/src/ESP_FlexyStepper.cpp index 1d5b387..2965228 100644 --- a/src/ESP_FlexyStepper.cpp +++ b/src/ESP_FlexyStepper.cpp @@ -610,6 +610,38 @@ float ESP_FlexyStepper::getCurrentVelocityInMillimetersPerSecond() return (getCurrentVelocityInStepsPerSecond() / stepsPerMillimeter); } + +float ESP_FlexyStepper::getCurrentAccelerationInStepsPerSecondPerSecond() +{ + return acceleration_InStepsPerSecondPerSecond; +} + +float ESP_FlexyStepper::getCurrentAccelerationInRevolutionsPerSecondPerSecond() +{ + return acceleration_InStepsPerSecondPerSecond / stepsPerRevolution; +} + +float ESP_FlexyStepper::getCurrentAccelerationInMillimetersPerSecondPerSecond() +{ + return getCurrentAccelerationInStepsPerSecondPerSecond() / stepsPerMillimeter; +} + +float ESP_FlexyStepper::getCurrentDescelerationInStepsPerSecondPerSecond() +{ + return deceleration_InStepsPerSecondPerSecond; +} + +float ESP_FlexyStepper::getCurrentDescelerationInRevolutionsPerSecondPerSecond() +{ + return deceleration_InStepsPerSecondPerSecond / stepsPerRevolution; +} + +float ESP_FlexyStepper::getCurrentDescelerationInMillimetersPerSecondPerSecond() +{ + return deceleration_InStepsPerSecondPerSecond / stepsPerMillimeter; +} + + // --------------------------------------------------------------------------------- // Public functions with units in revolutions // --------------------------------------------------------------------------------- diff --git a/src/ESP_FlexyStepper.h b/src/ESP_FlexyStepper.h index b4dda2d..081f62e 100644 --- a/src/ESP_FlexyStepper.h +++ b/src/ESP_FlexyStepper.h @@ -109,6 +109,14 @@ class ESP_FlexyStepper float getCurrentVelocityInRevolutionsPerSecond(); float getCurrentVelocityInMillimetersPerSecond(void); + float getCurrentAccelerationInStepsPerSecondPerSecond(); + float getCurrentAccelerationInRevolutionsPerSecondPerSecond(); + float getCurrentAccelerationInMillimetersPerSecondPerSecond(); + + float getCurrentDescelerationInStepsPerSecondPerSecond(); + float getCurrentDescelerationInRevolutionsPerSecondPerSecond(); + float getCurrentDescelerationInMillimetersPerSecondPerSecond(); + // positioning functions void setCurrentPositionInSteps(long currentPositionInSteps); void setCurrentPositionInMillimeters(float currentPositionInMillimeters); From cc7eee51fa89556513b75ac532a5079c46a05f10 Mon Sep 17 00:00:00 2001 From: ameisso Date: Sun, 14 Jan 2024 12:54:38 +0100 Subject: [PATCH 2/6] Fix : rename getters for acceleration and deceleration parameters --- src/ESP_FlexyStepper.cpp | 17 ++++++++++------- src/ESP_FlexyStepper.h | 12 ++++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/ESP_FlexyStepper.cpp b/src/ESP_FlexyStepper.cpp index 2965228..5ef3e24 100644 --- a/src/ESP_FlexyStepper.cpp +++ b/src/ESP_FlexyStepper.cpp @@ -610,33 +610,36 @@ float ESP_FlexyStepper::getCurrentVelocityInMillimetersPerSecond() return (getCurrentVelocityInStepsPerSecond() / stepsPerMillimeter); } +/* +access the acceleration/deceleration parameters set by user +*/ -float ESP_FlexyStepper::getCurrentAccelerationInStepsPerSecondPerSecond() +float ESP_FlexyStepper::getConfiguredAccelerationInStepsPerSecondPerSecond() { return acceleration_InStepsPerSecondPerSecond; } -float ESP_FlexyStepper::getCurrentAccelerationInRevolutionsPerSecondPerSecond() +float ESP_FlexyStepper::getConfiguredAccelerationInRevolutionsPerSecondPerSecond() { return acceleration_InStepsPerSecondPerSecond / stepsPerRevolution; } -float ESP_FlexyStepper::getCurrentAccelerationInMillimetersPerSecondPerSecond() +float ESP_FlexyStepper::getConfiguredAccelerationInMillimetersPerSecondPerSecond() { - return getCurrentAccelerationInStepsPerSecondPerSecond() / stepsPerMillimeter; + return acceleration_InStepsPerSecondPerSecond / stepsPerMillimeter; } -float ESP_FlexyStepper::getCurrentDescelerationInStepsPerSecondPerSecond() +float ESP_FlexyStepper::getConfiguredDescelerationInStepsPerSecondPerSecond() { return deceleration_InStepsPerSecondPerSecond; } -float ESP_FlexyStepper::getCurrentDescelerationInRevolutionsPerSecondPerSecond() +float ESP_FlexyStepper::getConfiguredDescelerationInRevolutionsPerSecondPerSecond() { return deceleration_InStepsPerSecondPerSecond / stepsPerRevolution; } -float ESP_FlexyStepper::getCurrentDescelerationInMillimetersPerSecondPerSecond() +float ESP_FlexyStepper::getConfiguredDescelerationInMillimetersPerSecondPerSecond() { return deceleration_InStepsPerSecondPerSecond / stepsPerMillimeter; } diff --git a/src/ESP_FlexyStepper.h b/src/ESP_FlexyStepper.h index 081f62e..f601ed4 100644 --- a/src/ESP_FlexyStepper.h +++ b/src/ESP_FlexyStepper.h @@ -109,13 +109,13 @@ class ESP_FlexyStepper float getCurrentVelocityInRevolutionsPerSecond(); float getCurrentVelocityInMillimetersPerSecond(void); - float getCurrentAccelerationInStepsPerSecondPerSecond(); - float getCurrentAccelerationInRevolutionsPerSecondPerSecond(); - float getCurrentAccelerationInMillimetersPerSecondPerSecond(); + float getConfiguredAccelerationInStepsPerSecondPerSecond(); + float getConfiguredAccelerationInRevolutionsPerSecondPerSecond(); + float getConfiguredAccelerationInMillimetersPerSecondPerSecond(); - float getCurrentDescelerationInStepsPerSecondPerSecond(); - float getCurrentDescelerationInRevolutionsPerSecondPerSecond(); - float getCurrentDescelerationInMillimetersPerSecondPerSecond(); + float getConfiguredDescelerationInStepsPerSecondPerSecond(); + float getConfiguredDescelerationInRevolutionsPerSecondPerSecond(); + float getConfiguredDescelerationInMillimetersPerSecondPerSecond(); // positioning functions void setCurrentPositionInSteps(long currentPositionInSteps); From d3658eaace3dcaf7519407b8ecc49b7d38874923 Mon Sep 17 00:00:00 2001 From: ameisso Date: Sun, 14 Jan 2024 14:21:54 +0100 Subject: [PATCH 3/6] Clean : identation --- src/ESP_FlexyStepper.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ESP_FlexyStepper.cpp b/src/ESP_FlexyStepper.cpp index cf9978e..6a9763a 100644 --- a/src/ESP_FlexyStepper.cpp +++ b/src/ESP_FlexyStepper.cpp @@ -340,7 +340,7 @@ void ESP_FlexyStepper::setEnablePin(signed char enablePin, byte activeState) this->enablePinActiveState = ESP_FlexyStepper::ACTIVE_LOW; } - if(this->enablePin >= 0) + if (this->enablePin >= 0) { // configure the IO pins pinMode((uint8_t)this->enablePin, OUTPUT); @@ -418,7 +418,7 @@ bool ESP_FlexyStepper::isBrakeActive() */ void ESP_FlexyStepper::enableDriver(void) { -if (this->_isEnableConfigured) + if (this->_isEnableConfigured) { digitalWrite((uint8_t)this->enablePin, (this->enablePinActiveState == ESP_FlexyStepper::ACTIVE_HIGH) ? 1 : 0); this->_isDriverEnabled = true; @@ -611,7 +611,7 @@ float ESP_FlexyStepper::getCurrentVelocityInMillimetersPerSecond() } /* -access the acceleration/deceleration parameters set by user +access the acceleration/deceleration parameters set by user */ float ESP_FlexyStepper::getConfiguredAccelerationInStepsPerSecondPerSecond() @@ -636,7 +636,7 @@ float ESP_FlexyStepper::getConfiguredDescelerationInStepsPerSecondPerSecond() float ESP_FlexyStepper::getConfiguredDescelerationInRevolutionsPerSecondPerSecond() { - return deceleration_InStepsPerSecondPerSecond / stepsPerRevolution; + return deceleration_InStepsPerSecondPerSecond / stepsPerRevolution; } float ESP_FlexyStepper::getConfiguredDescelerationInMillimetersPerSecondPerSecond() From 8239eb87854025a4361dc3b408e0b21b88acb311 Mon Sep 17 00:00:00 2001 From: ameisso Date: Sun, 14 Jan 2024 14:33:30 +0100 Subject: [PATCH 4/6] fix : core 1 doesn't exist on esp32C3 and S2 --- src/ESP_FlexyStepper.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ESP_FlexyStepper.cpp b/src/ESP_FlexyStepper.cpp index 6a9763a..555d15a 100644 --- a/src/ESP_FlexyStepper.cpp +++ b/src/ESP_FlexyStepper.cpp @@ -96,7 +96,9 @@ bool ESP_FlexyStepper::startAsService(int coreNumber) if (coreNumber == 1) { +#if ! (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2) disableCore1WDT(); // we have to disable the Watchdog timer to prevent it from rebooting the ESP all the time another option would be to add a vTaskDelay but it would slow down the stepper +#endif } else if (coreNumber == 0) { From 0a891ea6d6602c1204d6b42005745dd13a5a26a5 Mon Sep 17 00:00:00 2001 From: ameisso Date: Sun, 14 Jan 2024 20:08:44 +0100 Subject: [PATCH 5/6] Fix : typo in function name --- src/ESP_FlexyStepper.cpp | 6 +++--- src/ESP_FlexyStepper.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ESP_FlexyStepper.cpp b/src/ESP_FlexyStepper.cpp index 555d15a..5ff8f9d 100644 --- a/src/ESP_FlexyStepper.cpp +++ b/src/ESP_FlexyStepper.cpp @@ -631,17 +631,17 @@ float ESP_FlexyStepper::getConfiguredAccelerationInMillimetersPerSecondPerSecond return acceleration_InStepsPerSecondPerSecond / stepsPerMillimeter; } -float ESP_FlexyStepper::getConfiguredDescelerationInStepsPerSecondPerSecond() +float ESP_FlexyStepper::getConfiguredDecelerationInStepsPerSecondPerSecond() { return deceleration_InStepsPerSecondPerSecond; } -float ESP_FlexyStepper::getConfiguredDescelerationInRevolutionsPerSecondPerSecond() +float ESP_FlexyStepper::getConfiguredDecelerationInRevolutionsPerSecondPerSecond() { return deceleration_InStepsPerSecondPerSecond / stepsPerRevolution; } -float ESP_FlexyStepper::getConfiguredDescelerationInMillimetersPerSecondPerSecond() +float ESP_FlexyStepper::getConfiguredDecelerationInMillimetersPerSecondPerSecond() { return deceleration_InStepsPerSecondPerSecond / stepsPerMillimeter; } diff --git a/src/ESP_FlexyStepper.h b/src/ESP_FlexyStepper.h index d8161bc..b39a73e 100644 --- a/src/ESP_FlexyStepper.h +++ b/src/ESP_FlexyStepper.h @@ -113,9 +113,9 @@ class ESP_FlexyStepper float getConfiguredAccelerationInRevolutionsPerSecondPerSecond(); float getConfiguredAccelerationInMillimetersPerSecondPerSecond(); - float getConfiguredDescelerationInStepsPerSecondPerSecond(); - float getConfiguredDescelerationInRevolutionsPerSecondPerSecond(); - float getConfiguredDescelerationInMillimetersPerSecondPerSecond(); + float getConfiguredDecelerationInStepsPerSecondPerSecond(); + float getConfiguredDecelerationInRevolutionsPerSecondPerSecond(); + float getConfiguredDecelerationInMillimetersPerSecondPerSecond(); // positioning functions void setCurrentPositionInSteps(long currentPositionInSteps); From 345d2d7a2e7cab2a29df8b0f4876d76af3260726 Mon Sep 17 00:00:00 2001 From: ameisso Date: Mon, 15 Jan 2024 14:13:53 +0100 Subject: [PATCH 6/6] Fix : avoid empty code blocks --- src/ESP_FlexyStepper.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ESP_FlexyStepper.cpp b/src/ESP_FlexyStepper.cpp index 5ff8f9d..b257253 100644 --- a/src/ESP_FlexyStepper.cpp +++ b/src/ESP_FlexyStepper.cpp @@ -93,17 +93,16 @@ ESP_FlexyStepper::~ESP_FlexyStepper() // TODO: use https://github.com/nrwiersma/ESP8266Scheduler/blob/master/examples/simple/simple.ino for ESP8266 bool ESP_FlexyStepper::startAsService(int coreNumber) { - - if (coreNumber == 1) + if (coreNumber == 0) { -#if ! (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2) - disableCore1WDT(); // we have to disable the Watchdog timer to prevent it from rebooting the ESP all the time another option would be to add a vTaskDelay but it would slow down the stepper -#endif + disableCore0WDT(); // we have to disable the Watchdog timer to prevent it from rebooting the ESP all the time another option would be to add a vTaskDelay but it would slow down the stepper } - else if (coreNumber == 0) +#if !(CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2) + else if (coreNumber == 1) { - disableCore0WDT(); // we have to disable the Watchdog timer to prevent it from rebooting the ESP all the time another option would be to add a vTaskDelay but it would slow down the stepper + disableCore1WDT(); // we have to disable the Watchdog timer to prevent it from rebooting the ESP all the time another option would be to add a vTaskDelay but it would slow down the stepper } +#endif else { // invalid core number given @@ -646,7 +645,6 @@ float ESP_FlexyStepper::getConfiguredDecelerationInMillimetersPerSecondPerSecond return deceleration_InStepsPerSecondPerSecond / stepsPerMillimeter; } - // --------------------------------------------------------------------------------- // Public functions with units in revolutions // ---------------------------------------------------------------------------------