Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
0c56772
added ocv soc lookup table
SoorajTharumia Nov 2, 2025
02c3610
Merge remote-tracking branch 'origin' into feat/ocv-soc-table
SoorajTharumia Nov 9, 2025
8a16885
addded ht08 ocv soc table for now
SoorajTharumia Nov 10, 2025
107ffb9
added basic functionality for ocv-soc table
SoorajTharumia Nov 14, 2025
d74a12f
fixes made
SoorajTharumia Nov 14, 2025
fac9cfa
fixed compile errors
SoorajTharumia Nov 14, 2025
1ee388d
updated tests for table with new field
SoorajTharumia Nov 14, 2025
c92f59f
fixed issues and
SoorajTharumia Nov 14, 2025
adb74f6
did interpolation for data and return type
SoorajTharumia Nov 16, 2025
cab6836
Merge remote-tracking branch 'origin' into feat/ocv-soc-table
SoorajTharumia Jan 8, 2026
0240af8
merge changed
SoorajTharumia Jan 8, 2026
1ec8e53
removed templating format
SoorajTharumia Jan 8, 2026
72fba2a
ekf for soc tracking
SoorajTharumia Jan 13, 2026
3e6e08c
fixed typo
SoorajTharumia Jan 13, 2026
de95a7a
added tests and improved kalman filter
SoorajTharumia Jan 14, 2026
4571903
removed reference to old member variable
SoorajTharumia Jan 14, 2026
9ec504d
tests updated
SoorajTharumia Jan 14, 2026
0b9c9b2
clang tidy
SoorajTharumia Jan 15, 2026
04f8228
acu constants
SoorajTharumia Jan 15, 2026
fe6ad83
replaced acu constants with num cells
SoorajTharumia Jan 15, 2026
99322ba
added comments to elaborate on math in update
SoorajTharumia Jan 19, 2026
dc42347
initialization of state and covariance matrix in constructor
SoorajTharumia Jan 19, 2026
8a1cefe
tuned process and measurement noise values based on sim
SoorajTharumia Jan 29, 2026
a98111f
changed tests to pass (simulation > tests so fine)
SoorajTharumia Jan 29, 2026
24f6b8e
added soc can message for dash implementation
SoorajTharumia Feb 1, 2026
242e939
Merge remote-tracking branch 'origin' into feat/ocv-soc-table
SoorajTharumia Feb 10, 2026
194229b
fixed negative current issue
SoorajTharumia Feb 17, 2026
4963562
nvm negative current was right
SoorajTharumia Feb 17, 2026
6bd1330
Merge remote-tracking branch 'origin' into feat/ocv-soc-table
SoorajTharumia Mar 11, 2026
07b5938
comment out tests from main commit
SoorajTharumia Mar 11, 2026
f17334a
Merge remote-tracking branch 'origin' into feat/ocv-soc-table
SoorajTharumia Apr 1, 2026
7b6d5b7
joseph form kalman filter, moved vars around
SoorajTharumia Apr 2, 2026
f67877d
linter
SoorajTharumia Apr 2, 2026
2e00150
added back soc test
SoorajTharumia Apr 2, 2026
71d3ea4
private to public var
SoorajTharumia Apr 2, 2026
1035da6
changed to minimum cell voltage for EKF
SoorajTharumia Apr 3, 2026
9880198
logical changes to soc
SoorajTharumia Apr 15, 2026
fe4927f
nit
SoorajTharumia Apr 15, 2026
a97ec52
nit
SoorajTharumia Apr 15, 2026
496b194
found good data for ocv-soc table
SoorajTharumia Apr 15, 2026
9aac820
Merge branch 'main' into feat/ocv-soc-table
songyueli Apr 15, 2026
25ed2e4
modify constants
songyueli Apr 15, 2026
83e2d50
fixes
songyueli Apr 16, 2026
bbbc870
Merge branch 'main' into feat/ocv-soc-table
songyueli Apr 16, 2026
e312e0b
fixed em to use correct voltage and current
SoorajTharumia Apr 16, 2026
00e88f8
clean
songyueli Apr 16, 2026
a2a3ca9
add
songyueli Apr 16, 2026
ebd24c8
increase imd startup time to 5 seconds
songyueli Apr 16, 2026
e0cf48a
spi dma max adc
songyueli Apr 16, 2026
4772bc1
aggressive spi dma on max 1148
songyueli Apr 16, 2026
364e839
cleanup comment
songyueli Apr 16, 2026
2a294ad
read correct current
songyueli Apr 16, 2026
4b25e7d
add fix
songyueli Apr 16, 2026
2ef30e7
added not use channel
songyueli Apr 16, 2026
e4b5dd9
clean comment
songyueli Apr 16, 2026
e23cdef
decrease r_v1 to rely less on voltage sensor
SoorajTharumia Apr 17, 2026
7df5265
tuned stabilized current threshold
SoorajTharumia Apr 18, 2026
3972ff4
fixed timing issue with voltage data freshness
SoorajTharumia Apr 18, 2026
92d0ff4
to test
songyueli Apr 18, 2026
983d2ba
clean
songyueli Apr 18, 2026
d2b91fc
SoC default -1
songyueli Apr 18, 2026
9f576b2
formatting
songyueli Apr 18, 2026
f806c1f
Merge branch 'main' into feat/ocv-soc-table
songyueli Apr 20, 2026
1d1e395
fixed sign error and adjusted r_v1
SoorajTharumia Apr 21, 2026
d30786e
fixed test for new table
SoorajTharumia Apr 21, 2026
fd752be
ahh
songyueli Apr 22, 2026
1e98036
repl
songyueli Apr 22, 2026
a18b2dd
move
songyueli Apr 22, 2026
bccd9e7
move spi end transaction
songyueli Apr 22, 2026
1b680c5
fix
songyueli Apr 22, 2026
7c9c9b5
lock in
songyueli Apr 22, 2026
4205937
fix
songyueli Apr 26, 2026
8e6597f
cleanup
songyueli May 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions include/ACU_Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +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 = 50; // Volts
constexpr const volt TS_ISOLATION_VOLTAGE = 100; // Volts
}

