diff --git a/include/ACU_Constants.h b/include/ACU_Constants.h index a54b3b8f..6ab52312 100644 --- a/include/ACU_Constants.h +++ b/include/ACU_Constants.h @@ -24,6 +24,7 @@ namespace ACUSystems constexpr const volt VOLTAGE_DIFF_TO_INIT_CB = 0.02; // differential with lowest cell voltage to enable cell balancing for a cell constexpr const celsius BALANCE_TEMP_LIMIT_C = 50.0; constexpr const celsius BALANCE_ENABLE_TEMP_THRESH_C = 35.0; // Celsius + constexpr const volt TS_ISOLATION_VOLTAGE = 0.2; // Volts } namespace ACUInterfaces { @@ -32,7 +33,8 @@ namespace ACUInterfaces { const size_t SERIAL_BAUDRATE = 115200; constexpr const size_t TEENSY_OK_PIN = 3; // > Needs to stay HIGH while wd_kick_pin flips to keep BMS_OK high - constexpr const size_t WD_KICK_PIN = 4; // > Needs to flip at 100 Hz to keep BMS_OK high + constexpr const size_t WD_KICK_PIN = 4; // > Needs to flip at 100 Hz to keep BMS_OK high + constexpr const size_t SW_NOT_OK_PIN = 5; constexpr const size_t N_LATCH_EN_PIN = 6; // > Input to Safety Light, true when teensy is not in FAULT state constexpr const size_t TS_OUT_FILTERED_PIN = 17; constexpr const size_t PACK_OUT_FILTERED_PIN = 18; diff --git a/include/ACU_SystemTasks.h b/include/ACU_SystemTasks.h index 5a0f5356..2f3dcdd1 100644 --- a/include/ACU_SystemTasks.h +++ b/include/ACU_SystemTasks.h @@ -30,6 +30,7 @@ extern ::etl::delegate has_imd_fault; extern ::etl::delegate received_valid_shdn_out; extern ::etl::delegate enable_cell_balancing; extern ::etl::delegate disable_cell_balancing; +extern ::etl::delegate contactor_welded; extern ::etl::delegate disable_watchdog; extern ::etl::delegate reinitialize_watchdog; extern ::etl::delegate disable_n_latch_en; @@ -39,4 +40,6 @@ ::HT_TASK::TaskResponse evaluate_accumulator(const unsigned long &sysMicros, con ::HT_TASK::TaskResponse tick_state_machine(const unsigned long &sysMicros, const HT_TASK::TaskInfo &taskInfo); + + #endif \ No newline at end of file diff --git a/lib/interfaces/include/ADCInterface.h b/lib/interfaces/include/ADCInterface.h index c9bc4947..7181b94c 100644 --- a/lib/interfaces/include/ADCInterface.h +++ b/lib/interfaces/include/ADCInterface.h @@ -25,6 +25,7 @@ struct ADCPinout_s pin teensy_pack_out_filtered_pin; pin teensy_bspd_current_pin; pin teensy_scaled_24V_pin; + pin teensy_sw_not_ok_pin; }; struct ADCConversions_s @@ -155,6 +156,10 @@ class ADCInterface */ bool is_in_imd_startup_period() const; + void set_sw_not_ok_pin_high(); + + void set_sw_not_ok_pin_low(); + private: const ADCInterfaceParams_s _adc_parameters = {}; diff --git a/lib/interfaces/src/ACUEthernetInterface.cpp b/lib/interfaces/src/ACUEthernetInterface.cpp index 28614be3..d592f80f 100644 --- a/lib/interfaces/src/ACUEthernetInterface.cpp +++ b/lib/interfaces/src/ACUEthernetInterface.cpp @@ -45,6 +45,7 @@ hytech_msgs_ACUCoreData ACUEthernetInterface::make_acu_core_data_msg(const ACUCo out.min_measured_pack_voltage = shared_state.min_measured_pack_out_voltage; out.min_measured_tractive_system_voltage = shared_state.min_measured_ts_out_voltage; out.min_measured_shdn_out_voltage = shared_state.min_shdn_out_voltage; + return out; } diff --git a/lib/interfaces/src/ADCInterface.cpp b/lib/interfaces/src/ADCInterface.cpp index 81450fe0..f7850b90 100644 --- a/lib/interfaces/src/ADCInterface.cpp +++ b/lib/interfaces/src/ADCInterface.cpp @@ -9,6 +9,7 @@ void ADCInterface::init(uint32_t init_millis) { pinMode(_adc_parameters.pinout.teensy_pack_out_filtered_pin, INPUT); pinMode(_adc_parameters.pinout.teensy_bspd_current_pin, INPUT); pinMode(_adc_parameters.pinout.teensy_scaled_24V_pin, INPUT); + pinMode(_adc_parameters.pinout.teensy_sw_not_ok_pin, OUTPUT); _init_millis = init_millis; _in_imd_startup_period = true; @@ -80,4 +81,12 @@ const ADCInterfaceParams_s& ADCInterface::get_adc_params() const { bool ADCInterface::is_in_imd_startup_period() const { return _in_imd_startup_period; +} + +void ADCInterface::set_sw_not_ok_pin_high() { + digitalWrite(_adc_parameters.pinout.teensy_sw_not_ok_pin, HIGH); +} + +void ADCInterface::set_sw_not_ok_pin_low() { + digitalWrite(_adc_parameters.pinout.teensy_sw_not_ok_pin, LOW); } \ No newline at end of file diff --git a/lib/interfaces/src/WatchdogInterface.cpp b/lib/interfaces/src/WatchdogInterface.cpp index ef190c9e..0edd011a 100644 --- a/lib/interfaces/src/WatchdogInterface.cpp +++ b/lib/interfaces/src/WatchdogInterface.cpp @@ -5,6 +5,7 @@ void WatchdogInterface::init() { pinMode(_watchdog_parameters.pinout.teensy_ok_pin, OUTPUT); pinMode(_watchdog_parameters.pinout.teensy_wd_kick_pin, OUTPUT); pinMode(_watchdog_parameters.pinout.teensy_n_latch_en_pin, OUTPUT); + // Initial Pin States for OUTPUT pins digitalWrite(_watchdog_parameters.pinout.teensy_ok_pin, HIGH); diff --git a/lib/state_machine/include/ACUStateMachine.h b/lib/state_machine/include/ACUStateMachine.h index 4672e854..dada732b 100644 --- a/lib/state_machine/include/ACUStateMachine.h +++ b/lib/state_machine/include/ACUStateMachine.h @@ -13,7 +13,9 @@ enum class ACUState_e STARTUP = 0, ACTIVE = 1, CHARGING = 2, - FAULTED = 3, + FAULTED = 3, + WELDED = 4, + WELDPASSED = 5 }; class ACUStateMachine @@ -23,6 +25,9 @@ class ACUStateMachine etl::delegate charge_state_requested, etl::delegate has_bms_fault, etl::delegate has_imd_fault, + etl::delegate contactor_welded, + etl::delegate set_sw_not_ok_pin_high, + etl::delegate set_sw_not_ok_pin_low, etl::delegate received_valid_shdn_out, etl::delegate enable_cell_balancing, etl::delegate disable_cell_balancing, @@ -35,6 +40,9 @@ class ACUStateMachine _charge_state_requested(charge_state_requested), _has_bms_fault(has_bms_fault), _has_imd_fault(has_imd_fault), + _contactor_welded(contactor_welded), + _set_sw_not_ok_pin_high(set_sw_not_ok_pin_high), + _set_sw_not_ok_pin_low(set_sw_not_ok_pin_low), _received_valid_shdn_out(received_valid_shdn_out), _enable_cell_balancing(enable_cell_balancing), _disable_cell_balancing(disable_cell_balancing), @@ -54,6 +62,8 @@ class ACUStateMachine */ ACUState_e get_state() { return _current_state; } + + private: void _set_state(ACUState_e new_state, unsigned long curr_millis); @@ -72,11 +82,15 @@ class ACUStateMachine ACUState_e _current_state; unsigned long _last_state_changed_time; // time of last state change - + + // Lamdas for state machine abstraction, functions defined in main etl::delegate _charge_state_requested; etl::delegate _has_bms_fault; etl::delegate _has_imd_fault; + etl::delegate _contactor_welded; + etl::delegate _set_sw_not_ok_pin_high; + etl::delegate _set_sw_not_ok_pin_low; etl::delegate _received_valid_shdn_out; /// @brief setters etl::delegate _enable_cell_balancing; diff --git a/lib/state_machine/src/ACUStateMachine.cpp b/lib/state_machine/src/ACUStateMachine.cpp index c1e3536a..8c72f05d 100644 --- a/lib/state_machine/src/ACUStateMachine.cpp +++ b/lib/state_machine/src/ACUStateMachine.cpp @@ -1,19 +1,37 @@ #include "ACUStateMachine.h" +#include +using namespace std; + void ACUStateMachine::tick_state_machine(unsigned long current_millis) { switch(_current_state) { case ACUState_e::STARTUP: { - if (_received_valid_shdn_out()) { - _set_state(ACUState_e::ACTIVE, current_millis); - break; + if (current_millis - _last_state_changed_time >= 1000) { + if (_contactor_welded()) { + _set_state(ACUState_e::WELDED, current_millis); + break; + } + else { + _set_state(ACUState_e::WELDPASSED, current_millis); + break; + } } - if ((current_millis - _last_state_changed_time > 2000) && (_has_bms_fault() || _has_imd_fault())) { - _set_state(ACUState_e::FAULTED, current_millis); + + break; + } + case ACUState_e::WELDPASSED: + { + if (_received_valid_shdn_out()) { + _set_state(ACUState_e::ACTIVE, current_millis); break; } - break; } + case ACUState_e::WELDED: + { + + } + case ACUState_e::ACTIVE: { if (_charge_state_requested()) { @@ -84,6 +102,8 @@ void ACUStateMachine::_handle_exit_logic(ACUState_e prev_state, unsigned long cu } case ACUState_e::STARTUP: case ACUState_e::ACTIVE: + case ACUState_e::WELDPASSED: + case ACUState_e::WELDED: default: break; } @@ -94,9 +114,20 @@ void ACUStateMachine::_handle_entry_logic(ACUState_e new_state, unsigned long cu switch(new_state) { case ACUState_e::STARTUP: { + _last_state_changed_time = curr_millis; _reinitialize_watchdog(); break; } + case ACUState_e::WELDPASSED: + { + _set_sw_not_ok_pin_low(); + break; + } + case ACUState_e::WELDED: + { + _set_sw_not_ok_pin_high(); + break; + } case ACUState_e::CHARGING: { _enable_cell_balancing(); @@ -113,4 +144,5 @@ void ACUStateMachine::_handle_entry_logic(ACUState_e new_state, unsigned long cu default: break; } -} \ No newline at end of file +} + diff --git a/lib/systems/include/ACUController.h b/lib/systems/include/ACUController.h index 7efc94dd..a6798834 100644 --- a/lib/systems/include/ACUController.h +++ b/lib/systems/include/ACUController.h @@ -1,6 +1,7 @@ #ifndef ACUCONTROLLER_H #define ACUCONTROLLER_H +#include #include #include #include @@ -20,6 +21,8 @@ namespace acu_controller_default_parameters constexpr const float PACK_MAX_VOLTAGE = 529.2; // from data sheet https://wiki.hytechracing.org/books/ht09-design/page/molicel-pack-investigation constexpr const float PACK_MIN_VOLTAGE = 378.0; // from data sheet^ but just assume 126 * 3.0V constexpr const float PACK_INTERNAL_RESISTANCE = 0.246; // Ohms (measured) + + } struct ACUControllerData_s { @@ -37,6 +40,9 @@ struct ACUControllerData_s uint32_t last_bms_not_ok_eval; bool charging_enabled; bool balancing_enabled; + bool high_side_contactor_welded; + bool low_side_contactor_welded; + }; struct ACUControllerThresholds_s @@ -50,6 +56,7 @@ struct ACUControllerThresholds_s volt v_diff_to_init_cb = 0; celsius balance_temp_limit_c = 0; celsius balance_enable_temp_c = 0; + volt ts_isolation_voltage = 0; }; struct ACUControllerFaultDurations_s @@ -99,8 +106,10 @@ class ACUController .pack_nominal_capacity = acu_controller_default_parameters::PACK_NOMINAL_CAPACITY_AH, .pack_max_voltage = acu_controller_default_parameters::PACK_MAX_VOLTAGE, .pack_min_voltage = acu_controller_default_parameters::PACK_MIN_VOLTAGE, - .pack_internal_resistance = acu_controller_default_parameters::PACK_INTERNAL_RESISTANCE - }) : _acu_parameters{thresholds, invalid_packet_count_thresh, fault_durations, pack_specs} {}; + .pack_internal_resistance = acu_controller_default_parameters::PACK_INTERNAL_RESISTANCE} + + + ) : _acu_parameters{thresholds, invalid_packet_count_thresh, fault_durations, pack_specs} {}; /** * @brief Initialize the status time stamps because we don't want accidental sudden faults @@ -118,6 +127,7 @@ class ACUController * Calculate Cell Balancing values * @pre cell charging is enabled * @post output will have the new values + * check TS isolation */ void calculate_cell_balance_statuses(bool* output, const volt* voltages, size_t num_of_voltage_cells, volt min_voltage); @@ -136,6 +146,9 @@ class ACUController { _acu_state.charging_enabled = false; } + + bool check_ts_isolation(volt pack_voltage_adc, volt ts_voltage_adc); + private: diff --git a/lib/systems/src/ACUController.cpp b/lib/systems/src/ACUController.cpp index d3eda665..10bd2a81 100644 --- a/lib/systems/src/ACUController.cpp +++ b/lib/systems/src/ACUController.cpp @@ -1,6 +1,7 @@ #include "ACUController.h" + void ACUController::init(time_ms system_start_time, volt pack_voltage) { _acu_state.last_time_ov_fault_not_present = system_start_time; @@ -12,6 +13,8 @@ void ACUController::init(time_ms system_start_time, volt pack_voltage) _acu_state.prev_bms_time_stamp = system_start_time; _acu_state.SoC = (pack_voltage <= _acu_parameters.pack_specs.pack_min_voltage) ? 0.0f : ((pack_voltage - _acu_parameters.pack_specs.pack_min_voltage) / (_acu_parameters.pack_specs.pack_max_voltage - _acu_parameters.pack_specs.pack_min_voltage)); _acu_state.balancing_enabled = false; + _acu_state.high_side_contactor_welded = false; + _acu_state.low_side_contactor_welded = false; } @@ -100,7 +103,6 @@ ACUControllerData_s ACUController::evaluate_accumulator(time_ms current_millis, // Determine if bms is ok _acu_state.bms_ok = _check_bms_ok(current_millis); - return _acu_state; } @@ -173,4 +175,15 @@ bool ACUController::_check_invalid_packet_faults(time_ms current_millis) { bool invalid_packet_fault = (current_millis - _acu_state.last_time_invalid_packet_present) > _acu_parameters.fault_durations.max_allowed_invalid_packet_fault_dur; return invalid_packet_fault; +} + +bool ACUController::check_ts_isolation(volt pack_voltage_adc, volt ts_voltage_adc) +{ + + + _acu_state.low_side_contactor_welded = !(pack_voltage_adc < _acu_parameters.thresholds.ts_isolation_voltage); + _acu_state.high_side_contactor_welded = !(ts_voltage_adc < _acu_parameters.thresholds.ts_isolation_voltage); + + bool sw_not_ok = _acu_state.low_side_contactor_welded || _acu_state.high_side_contactor_welded; + return sw_not_ok; } \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index bb64b605..f2002090 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,7 +1,7 @@ [common] lib_deps_shared = https://github.com/hytech-racing/shared_firmware_systems.git - https://github.com/hytech-racing/shared_firmware_types.git#9525cc8b5778567afee9d9121f8f8933367e13b3 + https://github.com/hytech-racing/shared_firmware_types.git#7a3684f9501d672b8229476644b8ee5556f0adb5 Embedded Template Library@^20.39.4 ; Teensy41 Environment. This environment is the primary environment for uploading code to the car. diff --git a/src/ACU_InterfaceTasks.cpp b/src/ACU_InterfaceTasks.cpp index 33e75945..aa40923b 100644 --- a/src/ACU_InterfaceTasks.cpp +++ b/src/ACU_InterfaceTasks.cpp @@ -44,7 +44,11 @@ static ACUAllDataType_s make_acu_all_data() out.core_data.min_measured_ts_out_voltage = watchdog.min_measured_ts_out_voltage; out.core_data.min_shdn_out_voltage = watchdog.min_shdn_out_voltage; // SoC/SoH placeholders (leave unchanged here) - out.SoC = ACUControllerInstance::instance().get_status().SoC; + auto ACUStatus = ACUControllerInstance::instance().get_status(); + + out.SoC = ACUStatus.SoC; + out.core_data.high_side_contactor_welded = ACUStatus.high_side_contactor_welded; + out.core_data.low_side_contactor_welded = ACUStatus.low_side_contactor_welded; return out; } @@ -94,7 +98,8 @@ void initialize_all_interfaces() ACUInterfaces::TS_OUT_FILTERED_PIN, ACUInterfaces::PACK_OUT_FILTERED_PIN, ACUInterfaces::BSPD_CURRENT_PIN, - ACUInterfaces::SCALED_24V_PIN}, + ACUInterfaces::SCALED_24V_PIN, + ACUInterfaces::SW_NOT_OK_PIN}, ADCConversions_s {ACUInterfaces::SHUTDOWN_CONV_FACTOR, ACUInterfaces::PRECHARGE_CONV_FACTOR, ACUInterfaces::PACK_AND_TS_OUT_CONV_FACTOR, diff --git a/src/ACU_SystemTasks.cpp b/src/ACU_SystemTasks.cpp index 70c91121..7686bf8d 100644 --- a/src/ACU_SystemTasks.cpp +++ b/src/ACU_SystemTasks.cpp @@ -11,7 +11,8 @@ bool initialize_all_systems() ACUSystems::MIN_PACK_TOTAL_VOLTAGE, ACUSystems::VOLTAGE_DIFF_TO_INIT_CB, ACUSystems::BALANCE_TEMP_LIMIT_C, - ACUSystems::BALANCE_ENABLE_TEMP_THRESH_C}); + ACUSystems::BALANCE_ENABLE_TEMP_THRESH_C, + ACUSystems::TS_ISOLATION_VOLTAGE} ); ACUControllerInstance::instance().init(sys_time::hal_millis(), BMSDriverInstance_t::instance().get_bms_data().total_voltage); /* State Machine Initialization */ @@ -25,14 +26,25 @@ bool initialize_all_systems() etl::delegate has_imd_fault = etl::delegate::create([]() -> bool { return !ADCInterfaceInstance::instance().read_imd_ok(sys_time::hal_millis()); }); + etl::delegate contactor_welded = etl::delegate::create([]() -> bool + { ACUControllerInstance::instance().check_ts_isolation(ADCInterfaceInstance::instance().read_pack_out_filtered(), ADCInterfaceInstance::instance().read_ts_out_filtered()); }); + + etl::delegate set_sw_not_ok_pin_high = etl::delegate::create([]() -> void + { ADCInterfaceInstance::instance().set_sw_not_ok_pin_high(); }); + + etl::delegate set_sw_not_ok_pin_low = etl::delegate::create([]() -> void + { ADCInterfaceInstance::instance().set_sw_not_ok_pin_low(); }); + + etl::delegate disable_watchdog = etl::delegate::create(WatchdogInstance::instance()); + etl::delegate received_valid_shdn_out = etl::delegate::create(ADCInterfaceInstance::instance()); + etl::delegate enable_cell_balancing = etl::delegate::create([]() -> void { ACUControllerInstance::instance().enableCharging(); }); etl::delegate disable_cell_balancing = etl::delegate::create([]() -> void { ACUControllerInstance::instance().disableCharging(); }); - etl::delegate disable_watchdog = etl::delegate::create(WatchdogInstance::instance()); etl::delegate reinitialize_watchdog = etl::delegate::create(WatchdogInstance::instance()); @@ -40,9 +52,13 @@ bool initialize_all_systems() etl::delegate reset_latch = etl::delegate::create(WatchdogInstance::instance()); + ACUStateMachineInstance::create(charge_state_request, has_bms_fault, has_imd_fault, + contactor_welded, + set_sw_not_ok_pin_high, + set_sw_not_ok_pin_low, received_valid_shdn_out, enable_cell_balancing, disable_cell_balancing, @@ -52,6 +68,8 @@ bool initialize_all_systems() disable_n_latch_en, sys_time::hal_millis()); + ADCInterfaceInstance::instance().set_sw_not_ok_pin_high(); + return true; } diff --git a/test/test_systems/test_acu_controller.h b/test/test_systems/test_acu_controller.h index 95b7538d..bf076b64 100644 --- a/test/test_systems/test_acu_controller.h +++ b/test/test_systems/test_acu_controller.h @@ -19,17 +19,19 @@ ACUControllerThresholds_s thresholds = {ACUSystems::MIN_DISCHARGE_VOLTAGE_THRESH ACUSystems::MIN_PACK_TOTAL_VOLTAGE, ACUSystems::VOLTAGE_DIFF_TO_INIT_CB, ACUSystems::BALANCE_TEMP_LIMIT_C, - ACUSystems::BALANCE_ENABLE_TEMP_THRESH_C - }; + ACUSystems::BALANCE_ENABLE_TEMP_THRESH_C, + ACUSystems::TS_ISOLATION_VOLTAGE}; TEST(ACUControllerTesting, initial_state) { ACUControllerInstance::create(thresholds); ACUController controller = ACUControllerInstance::instance(); + charging_enabled = false; uint32_t start_time = 0; - + controller.init(start_time, 420.0f); + BMSCoreData_s data{}; // zeros auto status = controller.evaluate_accumulator(start_time, data, 0, ZERO_PACK_CURRENT, num_cells); @@ -260,7 +262,7 @@ TEST(ACUControllerTesting, cell_overvoltage_fault_persistence) // Tests that UV faults require 1000ms persistence before triggering TEST(ACUControllerTesting, cell_undervoltage_fault_persistence) { - ACUControllerInstance::create(thresholds); + ACUControllerInstance::create(thresholds, ACUInterfaces::SW_NOT_OK_PIN); ACUController controller = ACUControllerInstance::instance(); charging_enabled = false; diff --git a/test/test_systems/test_acu_state_machine.h b/test/test_systems/test_acu_state_machine.h index 3e839a6f..9b1b9439 100644 --- a/test/test_systems/test_acu_state_machine.h +++ b/test/test_systems/test_acu_state_machine.h @@ -6,17 +6,18 @@ #include "ACUStateMachine.h" -bool received_CCU_msg_var; +bool request_charge_state; bool has_bms_fault_var; bool has_imd_fault_var; bool received_valid_shdn_out_var; +bool is_contactor_welded; bool charging_en = false; bool watchdog_en = true; bool n_latch_en = true; -etl::delegate received_CCU_message = etl::delegate::create([]() -> bool { - return received_CCU_msg_var; +etl::delegate charge_state_requested = etl::delegate::create([]() -> bool { + return request_charge_state; }); etl::delegate has_bms_fault = etl::delegate::create([]() -> bool { @@ -27,6 +28,16 @@ etl::delegate has_imd_fault = etl::delegate::create([]() -> bool return has_imd_fault_var; }); +etl::delegate contactor_welded = etl::delegate::create([]() -> bool { + return is_contactor_welded; +}); + +etl::delegate set_sw_not_ok_pin_high = etl::delegate::create([]() -> void { +}); + +etl::delegate set_sw_not_ok_pin_low = etl::delegate::create([]() -> void { +}); + etl::delegate received_valid_shdn_out = etl::delegate::create([]() -> bool { return received_valid_shdn_out_var; }); @@ -56,9 +67,12 @@ etl::delegate reset_latch = etl::delegate::create([]() -> void { }); ACUStateMachine state_machine = ACUStateMachine( - received_CCU_message, + charge_state_requested, has_bms_fault, has_imd_fault, + contactor_welded, + set_sw_not_ok_pin_high, + set_sw_not_ok_pin_low, received_valid_shdn_out, enable_cell_balancing, disable_cell_balancing, @@ -70,46 +84,55 @@ ACUStateMachine state_machine = ACUStateMachine( ); TEST (ACUStateMachineTesting, initial_state) { - received_CCU_msg_var = false; + request_charge_state = false; has_bms_fault_var = false; has_imd_fault_var = false; received_valid_shdn_out_var = false; + is_contactor_welded = false; ASSERT_EQ(state_machine.get_state(), ACUState_e::STARTUP); // initial state_machine.tick_state_machine(0); ASSERT_EQ(state_machine.get_state(), ACUState_e::STARTUP); + state_machine.tick_state_machine(1001); + ASSERT_EQ(state_machine.get_state(), ACUState_e::WELDPASSED); + received_valid_shdn_out_var = true; state_machine.tick_state_machine(0); ASSERT_EQ(state_machine.get_state(), ACUState_e::ACTIVE); + + } -TEST (ACUStateMachineTesting, CCU_msg_state) { - received_CCU_msg_var = false; +TEST (ACUStateMachineTesting, charge_state) { + request_charge_state = false; has_bms_fault_var = false; has_imd_fault_var = false; received_valid_shdn_out_var = false; + is_contactor_welded = false; ASSERT_EQ(state_machine.get_state(), ACUState_e::ACTIVE); // initial - received_CCU_msg_var = true; + request_charge_state = true; + ASSERT_EQ(state_machine.get_state(), ACUState_e::ACTIVE); ASSERT_EQ(charging_en, false); state_machine.tick_state_machine(0); ASSERT_EQ(state_machine.get_state(), ACUState_e::CHARGING); ASSERT_EQ(charging_en, true); - received_CCU_msg_var = false; + request_charge_state = false; state_machine.tick_state_machine(0); ASSERT_EQ(state_machine.get_state(), ACUState_e::ACTIVE); ASSERT_EQ(charging_en, false); } TEST (ACUStateMachineTesting, fault_states) { - received_CCU_msg_var = false; + request_charge_state = false; has_bms_fault_var = false; has_imd_fault_var = false; received_valid_shdn_out_var = true; + is_contactor_welded = false; ASSERT_EQ(state_machine.get_state(), ACUState_e::ACTIVE); // initial @@ -141,9 +164,18 @@ TEST (ACUStateMachineTesting, fault_states) { has_bms_fault_var = false; state_machine.tick_state_machine(0); ASSERT_EQ(state_machine.get_state(), ACUState_e::STARTUP); + + is_contactor_welded = true; + state_machine.tick_state_machine(0); + ASSERT_EQ(state_machine.get_state(), ACUState_e::STARTUP); + state_machine.tick_state_machine(1000); + ASSERT_EQ(state_machine.get_state(), ACUState_e::WELDED); + + is_contactor_welded = false; state_machine.tick_state_machine(0); - ASSERT_EQ(state_machine.get_state(), ACUState_e::ACTIVE); + ASSERT_EQ(state_machine.get_state(), ACUState_e::WELDED); + }