From dcae9763729063f9ebf06c75b406c3c3037133a8 Mon Sep 17 00:00:00 2001 From: doudar Date: Tue, 4 Oct 2022 22:28:02 -0500 Subject: [PATCH] Simplified CAD compensation in Powertable --- CHANGELOG.md | 4 +++- src/BLE_Server.cpp | 2 +- src/ERG_Mode.cpp | 23 ++++++----------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df16746b..00eaee9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,8 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed HR in the hidden btsimulator.html - Enabled CORS for doudar/StreamFit. - Re-arranged index.html. -- restored link to bluetooth scanner +- restored link to bluetooth scanner. - Reverted conditional variable initialization in powertable lookup function. +- Simplified cadence compensation in powertable lookup. +- Fixed issue where you couldn't set a ERG target less than 50W (MIN_WATTS wasn't being respected.) ### Hardware - Ultra Short Direct Mount case for use on bikes with limited space between knob and head tube diff --git a/src/BLE_Server.cpp b/src/BLE_Server.cpp index 0a9a01b5..e901d7e0 100644 --- a/src/BLE_Server.cpp +++ b/src/BLE_Server.cpp @@ -318,7 +318,7 @@ void MyServerCallbacks::onDisconnect(BLEServer *pServer) { void MyCallbacks::onWrite(BLECharacteristic *pCharacteristic) { FTMSWrite = pCharacteristic->getValue(); } void MyCallbacks::onSubscribe(NimBLECharacteristic *pCharacteristic, ble_gap_conn_desc *desc, uint16_t subValue) { - String str = "Client ID: "; + String str = "Client ID: "; NimBLEUUID pUUID = pCharacteristic->getUUID(); str += desc->conn_handle; str += " Address: "; diff --git a/src/ERG_Mode.cpp b/src/ERG_Mode.cpp index a828cfed..bc911bc6 100644 --- a/src/ERG_Mode.cpp +++ b/src/ERG_Mode.cpp @@ -279,20 +279,9 @@ int32_t PowerTable::lookup(int watts, int cad) { return (RETURN_ERROR); } - // @MarkusSchneider's data shows a linear relationship between CAD and Watts for a given resistance level. - // It looks like for every 20 CAD increase there is ~50w increase in power. This may need to be adjusted later - // as higher resistance levels have a steeper slope (bigger increase in power/cad) than low resistance levels. + // Cadence Adjustment float averageCAD = (below.cad + above.cad) / 2; - float deltaCAD = abs(averageCAD - cad); - - if (deltaCAD > 5) { - if (cad > averageCAD) { // cad is higher than the table so we need to target a lower wattage (and targetPosition) - watts -= (deltaCAD / 20) * 50; - } - if (cad < averageCAD) { // cad is lower than the table so we need to target a higher wattage (and targetPosition) - watts += (deltaCAD / 20) * 50; - } - } + watts = ((watts * 2) * (averageCAD / (cad + 1)) / 2); // actual interpolation int32_t rTargetPosition = below.targetPosition + ((watts - below.power) / (above.power - below.power)) * (above.targetPosition - below.targetPosition); @@ -355,10 +344,10 @@ void ErgMode::computErg() { return; } - // set minimum SetPoint to 50 watt if trainer sends setpoints lower than 50 watt. - if (newSetPoint < 50) { + // set minimum SetPoint to MIN_WATTS if app sends setpoints lower than MIN_WATTS. + if (newSetPoint < MIN_WATTS) { SS2K_LOG(ERG_MODE_LOG_TAG, "ERG Target Below Minumum Value."); - newSetPoint = 50; + newSetPoint = MIN_WATTS; } bool isUserSpinning = this->_userIsSpinning(newCadence, currentIncline); @@ -394,7 +383,7 @@ void ErgMode::_setPointChangeState(int newSetPoint, int newCadence, Measurement& int i = 0; while (rtConfig.getTargetIncline() != rtConfig.getCurrentIncline()) { // wait while the knob moves to target position. vTaskDelay(100 / portTICK_PERIOD_MS); - if (i > 50) { // failsafe for infinate loop + if (i > 50) { // failsafe for infinite loop SS2K_LOG(ERG_MODE_LOG_TAG, "Stepper didn't reach target position"); break; }