Skip to content

Rewrote how processPowerValue got their readings for the power table. #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2d2ce2b
created and set totalTravel
benv12 Nov 5, 2024
fb6c02d
Merge pull request #2 from doudar/develop
benv12 Nov 19, 2024
6c13624
Merge branch 'develop' of https://github.com/benv12/SmartSpin2k into …
benv12 Dec 17, 2024
ac3c6fb
caught up date with develop
benv12 Dec 19, 2024
66fd6ee
implemented neighbor weighting for extrapFillTable() function.
benv12 Jan 12, 2025
db82a4d
Update changelog for version 24.12.17
actions-user Jan 12, 2025
61c7654
Merge pull request #3 from benv12/ERG-mode-rewrite
benv12 Jan 12, 2025
a0acc00
implemented neighbor testing on diag extrapolation
benv12 Jan 13, 2025
e3cfb5d
Merge branch 'develop' of https://github.com/benv12/SmartSpin2k into …
benv12 Jan 13, 2025
4f55587
up to date with doudar develop
benv12 Jan 13, 2025
8173162
Merge branch 'develop' of https://github.com/benv12/SmartSpin2k into …
benv12 Jan 13, 2025
30f088c
Merge branch 'develop' of https://github.com/benv12/SmartSpin2k into …
benv12 Jan 13, 2025
f363e58
Merge branch 'ERG-mode-rewrite' of https://github.com/benv12/SmartSpi…
benv12 Jan 13, 2025
64a8da1
added calculation when homed
benv12 Jan 16, 2025
5b0326d
cleaned up code (still need to solve non-homing problem)
benv12 Jan 20, 2025
0f0f240
testing for setstepperMinMax
benv12 Jan 21, 2025
1127f21
uncommented out situations where peleton was detected
benv12 Jan 21, 2025
cf30bcb
Merge branch 'develop' of https://github.com/benv12/SmartSpin2k into …
benv12 Jan 21, 2025
339e202
Merge branch 'develop' of https://github.com/benv12/SmartSpin2k into …
benv12 Jan 21, 2025
d3f8b3c
forgot to uncomment out fill functions for powertable
benv12 Jan 21, 2025
3195d73
Merge branch 'develop' into pr/618
doudar Jan 30, 2025
ee82c8a
bumped Power table version to version 6
doudar Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/ERG_Mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class PowerEntry {
public:
int watts;
int resistance;
int32_t targetPosition;
int cad;
int readings;
Expand All @@ -28,6 +29,7 @@ class PowerEntry {
this->targetPosition = 0;
this->cad = 0;
this->readings = 0;
this->resistance = 0;
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ const char* const DEFAULT_PASSWORD = "password";
#define RUNTIMECONFIG_JSON_SIZE 1000 + DEBUG_LOG_BUFFER_SIZE

// PowerTable Version
#define TABLE_VERSION 5
#define TABLE_VERSION 6

/* Number of entries in the ERG Power Lookup Table
This is currently maintained as to keep memory usage lower and reduce the print output of the table.
Expand Down
29 changes: 21 additions & 8 deletions src/ERG_Mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <cmath>
#include <limits>
#include <numeric>
#include <unordered_map>

PowerTable* powerTable = new PowerTable;

Expand Down Expand Up @@ -108,18 +109,30 @@ int PowerBuffer::getReadings() {
return ret;
}

void PowerTable::processPowerValue(PowerBuffer& powerBuffer, int cadence, Measurement watts) {
void PowerTable::processPowerValue(PowerBuffer& powerBuffer, int cadence, Measurement watts) { //this basically checks the constaraints and if everything is good it adds it into the powerbuffer. no need to change
static int calcStep; //calcStep is the percentage range of the stepper motor

if ((cadence >= (MINIMUM_TABLE_CAD - (POWERTABLE_CAD_INCREMENT / 2))) &&
(cadence <= (MINIMUM_TABLE_CAD + (POWERTABLE_CAD_INCREMENT * POWERTABLE_CAD_SIZE) - (POWERTABLE_CAD_SIZE / 2))) && (watts.getValue() > 10) &&
(cadence <= (MINIMUM_TABLE_CAD + (POWERTABLE_CAD_INCREMENT * POWERTABLE_CAD_SIZE) - (POWERTABLE_CAD_SIZE / 2))) && (watts.getValue() > 10) && //adding constraints
(watts.getValue() < (POWERTABLE_WATT_SIZE * POWERTABLE_WATT_INCREMENT))) {
if (powerBuffer.powerEntry[0].readings == 0) {

if(rtConfig->getMaxStep() == DEFAULT_STEPPER_TRAVEL && rtConfig->getMinStep() == -DEFAULT_STEPPER_TRAVEL){
int totalStep = ((rtConfig->getMaxStep() - rtConfig->getMaxStep() / 2000000)); //stepper distance is 400,000,000 so dividing it by 2,000,000 gives us 200
calcStep = totalStep * 0.05; // 5% of that would give us around a 10 positive and negative range
} else if (rtConfig->getHomed()){
int totalStep = (rtConfig->getMaxStep() / 100); //maxStep should be around 22000 / 100 gives us 200ish
calcStep = totalStep * 0.05; // 5% of that would give us around a 10 positive and negative range
}

if (powerBuffer.powerEntry[0].readings == 0) { //we need to make sure stepper position is not negative so it only takes positive resistance values
// Take Initial reading
powerBuffer.set(0);
// Check that reading is within 1/2 of the initial reading
} else if ((abs(powerBuffer.powerEntry[0].watts - watts.getValue()) < (POWERTABLE_WATT_INCREMENT / 2)) &&
(abs(powerBuffer.powerEntry[0].cad - cadence) < (POWERTABLE_CAD_INCREMENT))) {
// Check if the current stepper posistion is within a 5% range of the previous stepper position and that the current position is not negative
} if (((ss2k->getCurrentPosition()/100) >= ((powerBuffer.powerEntry[0].targetPosition) - calcStep)) &&
((ss2k->getCurrentPosition()/100) <= ((powerBuffer.powerEntry[0].targetPosition) + calcStep))) {
for (int i = 1; i < POWER_SAMPLES; i++) {
if (powerBuffer.powerEntry[i].readings == 0) {
SS2K_LOG(POWERTABLE_LOG_TAG, "Success!");
powerBuffer.set(i); // Add additional readings to the buffer.
break;
}
Expand All @@ -129,8 +142,8 @@ void PowerTable::processPowerValue(PowerBuffer& powerBuffer, int cadence, Measur
this->toLog();
this->_manageSaveState();
powerBuffer.reset();
}
} else { // Reading was outside the range - clear the buffer and start over.
}
} else { // Reading was outside the range - clear the buffer and start over.
powerBuffer.reset();
}
}
Expand Down
Loading