namespace ACUInterfaces {
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace ACUInterfaces {

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 SW_NOT_OK_PIN = 5; // should be HIGH by default, and then set LOW after traversing state machine
constexpr const size_t SW_NOT_OK_PIN = 5; // should be HIGH by default, and then set LOW after traversing state machine
constexpr const size_t N_FAULTED_STATE_PIN = 6; // > Input to Safety Light, true when teensy is not in FAULT state

constexpr const size_t BSPD_CURRENT_PIN = 15;
Expand Down Expand Up @@ -100,7 +100,6 @@ namespace ACUInterfaces {

constexpr const float BIT_RESOLUTION = 4095.0F;
}

namespace ACUConstants
{
constexpr size_t NUM_CELLS = 126;
Expand All @@ -119,42 +118,42 @@ namespace ACUConstants
/* Task Times */
constexpr uint32_t TICK_SM_PERIOD_US = 1000UL; // 1 000 us = 1000 Hz
constexpr uint32_t TICK_SM_PRIORITY = 9;
constexpr uint32_t KICK_WATCHDOG_PERIOD_US = 5000UL; // 5000 us = 200 Hz
constexpr uint32_t KICK_WATCHDOG_PERIOD_US = 4000UL; // 10 000 us = 100 Hz
constexpr uint32_t WATCHDOG_PRIORITY = 1;
constexpr uint32_t SAMPLE_BMS_PERIOD_US = 10000UL; // 10 000 us = 100 Hz (since we are reading by group)
constexpr uint32_t SAMPLE_BMS_PERIOD_US = 20000UL; // 5 000 us = 200 Hz (since we are reading by group)
constexpr uint32_t SAMPLE_BMS_PRIORITY = 2;
constexpr uint32_t EVAL_ACC_PERIOD_US = 20000UL; // 20 000 us = 50 Hz
constexpr uint32_t EVAL_ACC_PERIOD_US = 20000UL; // 20 000 us = 50 Hz (problem for soc if this is running faster than voltage)
constexpr uint32_t EVAL_ACC_PRIORITY = 10;
constexpr uint32_t WRITE_CELL_BALANCE_PERIOD_US = 100000UL; // 100 000 us = 10 Hz
constexpr uint32_t WRITE_CELL_BALANCE_PRIORITY = 15;
constexpr uint32_t ALL_DATA_ETHERNET_PERIOD_US = 100000UL; // 100 000 us = 10 Hz
constexpr uint32_t ALL_DATA_ETHERNET_PRIORITY = 5;
constexpr uint32_t CORE_DATA_ETHERNET_PERIOD_US = 4000UL; // 20 000 us = 50 Hz
constexpr uint32_t CORE_DATA_ETHERNET_PERIOD_US = 8000UL; // 8 000 us = 125 Hz
constexpr uint32_t CORE_DATA_ETHERNET_PRIORITY = 4;

constexpr uint32_t SAMPLE_ADC_PRIORITY = 20;
constexpr uint32_t SAMPLE_ADC_PERIOD_US = 5000UL; // 10 000 us = 100 Hz
constexpr uint32_t SAMPLE_ADC_PRIORITY = 11;
constexpr uint32_t SAMPLE_ADC_PERIOD_US = 1000UL; // 1 000 us = 1000 Hz

constexpr uint32_t CCU_SEND_PERIOD_US = 100000UL; // 100 000 us = 10 Hz
constexpr uint32_t CCU_SEND_PRIORITY = 11;
constexpr uint32_t CCU_SEND_PRIORITY = 14;
constexpr uint32_t ACU_OK_CAN_PERIOD_US = 50000UL; // 50 000 us = 20 Hz
constexpr uint32_t ACU_OK_CAN_PRIORITY = 3;
constexpr uint32_t CCU_SEND_A_PERIOD_US = 100000UL; // 100 000 us = 10 Hz
constexpr uint32_t CCU_SEND_A_PRIORITY = 12;
constexpr uint32_t CCU_SEND_B_PERIOD_US = 100000UL; // 100 000 us = 10 Hz
constexpr uint32_t CCU_SEND_B_PRIORITY = 13;
constexpr uint32_t EM_MEASUREMENT_SEND_PERIOD_US = 4000UL; // 10 000 us = 100 Hz
constexpr uint32_t EM_MEASUREMENT_SEND_PERIOD_US = 4000UL; // 4 000 us = 250 Hz
constexpr uint32_t EM_MEASUREMENT_SEND_PRIORITY = 6;

constexpr uint32_t SEND_CAN_PERIOD_US = 4000UL; // 10 000 us = 100 Hz
constexpr uint32_t SEND_CAN_PERIOD_US = 4000UL; // 40 000 us = 250 Hz
constexpr uint32_t SEND_CAN_PRIORITY = 8;
constexpr uint32_t RECV_CAN_PERIOD_US = 10000UL; // 10 000 us = 100 Hz
constexpr uint32_t RECV_CAN_PERIOD_US = 50000UL; // 50 000 us = 20 Hz
constexpr uint32_t RECV_CAN_PRIORITY = 7;

constexpr uint32_t DEBUG_PRINT_PERIOD_US = 250000UL; // 250 000 us = 4 Hz
constexpr uint32_t DEBUG_PRINT_PRIORITY = 20;

constexpr uint32_t IDLE_SAMPLE_PERIOD_US = 200UL; // 1 000 us = 100 Hz
constexpr uint32_t IDLE_SAMPLE_PERIOD_US = 1000UL; // 1 000 us = 1000 Hz
constexpr uint32_t IDLE_SAMPLE_PRIORITY = 0;

/* Message Interface */
Expand Down
2 changes: 1 addition & 1 deletion lib/interfaces/include/ADCInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace adc_default_parameters
constexpr const float TEENSY41_MAX_DIGITAL_READ_VOLTAGE_THRESH = 2.8F;
constexpr const float SHUTDOWN_VOLTAGE_DIGITAL_THRESHOLD = 12.0F;

constexpr const uint32_t IMD_STARTUP_TIME = 2000;
constexpr const uint32_t IMD_STARTUP_TIME = 10000;
constexpr const float TEENSY41_MAX_INPUT_VOLTAGE = 3.3F;

constexpr int MAX114X_VERSION = 8;
Expand Down
25 changes: 21 additions & 4 deletions lib/interfaces/include/BMSDriverGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cstdint>
#include "etl/optional.h"
#include <numeric>
#include <atomic>

#include "etl/singleton.h"

Expand All @@ -29,7 +30,7 @@ enum class SPIState_e
IDLE = 0,
WAIT_WRITE_COMPLETE = 1,
WAIT_POLL_ADC_COMPLETE = 2,
START_CONVERSION = 3,
START_CONVERSIONS = 3,
WAIT_CONVERSION = 4,
WAIT_READ_COMPLETE = 5,
};
Expand Down Expand Up @@ -95,8 +96,8 @@ namespace bms_driver_defaults
constexpr const uint16_t OVER_VOLTAGE_THRESHOLD = 2625; // 4.2V (datasheet formula) Comparison Voltage = VOV • 16 • 100μV
constexpr const uint16_t GPIO_ENABLE = 0x1F;
constexpr const uint16_t CRC15_POLY = 0x4599; // Used for calculating the PEC table for LTC6811
constexpr const uint16_t CV_ADC_CONVERSION_TIME_US = 2000;
constexpr const uint16_t GPIO_ADC_CONVERSION_TIME_US = 2000;
constexpr const uint16_t CV_ADC_CONVERSION_TIME_US = 1200;
constexpr const uint16_t GPIO_ADC_CONVERSION_TIME_US = 1200;
constexpr const float CV_ADC_LSB_VOLTAGE = 0.0001f; // Cell voltage ADC resolution: 100μV per LSB (1/10000 V)
}

Expand Down Expand Up @@ -281,6 +282,8 @@ class BMSDriverGroup
*/
const char* get_current_read_group_name();

const char* get_spi_state_name();

/**
* @brief Get validity status for all chips from last read
* @return Const reference to validity data array (no copy overhead)
Expand Down Expand Up @@ -324,11 +327,20 @@ class BMSDriverGroup
return _config;
}

/**
* @brief Runs atomic fetch and clear so it does everything in one atomic operation on the new voltage for fresh flag
* @return true if the voltage data is fresh (only happens once per good cycle)
* @return false if the voltage data is not fresh
*/
bool check_clear_voltage_ready() {
return _new_voltage_data_ready.exchange(false, std::memory_order_acquire);
}

private:

ReadGroup_e _current_read_group = ReadGroup_e::CV_GROUP_A;

SPIState_e _spi_state = SPIState_e::IDLE;
SPIState_e _spi_state = SPIState_e::START_CONVERSIONS;

/**
* PEC:
Expand Down Expand Up @@ -390,6 +402,8 @@ class BMSDriverGroup
*/
void _start_cell_voltage_ADC_conversion();

void _init_adc_conversion();

/**
* Writes command to start GPIO ADC conversion
* @post packaged data transfered over SPI, need to delay before we can read
Expand Down Expand Up @@ -523,6 +537,9 @@ class BMSDriverGroup
array<uint8_t, cmd_and_data_buffer_size> _rx_read_buffer;
array<uint8_t, cmd_only_buffer_size> _tx_write_buffer;
array<uint8_t, cmd_only_buffer_size> _rx_write_buffer;

// Says if voltage data is fresh for the state of charge estimator
std::atomic<bool> _new_voltage_data_ready{false};
};

template <size_t num_chips, size_t num_chip_selects, LTC6811_Type_e chip_type>
Expand Down
Loading
Loading