Skip to content

Commit

Permalink
Merge pull request #391 from doudar/Min_Max_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
doudar authored Oct 25, 2022
2 parents 5ad002c + 05ee158 commit af0581a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion include/ERG_Mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions src/ERG_Mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void setupERG() {
}

void ergTaskLoop(void* pvParameters) {
ErgMode ergMode = ErgMode(&powerTable);
ErgMode ergMode = ErgMode(&powerTable);
PowerBuffer powerBuffer;

ergMode._writeLogHeader();
Expand Down Expand Up @@ -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;

Expand All @@ -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

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

0 comments on commit af0581a

Please sign in to comment.