From 9e8f4b51f5e40ba8f016d4e3738c4d1457c5c133 Mon Sep 17 00:00:00 2001 From: ChrGri Date: Sun, 4 Aug 2024 12:12:13 +0200 Subject: [PATCH] Per user request, slow movement to min position when new config is sent to pedal --- ESP32/include/StepperWithLimits.h | 1 + ESP32/src/Main.cpp | 14 ++++++++++- ESP32/src/StepperWithLimits.cpp | 25 +++++++++++-------- .../FastAccelStepper/library.properties | 12 +++++++++ 4 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 ESP32_master/.pio/libdeps/esp32-speedcrafter/FastAccelStepper/library.properties diff --git a/ESP32/include/StepperWithLimits.h b/ESP32/include/StepperWithLimits.h index c3f1a2dc..558a54d6 100644 --- a/ESP32/include/StepperWithLimits.h +++ b/ESP32/include/StepperWithLimits.h @@ -31,6 +31,7 @@ class StepperWithLimits { void refindMinLimitSensorless(isv57communication * isv57); public: int8_t moveTo(int32_t position, bool blocking = false); + void moveSlowlyToPos(int32_t targetPos_ui32); void printStates(); public: diff --git a/ESP32/src/Main.cpp b/ESP32/src/Main.cpp index 4d930298..e2ed4d94 100644 --- a/ESP32/src/Main.cpp +++ b/ESP32/src/Main.cpp @@ -231,6 +231,8 @@ StepperWithLimits* stepper = NULL; //static const int32_t MIN_STEPS = 5; #include "StepperMovementStrategy.h" + +bool moveSlowlyToPosition_b = false; /**********************************************************************************************/ /* */ /* OTA */ @@ -800,6 +802,7 @@ void pedalUpdateTask( void * pvParameters ) } updatePedalCalcParameters(); // update the calc parameters + moveSlowlyToPosition_b = true; } } @@ -1114,10 +1117,19 @@ void pedalUpdateTask( void * pvParameters ) //int32_t stepperPosCurrent = stepper->getCurrentPositionFromMin(); //int32_t stepperPosCurrent = stepper->getTargetPositionSteps(); //int32_t movement = abs(stepperPosCurrent - Position_Next); - //if (movement > MIN_STEPS) + if (!moveSlowlyToPosition_b) { stepper->moveTo(Position_Next, false); } + else + { + moveSlowlyToPosition_b = false; + stepper->moveSlowlyToPos(Position_Next); + } + + // move slowly to target position + + diff --git a/ESP32/src/StepperWithLimits.cpp b/ESP32/src/StepperWithLimits.cpp index 8262d1ec..ac59d50c 100644 --- a/ESP32/src/StepperWithLimits.cpp +++ b/ESP32/src/StepperWithLimits.cpp @@ -132,25 +132,30 @@ void StepperWithLimits::findMinMaxSensorless(isv57communication * isv57, DAP_con _limitMax = _stepper->getCurrentPosition(); + + // move slowly to min position + moveSlowlyToPos(_posMin); + + +#if defined(SUPPORT_ESP32_PULSE_COUNTER) + _stepper->clearPulseCounter(); +#endif + + +} + + +void StepperWithLimits::moveSlowlyToPos(int32_t targetPos_ui32) { // reduce speed and accelerartion _stepper->setSpeedInHz(MAXIMUM_STEPPER_SPEED / 4); _stepper->setAcceleration(MAXIMUM_STEPPER_ACCELERATION / 4); // move to min - _stepper->moveTo(_posMin, true); + _stepper->moveTo(targetPos_ui32, true); // increase speed and accelerartion _stepper->setAcceleration(MAXIMUM_STEPPER_ACCELERATION); _stepper->setSpeedInHz(MAXIMUM_STEPPER_SPEED); - - - - -#if defined(SUPPORT_ESP32_PULSE_COUNTER) - _stepper->clearPulseCounter(); -#endif - - } diff --git a/ESP32_master/.pio/libdeps/esp32-speedcrafter/FastAccelStepper/library.properties b/ESP32_master/.pio/libdeps/esp32-speedcrafter/FastAccelStepper/library.properties new file mode 100644 index 00000000..b3787033 --- /dev/null +++ b/ESP32_master/.pio/libdeps/esp32-speedcrafter/FastAccelStepper/library.properties @@ -0,0 +1,12 @@ +name=FastAccelStepper +version=0.30.15 +license=MIT +author=Jochen Kiemes +maintainer=Jochen Kiemes +sentence=A high speed stepper library for Atmega 168/168p/328/328p (nano), 32u4 (leonardo), 2560, ESP32, ESP32S2, ESP32S3, ESP32C3 and Atmel SAM Due +paragraph=Drive stepper motors with acceleration/deceleration profile up to 50 kSteps/s (Atmega) and 200kSteps/s (esp32). +url=https://github.com/gin66/FastAccelStepper +repository=https://github.com/gin66/FastAccelStepper.git +architectures=avr,esp32,sam +category=Device Control +dot_a_linkage=true