Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stepperspeed bugfix #620

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading