Skip to content

Commit

Permalink
Added min_cell_voltage to SoC CAN msg
Browse files Browse the repository at this point in the history
  • Loading branch information
jhwang04 committed Jul 9, 2024
1 parent 507da84 commit 9325196
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/interfaces/include/AMSInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion lib/interfaces/src/AMSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<STATE_OF_CHARGE_t>(&soc_struct, Pack_STATE_OF_CHARGE_hytech);

last_tick_ = tick;
Expand Down
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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


0 comments on commit 9325196

Please sign in to comment.