diff --git a/CHANGELOG.md b/CHANGELOG.md index af3ce930..78d5ff03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- Added blocking for shifts above or below min/max setpoints. +- Added blocking for shifts above or below min/max set points. ### Changed - PowerTable values are now adjusted to 90 RPM cad on input. - PowerTable entries are now validated against previous entries. -- changes to default settings for better rideability. raised incline multiplier and erg sensitivity, increased incline multiplier and max brake watts. +- Changes to default settings for better ride-ability. raised incline multiplier and erg sensitivity, increased incline multiplier and max brake watts. +- Fixed a bug in the new cadence compensation where an int should have been a float. ### Hardware diff --git a/include/ERG_Mode.h b/include/ERG_Mode.h index 5492710f..1e691e4c 100644 --- a/include/ERG_Mode.h +++ b/include/ERG_Mode.h @@ -69,7 +69,7 @@ class PowerTable { private: // Adjust Watts For Cadence - int _adjustWattsForCadence(int watts, int cad); + int _adjustWattsForCadence(int watts, float cad); }; class ErgMode { diff --git a/src/ERG_Mode.cpp b/src/ERG_Mode.cpp index def2531a..5d04751a 100644 --- a/src/ERG_Mode.cpp +++ b/src/ERG_Mode.cpp @@ -30,7 +30,7 @@ void setupERG() { } void ergTaskLoop(void* pvParameters) { - ErgMode ergMode = ErgMode(&powerTable); + ErgMode ergMode = ErgMode(&powerTable); PowerBuffer powerBuffer; ergMode._writeLogHeader(); @@ -143,7 +143,7 @@ void PowerTable::setStepperMinMax() { // Accepts new data into the table and averages input by number of readings in the power entry. void PowerTable::newEntry(PowerBuffer& powerBuffer) { - int watts = 0; + float watts = 0; int cad = 0; int32_t targetPosition = 0; @@ -165,9 +165,9 @@ void PowerTable::newEntry(PowerBuffer& powerBuffer) { } // calculate average - watts = (watts + powerBuffer.powerEntry[i].watts) / 2; - targetPosition = (targetPosition + powerBuffer.powerEntry[i].targetPosition) / 2; - cad = (cad + powerBuffer.powerEntry[i].cad) / 2; + watts = (watts + powerBuffer.powerEntry[i].watts) / 2.0; + targetPosition = (targetPosition + powerBuffer.powerEntry[i].targetPosition) / 2.0; + cad = (cad + powerBuffer.powerEntry[i].cad) / 2.0; } // Done with powerBuffer @@ -199,9 +199,9 @@ void PowerTable::newEntry(PowerBuffer& powerBuffer) { this->powerEntry[i].targetPosition = targetPosition; this->powerEntry[i].readings = 1; } else { // Average and update the readings. - this->powerEntry[i].watts = (watts + (this->powerEntry[i].watts * this->powerEntry[i].readings)) / (this->powerEntry[i].readings + 1); - this->powerEntry[i].cad = (cad + (this->powerEntry[i].cad * this->powerEntry[i].readings)) / (this->powerEntry[i].readings + 1); - this->powerEntry[i].targetPosition = (targetPosition + (this->powerEntry[i].targetPosition * this->powerEntry[i].readings)) / (this->powerEntry[i].readings + 1); + this->powerEntry[i].watts = (watts + (this->powerEntry[i].watts * this->powerEntry[i].readings)) / (this->powerEntry[i].readings + 1.0); + this->powerEntry[i].cad = (cad + (this->powerEntry[i].cad * this->powerEntry[i].readings)) / (this->powerEntry[i].readings + 1.0); + this->powerEntry[i].targetPosition = (targetPosition + (this->powerEntry[i].targetPosition * this->powerEntry[i].readings)) / (this->powerEntry[i].readings + 1.0); this->powerEntry[i].readings++; if (this->powerEntry[i].readings > 10) { this->powerEntry[i].readings = 10; // keep from diluting recent readings too far. @@ -322,9 +322,9 @@ int32_t PowerTable::lookup(int watts, int cad) { return rTargetPosition; } -int PowerTable::_adjustWattsForCadence(int watts, int cad) { +int PowerTable::_adjustWattsForCadence(int watts, float cad) { if (cad > 0) { - watts = (watts * (NORMAL_CAD / cad)); + watts = (watts * (((NORMAL_CAD / cad)+1)/2)); return watts; } else { return 0;