From 500581535b7224da89f768cdc9c09df84445ae77 Mon Sep 17 00:00:00 2001 From: Anthony Doud Date: Sun, 26 Jan 2025 09:04:38 -0600 Subject: [PATCH 1/3] stepperspeed bugfix --- CHANGELOG.md | 2 ++ src/Main.cpp | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 582458ac..7d5a4237 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed +- Bugfix in ERG Mode +- Bugfix for spamming log messages when using Peloton and not homed. ### Hardware diff --git a/src/Main.cpp b/src/Main.cpp index b495a40b..4b5b9c30 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -224,7 +224,6 @@ void SS2K::maintenanceLoop(void *pvParameters) { speed = userConfig->getStepperSpeed(); } } - ss2k->updateStepperSpeed(speed); } @@ -263,10 +262,8 @@ void SS2K::maintenanceLoop(void *pvParameters) { userPWC->saveToLittleFS(); } - // Things to do every two seconds - if ((millis() - intervalTimer) > 2003) { // add check here for when to restart WiFi - // maybe if in STA mode and 8.8.8.8 no ping return? - // ss2k->restartWifi(); + // Things to do every one seconds + if ((millis() - intervalTimer) > 1003) { logHandler.writeLogs(); webSocketAppender.Loop(); intervalTimer = millis(); @@ -471,7 +468,7 @@ void SS2K::moveStepper() { if (rtConfig->cad.getValue() > 1) { stepper->enableOutputs(); stepper->setAutoEnable(false); - }else{ + } else { stepper->setAutoEnable(true); } @@ -674,11 +671,28 @@ void SS2K::updateStealthChop() { } // Applies userconfig stepper speed if speed not specified +/** + * @brief Updates the speed of the stepper motor. + * + * This function updates the speed of the stepper motor to the specified value. + * If the provided speed is 0, it retrieves the speed from the user configuration. + * The function also includes a tolerance check to avoid unnecessary updates if + * the current speed is within 5 units of the target speed. + * + * @param speed The desired speed for the stepper motor. If 0, the speed is retrieved from user configuration. + */ void SS2K::updateStepperSpeed(int speed) { if (speed == 0) { speed = userConfig->getStepperSpeed(); } - SS2K_LOG(MAIN_LOG_TAG, "StepperSpeed is now %d", speed); + int s = stepper->getSpeedInMilliHz() / 1000; + //Because the conversion to/from the TMC driver is not perfect, we need to allow a little bit of slop. + //Skip the update if the speed is within 5 of the target. + if (abs(s-speed) < 5) { + return; + } + speed = speed; + //SS2K_LOG(MAIN_LOG_TAG, "StepperSpeed is now %d, %d", speed, s); stepper->setSpeedInHz(speed); } @@ -699,11 +713,20 @@ void SS2K::checkDriverTemperature() { } } +/** + * @brief Stops the motor and optionally releases tension. + * + * This function stops the motor by calling the stopMove() method on the stepper object. + * It then sets the current position of the stepper to the target position stored in ss2k. + * If the releaseTension parameter is true, the function moves the stepper to a position + * that releases tension by subtracting a calculated shift step from the target position. + * + * @param releaseTension A boolean flag indicating whether to release tension after stopping the motor. + */ void SS2K::motorStop(bool releaseTension) { stepper->stopMove(); - stepper->setCurrentPosition(ss2k->targetPosition); if (releaseTension) { - stepper->moveTo(ss2k->targetPosition - userConfig->getShiftStep() * 4); + rtConfig->setTargetIncline(ss2k->getCurrentPosition() - userConfig->getShiftStep()); } } From 0faab20f350751d69423fb7df6d790e8534c9d7b Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 26 Jan 2025 15:06:42 +0000 Subject: [PATCH 2/3] Update changelog for version 25.1.19 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d5a4237..df33a246 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +### Changed + +### Hardware + + +## [25.1.19] + +### Added + ### Changed - Bugfix in ERG Mode - Bugfix for spamming log messages when using Peloton and not homed. From 52afe82804cb7be9610920acc62580a22103ebf7 Mon Sep 17 00:00:00 2001 From: Anthony Doud Date: Sun, 26 Jan 2025 09:16:50 -0600 Subject: [PATCH 3/3] removed motorStop() method --- include/Main.h | 1 - src/ERG_Mode.cpp | 5 ++--- src/Main.cpp | 17 ----------------- 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/include/Main.h b/include/Main.h index 54805573..1d8ce3b5 100644 --- a/include/Main.h +++ b/include/Main.h @@ -65,7 +65,6 @@ class SS2K { void updateStealthChop(); void updateStepperSpeed(int speed = 0); void checkDriverTemperature(); - void motorStop(bool releaseTension = false); void FTMSModeShiftModifier(); static void rxSerial(void); void txSerial(); diff --git a/src/ERG_Mode.cpp b/src/ERG_Mode.cpp index 51ea2ce9..7b7f3a34 100644 --- a/src/ERG_Mode.cpp +++ b/src/ERG_Mode.cpp @@ -1204,9 +1204,8 @@ void ErgMode::_updateValues(int newCadence, Measurement& newWatts, float newIncl bool ErgMode::_userIsSpinning(int cadence, float incline) { if (cadence <= MIN_ERG_CADENCE) { - if (!this->engineStopped) { // Test so motor stop command only happens once. - ss2k->motorStop(); // release tension - rtConfig->setTargetIncline(incline - WATTS_PER_SHIFT); // release incline + if (!this->engineStopped) { // Test so motor stop command only happens once. // release tension + rtConfig->setTargetIncline(0); // release incline this->engineStopped = true; } return false; // Cadence too low, nothing to do here diff --git a/src/Main.cpp b/src/Main.cpp index 4b5b9c30..c54344f2 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -713,23 +713,6 @@ void SS2K::checkDriverTemperature() { } } -/** - * @brief Stops the motor and optionally releases tension. - * - * This function stops the motor by calling the stopMove() method on the stepper object. - * It then sets the current position of the stepper to the target position stored in ss2k. - * If the releaseTension parameter is true, the function moves the stepper to a position - * that releases tension by subtracting a calculated shift step from the target position. - * - * @param releaseTension A boolean flag indicating whether to release tension after stopping the motor. - */ -void SS2K::motorStop(bool releaseTension) { - stepper->stopMove(); - if (releaseTension) { - rtConfig->setTargetIncline(ss2k->getCurrentPosition() - userConfig->getShiftStep()); - } -} - void SS2K::txSerial() { // Serial.printf(" Before TX "); if (PELOTON_TX && (txCheck >= 1)) { static int alternate = 0;