updated the state machine

This commit is contained in:
Hamza Tamim 2024-05-23 19:08:46 +03:00
parent 61c8d173a1
commit 1642627dd2
2 changed files with 13 additions and 16 deletions

View File

@ -54,12 +54,12 @@ void sm_init();
void sm_update();
State sm_update_inactive();
State sm_update_active();
State sm_update_precharge();
State sm_update_ready();
State sm_update_active();
State sm_update_discharge();
State sm_update_error();
State sm_update_charging_check();
State sm_update_charging();
State sm_update_error();
typedef enum { RELAY_POS, RELAY_PRECHARGE } Relay;
void sm_set_relay_positions(State state);

View File

@ -16,39 +16,35 @@ void sm_update(){
switch (state.current_state) {
case INACTIVE:
//state.current_state = sm_update_inactive(); moniter only
state.current_state = sm_update_inactive(); // moniter only
break;
case PRECHARGE:
//state.current_state = sm_update_precharge(); set PRECHARGE and turn on cooling at 50% or such
state.current_state = sm_update_precharge(); // set PRECHARGE and turn on cooling at 50% or such
break;
case READY:
//state.current_state = ; keep cooling at 50%, get ready to turn on powerground
state.current_state = sm_update_ready(); // keep cooling at 50%, get ready to turn on powerground
break;
case ACTIVE:
//state.current_state = sm_update_precharge(); set PRECHARGE and turn on cooling at 50% or such
state.current_state = sm_update_active(); // set PRECHARGE and turn on cooling at 50% or such
break;
case DISCHARGE:
//state.current_state = sm_update_discharge(); // open the main relay, keep PRECHARGE closed
state.current_state = sm_update_discharge(); // open the main relay, keep PRECHARGE closed
break;
case CHARGING:
//state.current_state = sm_update_charging(); // turn on cooling if needed,
state.current_state = sm_update_charging(); // turn on cooling if needed,
break;
case ERROR:
//state.current_state = sm_update_error(); // enter the correct ERROR state
break;
case WARNING:
//state.current_state = sm_update_error(); // send warnings through CAN
state.current_state = sm_update_error(); // enter the correct ERROR state
break;
}
sm_set_relay_positions(state.current_state);
status_led_state(state.current_state, (ErrorKind) state.error_type);
//status_led_state(state.current_state, (ErrorKind) state.error_type);
}
State sm_update_inactive(){
switch (state.target_state) {
case PRECHARGE:
if ()
break;
case CHARGING:
break;
@ -121,7 +117,7 @@ State sm_update_error(){
void sm_set_relay_positions(State state){
return;
}
/*
void sm_set_relay(Relay relay, int closed){
static int closed = 0;
static int precharge_closed = 0;
@ -138,6 +134,7 @@ void sm_set_relay(Relay relay, int closed){
break;
}
}
*/
//void sm_check_close_wait(int *is_closed, int should_close);