Skip to content

Commit

Permalink
Merge pull request #620 from doudar/fix_for_StepperSpeed_Spam
Browse files Browse the repository at this point in the history
stepperspeed bugfix
  • Loading branch information
doudar authored Jan 28, 2025
2 parents 81b5ac2 + 52afe82 commit 35850e6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Hardware


## [25.1.19]

### Added

### Changed
- Bugfix in ERG Mode
- Bugfix for spamming log messages when using Peloton and not homed.

### Hardware


## [25.1.12]

### Added
Expand Down
1 change: 0 additions & 1 deletion include/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions src/ERG_Mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 21 additions & 15 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ void SS2K::maintenanceLoop(void *pvParameters) {
speed = userConfig->getStepperSpeed();
}
}

ss2k->updateStepperSpeed(speed);
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -471,7 +468,7 @@ void SS2K::moveStepper() {
if (rtConfig->cad.getValue() > 1) {
stepper->enableOutputs();
stepper->setAutoEnable(false);
}else{
} else {
stepper->setAutoEnable(true);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -699,14 +713,6 @@ void SS2K::checkDriverTemperature() {
}
}

void SS2K::motorStop(bool releaseTension) {
stepper->stopMove();
stepper->setCurrentPosition(ss2k->targetPosition);
if (releaseTension) {
stepper->moveTo(ss2k->targetPosition - userConfig->getShiftStep() * 4);
}
}

void SS2K::txSerial() { // Serial.printf(" Before TX ");
if (PELOTON_TX && (txCheck >= 1)) {
static int alternate = 0;
Expand Down

0 comments on commit 35850e6

Please sign in to comment.