Skip to content

Commit 29b5ece

Browse files
committed
Updated loadDisconnect to use counter
1 parent b66e53f commit 29b5ece

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

include/LoadContainer.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LoadContainer {
2323
TaskInfo tFSM{vTaskUpdateFSM, "FSM", 2048, nullptr, 20,
2424
nullptr, 0, false, true};
2525
TaskInfo tPoll{vTPollS, "Poll", 4096, nullptr, 20,
26-
nullptr, 0, false, false};
26+
nullptr, 0, false, false};
2727
TaskInfo tAdjustLoad{vTaskAdjustLoad, "AdLd", 2048, nullptr, 15,
2828
nullptr, 0, false, true};
2929
TaskInfo tRecv{vTaskRecvData, "Recv", 2048, nullptr, 10,
@@ -64,14 +64,24 @@ class LoadContainer {
6464
} // todo
6565

6666
inline void updateSafetyFlag() {
67-
ESP_LOGD(TAG, "ESTOP: %d", digitalRead(UM_PROS3::ESTOP_PIN));
67+
// ESP_LOGD(TAG, "ESTOP: %d", digitalRead(UM_PROS3::ESTOP_PIN));
68+
static uint_fast8_t loadDisconnectCounter = 0;
6869
if (digitalRead(UM_PROS3::ESTOP_PIN) == HIGH) {
6970
this->safetyFlag = ESTOP_TYPE_FAST::BUTTON;
71+
loadDisconnectCounter = 0;
7072
} else if (abs(INA260::current_mA) <
7173
PSENSOR::LOAD_SHED_I_THRESHOLD_mA) {
72-
this->safetyFlag = ESTOP_TYPE_FAST::LOAD_DISCONNECT_I;
74+
loadDisconnectCounter++;
75+
constexpr uint_fast32_t LOAD_DISCONNECT_DELAY_ms = 1000;
76+
constexpr uint_fast32_t LOAD_DISCONNECT_DELAY_CNT =
77+
LOAD_DISCONNECT_DELAY_ms /
78+
RUN::TASK_INTERVALS::TI_POLL_SENSORS_mS;
79+
if (loadDisconnectCounter > LOAD_DISCONNECT_DELAY_CNT) {
80+
this->safetyFlag = ESTOP_TYPE_FAST::LOAD_DISCONNECT_I;
81+
}
7382
} else {
7483
this->safetyFlag = ESTOP_TYPE_FAST::NONE;
84+
loadDisconnectCounter = 0;
7585
}
7686
}
7787
// inline void updatePowerPositive(bool powerPositive) {

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,6 @@ vTaskUpdateFSM([[maybe_unused]] void *pvParameters) { // NOSONAR
394394
while (true) {
395395
static TickType_t xLastWakeTime = xTaskGetTickCount();
396396

397-
// load.updateSafetyFlag(); // Moved to interrupts before noticing that
398-
// the backoff was the problem, might as well leave it that way
399-
400397
// static uint32_t backoffFactor =
401398
// RUN::TASK_INTERVALS::FAIL_BACKOFF_BASE_FACTOR;
402399
// uint32_t delay_ms = 0;
@@ -411,6 +408,9 @@ vTaskUpdateFSM([[maybe_unused]] void *pvParameters) { // NOSONAR
411408
// }
412409
INA260::updateReadings();
413410

411+
load.updateSafetyFlag(); // Moved to interrupts before noticing that
412+
// the backoff was the problem, might as well leave it that way
413+
414414
BaseType_t xWasDelayed = xTaskDelayUntil(
415415
&xLastWakeTime,
416416
pdMS_TO_TICKS(RUN::TASK_INTERVALS::TI_POLL_SENSORS_mS));

0 commit comments

Comments
 (0)