Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 35 additions & 3 deletions components/statemachine/statemachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,38 @@ void stateTransition(){
void errorCheck(){
// skip check if already in fault state
if (moboState.currentState == FAULT) return;

//Timer variables
static uint32_t overvoltage_start_time = 0;
static uint32_t undervoltage_start_time = 0;
static uint32_t overcurrent_start_time = 0;

//Initializing timer variables
//Overvoltage
if(getMaxVoltageIndex(&module, &errIndex) > OVERVOLTAGE_THRESHOLD){
if(overvoltage_start_time == 0){
overvoltage_start_time = pdTICKS_TO_MS(xTaskGetTickCount());
}
} else {
overvoltage_start_time = 0;
}
//Undercurrent

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this say undervoltage?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

if (getMinVoltageIndex(&module, &errIndex) < UNDERVOLTAGE_THRESHOLD && getMinVoltage() > 0){
if(undervoltage_start_time == 0){
undervoltage_start_time = pdTICKS_TO_MS(xTaskGetTickCount());
}
} else {
undervoltage_start_time = 0;
}
//Overcurrent
if (Cursense_VtoA(analogVoltages[ANALOG_CURSENSE]) > CURRENT_LIMIT){
if(overcurrent_start_time == 0){
overcurrent_start_time = pdTICKS_TO_MS(xTaskGetTickCount());
}
} else {
overcurrent_start_time = 0;
}

// 2 error check levels: mission mode for only critical faults, and test mode for all faults
if(getMaxTempIndex(&module, &errIndex) > OVERTEMP_THRESHOLD){
moboState.error = OVERTEMP;
Expand All @@ -122,21 +154,21 @@ void errorCheck(){
moboState.errorIndex = errIndex;
moboState.errorModule = module;
ESP_LOGE(TAG, "Fault: OVERTEMP");
} else if(getMaxVoltageIndex(&module, &errIndex) > OVERVOLTAGE_THRESHOLD){
} else if(overvoltage_start_time!=0 && (pdTICKS_TO_MS(xTaskGetTickCount()) - overvoltage_start_time) > MAX_DEBOUNCE_TIME){
moboState.error = OVERVOLTAGE;
moboState.lastState = moboState.currentState;
moboState.currentState = FAULT;
moboState.errorIndex = errIndex;
moboState.errorModule = module;
ESP_LOGE(TAG, "Fault: OVERVOLTAGE");
} else if(getMinVoltageIndex(&module, &errIndex) < UNDERVOLTAGE_THRESHOLD && getMinVoltage() > 0){
} else if(undervoltage_start_time!=0 && (pdTICKS_TO_MS(xTaskGetTickCount()) - undervoltage_start_time) > MAX_DEBOUNCE_TIME){
moboState.error = UNDERVOLTAGE;
moboState.lastState = moboState.currentState;
moboState.currentState = FAULT;
moboState.errorIndex = errIndex;
moboState.errorModule = module;
ESP_LOGE(TAG, "Fault: UNDERVOLTAGE");
} else if (Cursense_VtoA(analogVoltages[ANALOG_CURSENSE]) > CURRENT_LIMIT){
} else if (overcurrent_start_time!=0 && (pdTICKS_TO_MS(xTaskGetTickCount()) - overcurrent_start_time) > MAX_DEBOUNCE_TIME){
moboState.error = OVERCURRENT;
moboState.lastState = moboState.currentState;
moboState.currentState = FAULT;
Expand Down
2 changes: 2 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
#define MAX_CAN_TIMEOUT 10000
#define PRECHARGE_MINDELAY 5000

#define MAX_DEBOUNCE_TIME 50 //50ms

#define MISSION_MODE // only critical faults, for racing
#define INVERTER_PRECHARGE // precharge voltage from inverter