Skip to content

Commit 0fe240d

Browse files
committed
Fix ERG mode logic and improve power table validation; reset target incline on stop
1 parent e6ce99d commit 0fe240d

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Adjusted FTMS resistance handling: ignore malformed IC Bike ranges, log raw range data, and skip IC Bike resistance samples.
1818
- Rounded cadence/power calculations across CSC, CyclePower, Peloton, FTMS decoding; clamp invalid cadence values.
1919
- Applied rounding for FTMS shift targets/resistance mapping and homing thresholds; use fabs in resistance model and paused duplicate cleanup.
20+
- Fixed ERG mode logic to use correct watt increment and PID window for target calculation.
21+
- Improved power table result validation during ERG mode transitions.
22+
- Reset target incline to 1.0 when spinning stops in ERG mode.
2023

2124
### Hardware
2225

@@ -959,4 +962,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
959962
- Holding both shifters for 3 seconds after boot preforms a BLE device scan/reconnect.
960963

961964
- Bugfixes:
962-
- Automatic Updates setting switch now works :)
965+
- Automatic Updates setting switch now works :

dependencies.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ direct_dependencies:
9696
- espressif/network_provisioning
9797
- idf
9898
- joltwallet/littlefs
99-
manifest_hash: e7ce7a886dfdb3cc5cd59acbdb4ff333c0a91c6e4de55b9fd6323d866c7cc691
99+
manifest_hash: df9baa925ebc2a028ee0e349be53f2169bb7ac38b2cb9c63b3ebf69123c43ef8
100100
target: esp32
101101
version: 2.0.0

src/ERG_Mode.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ void ErgMode::computeErg() {
165165
rtConfig->watts.setTarget(userConfig->getMinWatts());
166166
}
167167

168-
// check for new torque value or new set point, if watts < 0 treat as faulty
168+
// check for new watt value or new set point, if watts < 0 treat as faulty
169169
if ((this->prevWatts.getTimestamp() == rtConfig->watts.getTimestamp() && this->prevWatts.getTarget() == rtConfig->watts.getTarget()) || rtConfig->watts.getValue() < 0) {
170170
SS2K_LOG(ERG_MODE_LOG_TAG, "Watts previously processed.");
171171
return;
172172
}
173173

174174
#ifdef ERG_MODE_USE_POWER_TABLE
175-
if (abs(this->prevWatts.getTarget() - rtConfig->watts.getTarget()) > POWERTABLE_CAD_INCREMENT && rtConfig->getHomed()) {
175+
if (abs(this->prevWatts.getTarget() - rtConfig->watts.getTarget()) > POWERTABLE_WATT_INCREMENT && rtConfig->getHomed()) {
176176
result = _setPointChangeState();
177177
}
178178
#endif
@@ -188,7 +188,7 @@ void ErgMode::computeErg() {
188188
int32_t ErgMode::_setPointChangeState() {
189189
mode = (rtConfig->watts.getTarget() > rtConfig->watts.getValue()) ? Mode::INCREASING : Mode::DECREASING;
190190
// It's better to undershoot increasing watts and overshoot decreasing watts, so lets set the lookup target to the nearest side of POWERTABLE_WATT_INCREMENT
191-
int adjustedWattTarget = (mode == Mode::INCREASING) ? rtConfig->watts.getTarget() - POWERTABLE_WATT_INCREMENT : rtConfig->watts.getTarget() + POWERTABLE_WATT_INCREMENT;
191+
int adjustedWattTarget = (mode == Mode::INCREASING) ? rtConfig->watts.getTarget() - ERG_MODE_PID_WINDOW : rtConfig->watts.getTarget() + ERG_MODE_PID_WINDOW;
192192
int32_t tableResult = powerTable->lookup(adjustedWattTarget,
193193
(mode == Mode::INCREASING) ? rtConfig->cad.getValue() + POWERTABLE_CAD_INCREMENT : rtConfig->cad.getValue() - POWERTABLE_CAD_INCREMENT);
194194

@@ -200,11 +200,11 @@ int32_t ErgMode::_setPointChangeState() {
200200

201201
// Test current watts against the table result. If We're already lower or higher than target, flag the result as a return error.
202202
if (tableResult != RETURN_ERROR) {
203-
if (adjustedWattTarget > rtConfig->watts.getValue() && tableResult < ss2k->getCurrentPosition()) {
203+
if (mode == Mode::INCREASING && tableResult < ss2k->getCurrentPosition()) {
204204
SS2K_LOG(ERG_MODE_LOG_TAG, "Table Result Failed increasing Test: %d", tableResult);
205205
tableResult = RETURN_ERROR;
206206
}
207-
if ((adjustedWattTarget < rtConfig->watts.getValue()) && tableResult > ss2k->getCurrentPosition()) {
207+
if (mode == Mode::DECREASING && tableResult > ss2k->getCurrentPosition()) {
208208
SS2K_LOG(ERG_MODE_LOG_TAG, "Table Result Failed decreasing Test: %d", tableResult);
209209
tableResult = RETURN_ERROR;
210210
}
@@ -303,6 +303,7 @@ void ErgMode::_updateValues(float newIncline) {
303303
bool ErgMode::_userIsSpinning(int cadence, float incline) {
304304
if (cadence <= MIN_ERG_CADENCE) {
305305
rtConfig->setFTMSMode(FitnessMachineControlPointProcedure::SetIndoorBikeSimulationParameters);
306+
rtConfig->setTargetIncline(1.0f);
306307
return false; // Cadence too low, nothing to do here
307308
}
308309
this->engineStopped = false;

0 commit comments

Comments
 (0)