Go into discharge for 5s
The discharge circuit is only active while the SDC is open. If the SDC never opens (or opens for a very short time only), but we go to TS_INACTIVE, then the discharge circuit will never be active. Going into a discharge state for 5s allows the PDU to open the SDC for long enough to reach <60V.
This commit is contained in:
@ -10,6 +10,7 @@ TSStateHandle ts_state;
|
||||
|
||||
static uint32_t precharge_95_reached_timestamp = 0;
|
||||
static uint32_t charging_check_timestamp = 0;
|
||||
static uint32_t discharge_begin_timestamp = 0;
|
||||
|
||||
void ts_sm_init() {
|
||||
ts_state.current_state = TS_INACTIVE;
|
||||
@ -63,6 +64,7 @@ TSState ts_sm_update_inactive() {
|
||||
|
||||
TSState ts_sm_update_active() {
|
||||
if (ts_state.target_state == TS_INACTIVE) {
|
||||
discharge_begin_timestamp = HAL_GetTick();
|
||||
return TS_DISCHARGE;
|
||||
}
|
||||
|
||||
@ -71,6 +73,7 @@ TSState ts_sm_update_active() {
|
||||
|
||||
TSState ts_sm_update_precharge() {
|
||||
if (ts_state.target_state == TS_INACTIVE) {
|
||||
discharge_begin_timestamp = HAL_GetTick();
|
||||
return TS_DISCHARGE;
|
||||
}
|
||||
if (shunt_data.voltage2 > MIN_VEHICLE_SIDE_VOLTAGE &&
|
||||
@ -88,8 +91,11 @@ TSState ts_sm_update_precharge() {
|
||||
}
|
||||
|
||||
TSState ts_sm_update_discharge() {
|
||||
// TODO: Actually wait for discharge
|
||||
return TS_INACTIVE;
|
||||
if (HAL_GetTick() - discharge_begin_timestamp >= DISCHARGE_DURATION) {
|
||||
return TS_INACTIVE;
|
||||
} else {
|
||||
return TS_DISCHARGE;
|
||||
}
|
||||
}
|
||||
|
||||
TSState ts_sm_update_error() {
|
||||
@ -109,6 +115,7 @@ TSState ts_sm_update_error() {
|
||||
|
||||
TSState ts_sm_update_charging_check() {
|
||||
if (ts_state.target_state == TS_INACTIVE) {
|
||||
discharge_begin_timestamp = HAL_GetTick();
|
||||
return TS_DISCHARGE;
|
||||
}
|
||||
|
||||
@ -124,6 +131,7 @@ TSState ts_sm_update_charging_check() {
|
||||
|
||||
TSState ts_sm_update_charging() {
|
||||
if (ts_state.target_state == TS_INACTIVE) {
|
||||
discharge_begin_timestamp = HAL_GetTick();
|
||||
return TS_DISCHARGE;
|
||||
}
|
||||
if (shunt_data.current < 0) {
|
||||
@ -136,6 +144,7 @@ TSState ts_sm_update_charging() {
|
||||
void ts_sm_set_relay_positions(TSState state) {
|
||||
switch (state) {
|
||||
case TS_INACTIVE:
|
||||
case TS_DISCHARGE:
|
||||
case TS_ERROR:
|
||||
ts_sm_set_relay_position(RELAY_NEG, 0);
|
||||
ts_sm_set_relay_position(RELAY_POS, 0);
|
||||
@ -143,7 +152,6 @@ void ts_sm_set_relay_positions(TSState state) {
|
||||
break;
|
||||
case TS_ACTIVE:
|
||||
case TS_CHARGING:
|
||||
case TS_DISCHARGE:
|
||||
ts_sm_set_relay_position(RELAY_NEG, 1);
|
||||
ts_sm_set_relay_position(RELAY_POS, 1);
|
||||
ts_sm_set_relay_position(RELAY_PRECHARGE, 1);
|
||||
|
||||
Reference in New Issue
Block a user