From 2d2ce2bcb4af573dc91a759807355980feae6b7d Mon Sep 17 00:00:00 2001 From: benv12 <151891474+benv12@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:54:40 -0600 Subject: [PATCH 1/3] created and set totalTravel --- include/BLE_Custom_Characteristic.h | 1 + include/ERG_Mode.h | 2 ++ include/SmartSpin_parameters.h | 4 ++++ src/BLE_Custom_Characteristic.cpp | 22 ++++++++++++++++++++++ src/Main.cpp | 3 +++ 5 files changed, 32 insertions(+) diff --git a/include/BLE_Custom_Characteristic.h b/include/BLE_Custom_Characteristic.h index ce91a0be..8cacbf1c 100644 --- a/include/BLE_Custom_Characteristic.h +++ b/include/BLE_Custom_Characteristic.h @@ -60,6 +60,7 @@ const uint8_t BLE_simulatedTargetWatts = 0x28; // current target watts const uint8_t BLE_simulateTargetWatts = 0x29; // are we sending target watts const uint8_t BLE_hMin = 0x2A; // Minimum homing value const uint8_t BLE_hMax = 0x2B; // Maximum homing value +const uint8_t BLE_totalTravel = 0x2C; // Total travel class BLE_ss2kCustomCharacteristic { public: diff --git a/include/ERG_Mode.h b/include/ERG_Mode.h index afdba436..4880333a 100644 --- a/include/ERG_Mode.h +++ b/include/ERG_Mode.h @@ -19,6 +19,7 @@ class PowerEntry { public: int watts; + int resistance; int32_t targetPosition; int cad; int readings; @@ -28,6 +29,7 @@ class PowerEntry { this->targetPosition = 0; this->cad = 0; this->readings = 0; + this->resistance = 0; } }; diff --git a/include/SmartSpin_parameters.h b/include/SmartSpin_parameters.h index d4ccd60d..1799c0b2 100644 --- a/include/SmartSpin_parameters.h +++ b/include/SmartSpin_parameters.h @@ -126,6 +126,7 @@ class userParameters { bool udpLogEnabled = false; int32_t hMin = INT32_MIN; int32_t hMax = INT32_MIN; + int32_t totalTravel; bool FTMSControlPointWrite = false; String ssid; @@ -196,6 +197,9 @@ class userParameters { void setShifterDir(bool shd) { shifterDir = shd; } bool getShifterDir() { return shifterDir; } + void setTotalTravel(int tT) { totalTravel = tT; } + bool getTotalTravel() { return totalTravel; } + void setUdpLogEnabled(bool enabled) { udpLogEnabled = enabled; } bool getUdpLogEnabled() { return udpLogEnabled; } diff --git a/src/BLE_Custom_Characteristic.cpp b/src/BLE_Custom_Characteristic.cpp index cce568ea..70baf77d 100644 --- a/src/BLE_Custom_Characteristic.cpp +++ b/src/BLE_Custom_Characteristic.cpp @@ -738,6 +738,22 @@ void BLE_ss2kCustomCharacteristic::process(std::string rxValue) { ss2k->setTargetPosition(int32_t((uint8_t)(rxValue[2]) << 0 | (uint8_t)(rxValue[3]) << 8 | (uint8_t)(rxValue[4]) << 16 | (uint8_t)(rxValue[5]) << 24)); logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, " (%f)", userConfig->getHMax()); } + + case BLE_totalTravel: // 0x2C + logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-totalTravel"); + if (rxValue[0] == cc_read) { + returnValue[0] = cc_success; + returnValue[2] = (uint8_t)(userConfig->getTotalTravel() & 0xff); + returnValue[3] = (uint8_t)(userConfig->getTotalTravel() >> 8); + returnValue[4] = (uint8_t)(userConfig->getTotalTravel() >> 16); + returnValue[5] = (uint8_t)(userConfig->getTotalTravel() >> 24); + returnLength += 4; + } + if (rxValue[0] == cc_write) { + returnValue[0] = cc_success; + ss2k->setTargetPosition(int32_t((uint8_t)(rxValue[2]) << 0 | (uint8_t)(rxValue[3]) << 8 | (uint8_t)(rxValue[4]) << 16 | (uint8_t)(rxValue[5]) << 24)); + logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, " (%f)", userConfig->getTotalTravel()); + } break; } @@ -900,4 +916,10 @@ void BLE_ss2kCustomCharacteristic::parseNemit() { BLE_ss2kCustomCharacteristic::notify(BLE_hMax); return; } + + if(userConfig->getTotalTravel() != _oldParams.getTotalTravel()){ + _oldParams.setTotalTravel(userConfig->getTotalTravel()); + BLE_ss2kCustomCharacteristic::notify(BLE_totalTravel); + return; + } } \ No newline at end of file diff --git a/src/Main.cpp b/src/Main.cpp index 13b2a0ff..dd7675fb 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -584,6 +584,7 @@ void SS2K::goHome(bool bothDirections) { vTaskDelay(2000 / portTICK_PERIOD_MS); rtConfig->setMaxStep(stepper->getCurrentPosition() - 200); SS2K_LOG(MAIN_LOG_TAG, "Max Position found: %d.", rtConfig->getMaxStep()); + rtConfig->setMaxResistance(rtConfig->resistance.getValue()); stepper->enableOutputs(); } stepper->runBackward(); @@ -600,12 +601,14 @@ void SS2K::goHome(bool bothDirections) { stepper->setCurrentPosition((int32_t)0); rtConfig->setMinStep(stepper->getCurrentPosition() + userConfig->getShiftStep()); SS2K_LOG(MAIN_LOG_TAG, "Min Position found: %d.", rtConfig->getMinStep()); + rtConfig->setMinResistance(rtConfig->resistance.getValue()); stepper->enableOutputs(); // Start Saving Settings if (bothDirections) { userConfig->setHMin(rtConfig->getMinStep()); userConfig->setHMax(rtConfig->getMaxStep()); + userConfig->setTotalTravel(userConfig->getHMax() - userConfig->getHMin()); } // In case this was only one direction homing. rtConfig->setMaxStep(userConfig->getHMax()); From 66fd6eecae41915ea7d1177b542ae772688a6349 Mon Sep 17 00:00:00 2001 From: benv12 <151891474+benv12@users.noreply.github.com> Date: Sun, 12 Jan 2025 15:59:24 -0600 Subject: [PATCH 2/3] implemented neighbor weighting for extrapFillTable() function. --- include/SmartSpin_parameters.h | 3 - src/BLE_Custom_Characteristic.cpp | 16 -- src/ERG_Mode.cpp | 254 ++++++++++++++++-------------- src/Main.cpp | 1 - 4 files changed, 136 insertions(+), 138 deletions(-) diff --git a/include/SmartSpin_parameters.h b/include/SmartSpin_parameters.h index 60c30975..befe8d77 100644 --- a/include/SmartSpin_parameters.h +++ b/include/SmartSpin_parameters.h @@ -196,9 +196,6 @@ class userParameters { void setShifterDir(bool shd) { shifterDir = shd; } bool getShifterDir() { return shifterDir; } - void setTotalTravel(int tT) { totalTravel = tT; } - bool getTotalTravel() { return totalTravel; } - void setUdpLogEnabled(bool enabled) { udpLogEnabled = enabled; } bool getUdpLogEnabled() { return udpLogEnabled; } diff --git a/src/BLE_Custom_Characteristic.cpp b/src/BLE_Custom_Characteristic.cpp index 131394aa..69f2a89f 100644 --- a/src/BLE_Custom_Characteristic.cpp +++ b/src/BLE_Custom_Characteristic.cpp @@ -739,22 +739,6 @@ void BLE_ss2kCustomCharacteristic::process(std::string rxValue) { ss2k->setTargetPosition(int32_t((uint8_t)(rxValue[2]) << 0 | (uint8_t)(rxValue[3]) << 8 | (uint8_t)(rxValue[4]) << 16 | (uint8_t)(rxValue[5]) << 24)); logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, " (%f)", userConfig->getHMax()); } - - case BLE_totalTravel: // 0x2C - logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-totalTravel"); - if (rxValue[0] == cc_read) { - returnValue[0] = cc_success; - returnValue[2] = (uint8_t)(userConfig->getTotalTravel() & 0xff); - returnValue[3] = (uint8_t)(userConfig->getTotalTravel() >> 8); - returnValue[4] = (uint8_t)(userConfig->getTotalTravel() >> 16); - returnValue[5] = (uint8_t)(userConfig->getTotalTravel() >> 24); - returnLength += 4; - } - if (rxValue[0] == cc_write) { - returnValue[0] = cc_success; - ss2k->setTargetPosition(int32_t((uint8_t)(rxValue[2]) << 0 | (uint8_t)(rxValue[3]) << 8 | (uint8_t)(rxValue[4]) << 16 | (uint8_t)(rxValue[5]) << 24)); - logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, " (%f)", userConfig->getTotalTravel()); - } break; case BLE_homingSensitivity: // 0x2C diff --git a/src/ERG_Mode.cpp b/src/ERG_Mode.cpp index 51ea2ce9..79c90839 100644 --- a/src/ERG_Mode.cpp +++ b/src/ERG_Mode.cpp @@ -15,6 +15,7 @@ #include #include #include +#include PowerTable* powerTable = new PowerTable; @@ -108,9 +109,9 @@ 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 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) { // Take Initial reading @@ -402,48 +403,80 @@ void PowerTable::fillTable() { // Fill each empty cell by linear interpolation for (int i = 0; i < POWERTABLE_CAD_SIZE; ++i) { - // Interpolate horizontally - for (int j = 0; j < POWERTABLE_WATT_SIZE; ++j) { - if (this->tableRow[i].tableEntry[j].targetPosition == INT16_MIN) { - // Find nearest left and right non-empty cells - int left = j - 1; - while (left >= 0 && this->tableRow[i].tableEntry[left].targetPosition == INT16_MIN) left--; - int right = j + 1; - while (right < POWERTABLE_WATT_SIZE && this->tableRow[i].tableEntry[right].targetPosition == INT16_MIN) right++; + + //create two hash maps for row and col + std::unordered_map> rowMap; + std::unordered_map> colMap; - if (left >= 0 && right < POWERTABLE_WATT_SIZE) { - // Linear interpolation - tempValue = this->tableRow[i].tableEntry[left].targetPosition + - (this->tableRow[i].tableEntry[right].targetPosition - this->tableRow[i].tableEntry[left].targetPosition) * (j - left) / (right - left); - if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { - this->tableRow[i].tableEntry[j].targetPosition = tempValue; - } + //store non-empty values + for (int i = 0; i < POWERTABLE_CAD_SIZE; ++i) { + for (int j = 0; j < POWERTABLE_WATT_SIZE; ++j) { + if (this->tableRow[i].tableEntry[j].targetPosition != INT16_MIN) { + rowMap[i][j] = this->tableRow[i].tableEntry[j].targetPosition; + colMap[j][i] = this->tableRow[i].tableEntry[j].targetPosition; + } + } } - } - } - } - for (int j = 0; j < POWERTABLE_WATT_SIZE; ++j) { - // Interpolate vertically + //horizontal interpolation for (int i = 0; i < POWERTABLE_CAD_SIZE; ++i) { - if (this->tableRow[i].tableEntry[j].targetPosition == INT16_MIN) { - // Find nearest top and bottom non-empty cells - int top = i - 1; - while (top >= 0 && this->tableRow[top].tableEntry[j].targetPosition == INT16_MIN) top--; - int bottom = i + 1; - while (bottom < POWERTABLE_CAD_SIZE && this->tableRow[bottom].tableEntry[j].targetPosition == INT16_MIN) bottom++; + for (int j = 0; j < POWERTABLE_WATT_SIZE; ++j) { + if (this->tableRow[i].tableEntry[j].targetPosition == INT16_MIN) { - if (top >= 0 && bottom < POWERTABLE_CAD_SIZE) { - // Linear interpolation - tempValue = this->tableRow[top].tableEntry[j].targetPosition + - (this->tableRow[bottom].tableEntry[j].targetPosition - this->tableRow[top].tableEntry[j].targetPosition) * (i - top) / (bottom - top); - if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { - this->tableRow[i].tableEntry[j].targetPosition = tempValue; - } + int left = j - 1; + while (left >= 0 && rowMap[i].find(left) == rowMap[i].end()) + left--; + + int right = j + 1; + while (right < POWERTABLE_WATT_SIZE && rowMap[i].find(right) == rowMap[i].end()) + right++; + + if (left >= 0 && right < POWERTABLE_WATT_SIZE) { + + int16_t tempValue = rowMap[i][left] + (rowMap[i][right] - rowMap[i][left]) * (j - left) / (right - left); + + if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { + this->tableRow[i].tableEntry[j].targetPosition = tempValue; + } + } + } + } } - } - } + + //vertical interpolation + for (int j = 0; j < POWERTABLE_WATT_SIZE; ++j) { + for (int i = 0; i < POWERTABLE_CAD_SIZE; ++i) { + if (this->tableRow[i].tableEntry[j].targetPosition == INT16_MIN) { + + int top = i - 1; + while (top >= 0 && colMap[j].find(top) == colMap[j].end()) + top--; + + int bottom = i + 1; + while (bottom < POWERTABLE_CAD_SIZE && colMap[j].find(bottom) == colMap[j].end()) + bottom++; + + if (top >= 0 && bottom < POWERTABLE_CAD_SIZE) { + + int16_t tempValue = colMap[j][top] + (colMap[j][bottom] - colMap[j][top]) * (i - top) / (bottom - top); + + if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { + this->tableRow[i].tableEntry[j].targetPosition = tempValue; + } + } + } + } + } + } +} + +int weightedAverage(int leftValue, int rightValue, int leftWeight, int rightWeight){ + if (leftWeight + rightWeight == 0){ + return INT16_MIN; } + int weightedValue = (leftValue * leftWeight + rightValue * rightWeight) / (leftWeight + rightWeight); + SS2K_LOG(POWERTABLE_LOG_TAG, "Weighted Value: %f", weightedValue); + return (leftValue * leftWeight + rightValue * rightWeight) / (leftWeight + rightWeight); } void PowerTable::extrapFillTable() { @@ -481,37 +514,34 @@ void PowerTable::extrapFillTable() { if (left >= 0 && right < POWERTABLE_WATT_SIZE) { // Linear extrapolation if (this->tableRow[i].tableEntry[left].targetPosition != INT16_MIN && this->tableRow[i].tableEntry[right].targetPosition != INT16_MIN) { - if (j < left) { - // Extrapolate to the left - tempValue = this->tableRow[i].tableEntry[left].targetPosition - - (this->tableRow[i].tableEntry[right].targetPosition - this->tableRow[i].tableEntry[left].targetPosition) / (right - left) * (left - j); - if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { - this->tableRow[i].tableEntry[j].targetPosition = tempValue; - } - } else if (j > right) { - // Extrapolate to the right - tempValue = this->tableRow[i].tableEntry[right].targetPosition + - (this->tableRow[i].tableEntry[right].targetPosition - this->tableRow[i].tableEntry[left].targetPosition) / (right - left) * (j - right); - if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { - this->tableRow[i].tableEntry[j].targetPosition = tempValue; - } + + int leftWeight = (j - left); + int rightWeight = (right - j); + int tempValue = weightedAverage(this->tableRow[i].tableEntry[left].targetPosition, this->tableRow[i].tableEntry[right].targetPosition, leftWeight, rightWeight); + SS2K_LOG(POWERTABLE_LOG_TAG, "Weighted Avg: %f", tempValue) + + if(this->testNeighbors(i, j, tempValue).allNeighborsPassed){ + this->tableRow[i].tableEntry[j].targetPosition = tempValue; } } - } else if (left - 1 >= 0) { + } else if (left>= 0) { // Only left value available, extrapolate to the right - if (this->tableRow[i].tableEntry[left].targetPosition != INT16_MIN && this->tableRow[i].tableEntry[left - 1].targetPosition != INT16_MIN) { - tempValue = this->tableRow[i].tableEntry[left].targetPosition + - (j - left) * (left > 0 ? this->tableRow[i].tableEntry[left].targetPosition - this->tableRow[i].tableEntry[left - 1].targetPosition : 1); + if (this->tableRow[i].tableEntry[left].targetPosition != INT16_MIN) { + int rigthWeight = 1; + int tempValue = this->tableRow[i].tableEntry[left].targetPosition + rigthWeight; + SS2K_LOG(POWERTABLE_LOG_TAG, "Weighted Avg: %f", tempValue) + if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { this->tableRow[i].tableEntry[j].targetPosition = tempValue; } } - } else if (right + 1 < POWERTABLE_WATT_SIZE) { + } else if (right < POWERTABLE_WATT_SIZE) { // Only right value available, extrapolate to the left - if (this->tableRow[i].tableEntry[right + 1].targetPosition != INT16_MIN && this->tableRow[i].tableEntry[right].targetPosition != INT16_MIN) { - tempValue = - this->tableRow[i].tableEntry[right].targetPosition - - (right - j) * (right < POWERTABLE_WATT_SIZE - 1 ? this->tableRow[i].tableEntry[right + 1].targetPosition - this->tableRow[i].tableEntry[right].targetPosition : 1); + if (this->tableRow[i].tableEntry[right].targetPosition != INT16_MIN) { + int leftWeight = 1; + int tempValue = this->tableRow[i].tableEntry[right].targetPosition - leftWeight; + SS2K_LOG(POWERTABLE_LOG_TAG, "Weighted Avg: %f", tempValue) + if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { this->tableRow[i].tableEntry[j].targetPosition = tempValue; } @@ -541,43 +571,39 @@ void PowerTable::extrapFillTable() { // Find nearest right non-empty cell int right = j + 1; while (right < POWERTABLE_WATT_SIZE && this->tableRow[i].tableEntry[right].targetPosition == INT16_MIN) right++; - if (this->tableRow[i].tableEntry[left].targetPosition != INT16_MIN && this->tableRow[i].tableEntry[right].targetPosition != INT16_MIN) { + if (left >= 0 && right < POWERTABLE_WATT_SIZE) { - // Linear extrapolation - if (j < left) { - // Extrapolate to the left - tempValue = this->tableRow[i].tableEntry[left].targetPosition - - (this->tableRow[i].tableEntry[right].targetPosition - this->tableRow[i].tableEntry[left].targetPosition) / (right - left) * (left - j); - if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { - this->tableRow[i].tableEntry[j].targetPosition = tempValue; - } + if (this->tableRow[i].tableEntry[left].targetPosition != INT16_MIN && this->tableRow[i].tableEntry[right].targetPosition != INT16_MIN) { + + int leftWeight = (j - left); + int rightWeight = (right - j); + int tempValue = weightedAverage(this->tableRow[i].tableEntry[left].targetPosition, this->tableRow[i].tableEntry[right].targetPosition, leftWeight, rightWeight); + SS2K_LOG(POWERTABLE_LOG_TAG, "Weighted Avg: %f", tempValue) - } else if (j > right) { - // Extrapolate to the right - tempValue = this->tableRow[i].tableEntry[right].targetPosition + - (this->tableRow[i].tableEntry[right].targetPosition - this->tableRow[i].tableEntry[left].targetPosition) / (right - left) * (j - right); - if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { - this->tableRow[i].tableEntry[j].targetPosition = tempValue; + + if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { + this->tableRow[i].tableEntry[j].targetPosition = tempValue; } } - } else if (left >= 1) { + } else if (left >= 0) { // Only left value available, extrapolate to the right - if (this->tableRow[i].tableEntry[left].targetPosition != INT16_MIN && this->tableRow[i].tableEntry[left - 1].targetPosition != INT16_MIN) { - tempValue = this->tableRow[i].tableEntry[left].targetPosition + - (j - left) * (left > 0 ? this->tableRow[i].tableEntry[left].targetPosition - this->tableRow[i].tableEntry[left - 1].targetPosition : 1); + if (this->tableRow[i].tableEntry[left].targetPosition != INT16_MIN) { + if (this->tableRow[i].tableEntry[left].targetPosition != INT16_MIN){ + int tempValue = this->tableRow[i].tableEntry[left].targetPosition + 1; + SS2K_LOG(POWERTABLE_LOG_TAG, "Weighted Avg: %f", tempValue) if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { this->tableRow[i].tableEntry[j].targetPosition = tempValue; } + } } - } else if (right + 1 < POWERTABLE_WATT_SIZE) { + } else if (right < POWERTABLE_WATT_SIZE) { // Only right value available, extrapolate to the left - if (this->tableRow[i].tableEntry[right].targetPosition != INT16_MIN && this->tableRow[i].tableEntry[right + 1].targetPosition != INT16_MIN) { - tempValue = this->tableRow[i].tableEntry[right].targetPosition - - (right - j) * - (right < POWERTABLE_WATT_SIZE - 1 ? this->tableRow[i].tableEntry[right + 1].targetPosition - this->tableRow[i].tableEntry[right].targetPosition : 1); + if (this->tableRow[i].tableEntry[right].targetPosition != INT16_MIN) { + int tempValue = this->tableRow[i].tableEntry[right].targetPosition - 1; + SS2K_LOG(POWERTABLE_LOG_TAG, "Weighted Avg: %f", tempValue) if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { this->tableRow[i].tableEntry[j].targetPosition = tempValue; - } + } } } @@ -598,41 +624,33 @@ void PowerTable::extrapFillTable() { while (bottom < POWERTABLE_CAD_SIZE && this->tableRow[bottom].tableEntry[j].targetPosition == INT16_MIN) bottom++; if (top >= 0 && bottom < POWERTABLE_CAD_SIZE) { - // Linear extrapolation - if (i < top) { - // Extrapolate upwards - tempValue = this->tableRow[top].tableEntry[j].targetPosition - - (this->tableRow[bottom].tableEntry[j].targetPosition - this->tableRow[top].tableEntry[j].targetPosition) / (bottom - top) * (top - i); - if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { - this->tableRow[i].tableEntry[j].targetPosition = tempValue; - } - } else if (i > bottom) { - // Extrapolate downwards - tempValue = this->tableRow[bottom].tableEntry[j].targetPosition + - (this->tableRow[bottom].tableEntry[j].targetPosition - this->tableRow[top].tableEntry[j].targetPosition) / (bottom - top) * (i - bottom); - if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { - this->tableRow[i].tableEntry[j].targetPosition = tempValue; - } + + if (this->tableRow[top].tableEntry[j].targetPosition != INT16_MIN && this->tableRow[bottom].tableEntry[j].targetPosition != INT16_MIN) { + int topWeight = (i - top); + int bottomWeight = (bottom - i); + int tempValue = weightedAverage(this->tableRow[top].tableEntry[j].targetPosition, this->tableRow[bottom].tableEntry[j].targetPosition, topWeight, bottomWeight); + SS2K_LOG(POWERTABLE_LOG_TAG, "Weighted Avg: %f", tempValue) + if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { + this->tableRow[i].tableEntry[j].targetPosition = tempValue; } - } else if (top >= 1) { - // Only top value available, extrapolate downwards - if (this->tableRow[top].tableEntry[j].targetPosition != INT16_MIN && this->tableRow[top - 1].tableEntry[j].targetPosition != INT16_MIN) { - tempValue = this->tableRow[top].tableEntry[j].targetPosition + - (i - top) * (top > 0 ? this->tableRow[top].tableEntry[j].targetPosition - this->tableRow[top - 1].tableEntry[j].targetPosition : 1); - if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { - this->tableRow[i].tableEntry[j].targetPosition = tempValue; - } else { - } + } + + } else if (top >= 0) { + if (this->tableRow[top].tableEntry[j].targetPosition != INT16_MIN) { + int tempValue = this->tableRow[top].tableEntry[j].targetPosition + 1; + SS2K_LOG(POWERTABLE_LOG_TAG, "Weighted Avg: %f", tempValue) + if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { + this->tableRow[i].tableEntry[j].targetPosition = tempValue; } - } else if (bottom + 1 < POWERTABLE_CAD_SIZE) { - // Only bottom value available, extrapolate upwards - if (this->tableRow[bottom].tableEntry[j].targetPosition != INT16_MIN && this->tableRow[bottom + 1].tableEntry[j].targetPosition != INT16_MIN) { - tempValue = this->tableRow[bottom].tableEntry[j].targetPosition - - (bottom - i) * - (bottom < POWERTABLE_CAD_SIZE - 1 ? this->tableRow[bottom + 1].tableEntry[j].targetPosition - this->tableRow[bottom].tableEntry[j].targetPosition : 1); - if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { - this->tableRow[i].tableEntry[j].targetPosition = tempValue; - } + } + + } else if (bottom < POWERTABLE_CAD_SIZE) { + if (this->tableRow[bottom].tableEntry[j].targetPosition != INT16_MIN) { + int tempValue = this->tableRow[bottom].tableEntry[j].targetPosition - 1; + SS2K_LOG(POWERTABLE_LOG_TAG, "Weighted Avg: %f", tempValue) + if (this->testNeighbors(i, j, tempValue).allNeighborsPassed) { + this->tableRow[i].tableEntry[j].targetPosition = tempValue; + } } } } diff --git a/src/Main.cpp b/src/Main.cpp index a25de80b..b495a40b 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -647,7 +647,6 @@ void SS2K::goHome(bool bothDirections) { if (bothDirections) { userConfig->setHMin(rtConfig->getMinStep()); userConfig->setHMax(rtConfig->getMaxStep()); - userConfig->setTotalTravel(userConfig->getHMax() - userConfig->getHMin()); } // In case this was only one direction homing. rtConfig->setMaxStep(userConfig->getHMax()); From db82a4d7aa5fe609fd92d2ffb3ace652c4214b11 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 12 Jan 2025 22:04:06 +0000 Subject: [PATCH 3/3] Update changelog for version 24.12.17 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 080ec42d..e2f7a81e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Hardware +## [24.12.17] + +### Added + +### Changed + +### Hardware + + ## [24.12.7] ### Added