Skip to content

Commit

Permalink
Merge pull request #380 from doudar/Erg_Fix
Browse files Browse the repository at this point in the history
Simplified CAD compensation in Powertable
  • Loading branch information
doudar authored Oct 7, 2022
2 parents d608dba + 11e931b commit 0446164
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,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.)
- Increased the BLE active scan window.
- BLE scan page now shows previous scan results.
- BLE scan page duplicates bug fixed.
Expand Down
2 changes: 1 addition & 1 deletion src/BLE_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: ";
Expand Down
23 changes: 6 additions & 17 deletions src/ERG_Mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

0 comments on commit 0446164

Please sign in to comment.