Skip to content

Commit 77e0dd9

Browse files
committed
Tried alt. load config + algo
1 parent a7284f1 commit 77e0dd9

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

include/LoadConfig.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ namespace RUN {
9999
TI_FSM_mS = 50, // CONFIG - 50 ms (20 Hz)
100100
TI_POLL_SENSORS_mS = 3, // CONFIG - 3 ms (333 Hz), stopped likeing 2 ms
101101
// (100 Hz) around commit 9d80f8b
102-
TI_ADJUST_LOAD_mS = 1000, // CONFIG - 1000 ms (1 Hz)
102+
TI_ADJUST_LOAD_mS = 3000, // CONFIG - 1000 ms (1 Hz)
103103
TI_RECV_ms = 50, // CONFIG - 100 ms (10 Hz)
104104
TI_SEND_ms = 75, // CONFIG - 75 ms (13.33 Hz) // FIXME
105105
TI_CFG_ms = 1000, // CONFIG - 1000 ms (1 Hz)

src/main.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
439439
// i)); // todo - just a quick performances test
440440
// i += 20;
441441
// static int_fast32_t lastPower = INT_FAST32_MIN;
442-
constexpr uint32_t powerHistoryLength_s = 5;
442+
constexpr uint32_t powerHistoryLength_s = 3 * 3;
443443
constexpr uint32_t powerHistoryLength =
444-
powerHistoryLength_s *
445-
(UNITS::MILLIS_PER_SEC / RUN::TASK_INTERVALS::TI_ADJUST_LOAD_mS);
444+
powerHistoryLength_s * UNITS::MILLIS_PER_SEC /
445+
RUN::TASK_INTERVALS::TI_ADJUST_LOAD_mS;
446446
static etl::circular_buffer<int_fast32_t, powerHistoryLength>
447447
powerHistory;
448448
// static int_fast8_t powerIndex = powerHistory.size() - 1;
@@ -484,9 +484,10 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
484484
static_cast<int>(powerHistory.back()),
485485
static_cast<int>(INA260::power_mW));
486486
// Don't do anything until one reading has been made
487-
} else if ((powerHistory.size() == 1) && (powerIndex > 0)) {
487+
} else if ((powerHistory.size() == 1) && (powerIndex > 1)) {
488488
// Make initial adjustment when one value filled
489-
powerIndex--;
489+
// powerIndex--;
490+
powerIndex -= 2;
490491
load.setLoadGPIO(LOAD::RES_INDEX_TABLE[powerIndex]);
491492
adjustmentHistory.push(LoadAdjustment::DECREASE);
492493
ESP_LOGD(TAG, "Last power: %d mW, current power: %d mW",
@@ -496,9 +497,10 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
496497
LOAD::RES_INDEX_TABLE[powerIndex]);
497498
} else if ((adjustmentHistory[0] != LoadAdjustment::DECREASE) &&
498499
(INA260::power_mW > powerHistory.back()) &&
499-
(powerIndex > 0)) {
500+
(powerIndex > 1)) {
500501
// Decreasing + got better -> decrease again
501-
powerIndex--;
502+
// powerIndex--;
503+
powerIndex -= 2;
502504
load.setLoadGPIO(LOAD::RES_INDEX_TABLE[powerIndex]);
503505
adjustmentHistory.push(LoadAdjustment::DECREASE);
504506
ESP_LOGD(TAG, "Last power: %d mW, current power: %d mW",
@@ -507,10 +509,13 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
507509
ESP_LOGI(TAG, "1Decreasing load to %d",
508510
LOAD::RES_INDEX_TABLE[powerIndex]); // TODO: Try by twos
509511
} else if ((adjustmentHistory[0] != LoadAdjustment::INCREASE) &&
512+
(INA260::power_mW > powerHistory.back()) &&
510513
(powerIndex <
511514
LOAD::RES_INDEX_TABLE.size() - 1)) { // MARK: BOLD LOAD
512515
// increasing + got better -> increase again
513516
// TODO: Not the best?
517+
// TODO: Fix cycleing
518+
// TODO: DOn't decrease when equal power
514519
powerIndex++;
515520
load.setLoadGPIO(LOAD::RES_INDEX_TABLE[powerIndex]);
516521
adjustmentHistory.push(LoadAdjustment::INCREASE);
@@ -543,7 +548,8 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
543548
(adjustmentHistory[0] != LoadAdjustment::INCREASE) &&
544549
(powerIndex > 0)) { // MARK: BOLD LOAD
545550
// increasing + got worse a bunch -> decrease
546-
powerIndex--;
551+
// powerIndex--;
552+
powerIndex -= 2;
547553
load.setLoadGPIO(LOAD::RES_INDEX_TABLE[powerIndex]);
548554
adjustmentHistory.push(LoadAdjustment::DECREASE);
549555
ESP_LOGI(TAG, "Last power: %d mW, current power: %d mW",

0 commit comments

Comments
 (0)