Skip to content

Commit c7c721d

Browse files
committed
Main: Fleshed out load adjustment prototype
1 parent aac4721 commit c7c721d

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/main.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,32 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
418418
// pitchPIDController.compute(
419419
// i)); // todo - just a quick performances test
420420
i += 20;
421+
static int_fast32_t lastPower = 0;
422+
static int_fast8_t powerIndex = 46;
423+
if (INA260::current_mA > 0) {
424+
// Don't run at startup
425+
delay(RUN::TASK_INTERVALS::TI_ADJUST_LOAD_mS);
426+
} else if (abs(INA260::dPower_mWPS) > (abs(INA260::power_mW) * 0.05)) {
427+
// Wait for power to stabilize
428+
} else if ((lastPower == 0) && (powerIndex > 0)) {
429+
powerIndex--;
430+
load.setLoadGPIO(LOAD::RES_INDEX_TABLE[powerIndex]);
431+
ESP_LOGI(TAG, "Initial load adjustment, setpoint: %d",
432+
LOAD::RES_INDEX_TABLE[powerIndex]);
433+
} else if ((INA260::dPower_mWPS > lastPower) && (powerIndex > 0)) {
434+
powerIndex--;
435+
load.setLoadGPIO(LOAD::RES_INDEX_TABLE[powerIndex]);
436+
ESP_LOGI(TAG, "Decreasing load to %d",
437+
LOAD::RES_INDEX_TABLE[powerIndex]);
438+
} else if ((INA260::dPower_mWPS < lastPower) && (powerIndex < 46)) {
439+
powerIndex++;
440+
load.setLoadGPIO(LOAD::RES_INDEX_TABLE[powerIndex]);
441+
ESP_LOGI(TAG, "Increasing load to %d",
442+
LOAD::RES_INDEX_TABLE[powerIndex]);
443+
delay(20 *
444+
1000); // todo RUN::TASK_INTERVALS::TI_ADJUST_LOAD_mS * 100
445+
} // todo: change trigger to when rpm changes or when power changes
446+
421447
delay(RUN::TASK_INTERVALS::TI_ADJUST_LOAD_mS);
422448
}
423449
}

0 commit comments

Comments
 (0)