From 93251964f3a2ed9b148b7150b5acad1b888d1458 Mon Sep 17 00:00:00 2001 From: Justin Hwang Date: Wed, 10 Jul 2024 01:39:28 +0900 Subject: [PATCH] Added min_cell_voltage to SoC CAN msg --- lib/interfaces/include/AMSInterface.h | 8 +++++++- lib/interfaces/src/AMSInterface.cpp | 6 +++++- platformio.ini | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/interfaces/include/AMSInterface.h b/lib/interfaces/include/AMSInterface.h index 7f412272f..ebd0aecbd 100644 --- a/lib/interfaces/include/AMSInterface.h +++ b/lib/interfaces/include/AMSInterface.h @@ -42,7 +42,8 @@ class AMSInterface charge_(0.0f), SoC_(0.0f), has_initialized_charge_(false), - has_received_bms_voltage_(false) {}; + has_received_bms_voltage_(false), + bms_low_voltage_at_init_(0.0f) {}; /* Overloaded constructor that only takes in software OK pin and uses default voltages and temp*/ AMSInterface(CANBufferType *msg_output_queue, int sw_ok_pin): @@ -260,6 +261,11 @@ class AMSInterface */ unsigned long timestamp_start_; + /** + * Stores the minimum cell voltage at initialization. + */ + float bms_low_voltage_at_init_; + // Check if lowest cell temperature is below threshold bool is_below_pack_charge_critical_low_thresh(); diff --git a/lib/interfaces/src/AMSInterface.cpp b/lib/interfaces/src/AMSInterface.cpp index ceccbaf88..002060e9f 100644 --- a/lib/interfaces/src/AMSInterface.cpp +++ b/lib/interfaces/src/AMSInterface.cpp @@ -78,7 +78,10 @@ float AMSInterface::get_filtered_min_cell_voltage() { float AMSInterface::initialize_charge() { int i = 0; - while (HYTECH_low_voltage_ro_fromS(bms_voltages_.low_voltage_ro) - VOLTAGE_LOOKUP_TABLE[i] < 0) { + float lowest_voltage = HYTECH_low_voltage_ro_fromS(bms_voltages_.low_voltage_ro); + bms_low_voltage_at_init_ = lowest_voltage; + + while (lowest_voltage - VOLTAGE_LOOKUP_TABLE[i] < 0) { i++; } charge_ = ( (100 - i) / 100.0) * MAX_PACK_CHARGE; @@ -140,6 +143,7 @@ void AMSInterface::tick(const SysTick_s &tick) { STATE_OF_CHARGE_t soc_struct; soc_struct.charge_percentage_ro = HYTECH_charge_percentage_ro_toS(SoC_); soc_struct.charge_coulombs_ro = HYTECH_charge_coulombs_ro_toS(charge_); + soc_struct.min_cell_voltage_at_initializati_ro = HYTECH_min_cell_voltage_at_initializati_ro_toS(bms_low_voltage_at_init_); enqueue_new_CAN(&soc_struct, Pack_STATE_OF_CHARGE_hytech); last_tick_ = tick; diff --git a/platformio.ini b/platformio.ini index 645a61380..6fae04347 100644 --- a/platformio.ini +++ b/platformio.ini @@ -55,7 +55,7 @@ lib_deps = https://github.com/RCMast3r/spi_libs#2214fee https://github.com/tonton81/FlexCAN_T4#b928bcb https://github.com/RCMast3r/hytech_can#testing_new_inv_ids - https://github.com/hytech-racing/HT_CAN/releases/download/99/can_lib.tar.gz + https://github.com/hytech-racing/HT_CAN/releases/download/107/can_lib.tar.gz git+ssh://git@github.com/hytech-racing/CASE_lib.git#v49 [env:test_interfaces] @@ -82,7 +82,7 @@ lib_deps = https://github.com/hytech-racing/shared_firmware_interfaces.git#feature/thermistor-template https://github.com/hytech-racing/shared_firmware_systems.git#af96a63 https://github.com/RCMast3r/spi_libs#2214fee - https://github.com/hytech-racing/HT_CAN/releases/latest/download/can_lib.tar.gz + https://github.com/hytech-racing/HT_CAN/releases/download/107/can_lib.tar.gz git+ssh://git@github.com/hytech-racing/CASE_lib.git#v49