Skip to content

Commit

Permalink
feat: set balancing threshold via can and send cell voltage sum and a…
Browse files Browse the repository at this point in the history
…verage
  • Loading branch information
Tonidotpy committed Dec 12, 2023
1 parent 5e10075 commit 33f95bf
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion cellboard/Core/Lib/can
Submodule can updated 37 files
+4 βˆ’4 dbc/bms/bms.dbc
+176 βˆ’176 dbc/inverters/inverters.dbc
+31 βˆ’17 dbc/primary/primary.dbc
+85 βˆ’69 dbc/secondary/secondary.dbc
+37 βˆ’29 dbc/simulator/simulator.dbc
+35 βˆ’39 lib/bms/bms_network.c
+10 βˆ’10 lib/bms/bms_network.h
+718 βˆ’718 lib/inverters/inverters_network.c
+3,576 βˆ’3,576 lib/inverters/inverters_network.h
+2 βˆ’2 lib/inverters/inverters_watchdog.c
+4 βˆ’4 lib/inverters/inverters_watchdog.h
+611 βˆ’135 lib/primary/primary_network.c
+498 βˆ’108 lib/primary/primary_network.h
+23 βˆ’5 lib/primary/primary_watchdog.c
+59 βˆ’55 lib/primary/primary_watchdog.h
+2,166 βˆ’750 lib/secondary/secondary_network.c
+2,444 βˆ’746 lib/secondary/secondary_network.h
+19 βˆ’1 lib/secondary/secondary_watchdog.c
+5 βˆ’1 lib/secondary/secondary_watchdog.h
+461 βˆ’171 lib/simulator/simulator_network.c
+407 βˆ’110 lib/simulator/simulator_network.h
+20 βˆ’11 lib/simulator/simulator_watchdog.c
+3 βˆ’1 lib/simulator/simulator_watchdog.h
+1 βˆ’1 networks/bms/network.json
+51 βˆ’11 networks/primary/network.json
+66 βˆ’68 networks/secondary/network.json
+58 βˆ’23 networks/simulator/network.json
+1 βˆ’1 proto/bms/bms.proto
+2 βˆ’2 proto/bms/bms_proto_interface.h
+841 βˆ’841 proto/inverters/inverters.proto
+249 βˆ’249 proto/inverters/inverters_proto_interface.h
+75 βˆ’58 proto/primary/primary.proto
+60 βˆ’6 proto/primary/primary_proto_interface.h
+80 βˆ’64 proto/secondary/secondary.proto
+74 βˆ’16 proto/secondary/secondary_proto_interface.h
+9 βˆ’1 proto/simulator/simulator.proto
+34 βˆ’5 proto/simulator/simulator_proto_interface.h
2 changes: 1 addition & 1 deletion cellboard/Core/Src/can_comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void can_send(uint16_t id) {

conv_version.canlib_build_time = CANLIB_BUILD_TIME;
conv_version.cellboard_id = cellboard_index;
conv_version.component_build_hash = 1;
conv_version.component_version = 1;

bms_cellboard_version_conversion_to_raw_struct(&raw_version, &conv_version);

Expand Down
34 changes: 13 additions & 21 deletions fenice_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,33 +161,25 @@ static const uint8_t TEMP_SENSOR_ADDRESS_CODING[TEMP_SENSORS_PER_STRIP] = {000,
*/
#define PACK_ENERGY_NOMINAL (CELL_ENERGY_NOMINAL * PACK_CELL_COUNT)

// @section Balancing
#define AIRN_CHECK_TIMEOUT 1000
#define PRECHARGE_TIMEOUT 13000
#define AIRP_CHECK_TIMEOUT 1000
#define CELLBOARD_COMM_TIMEOUT 500

/**
* Maximum voltage delta between cells (mV * 10)
*/
#define BAL_MAX_VOLTAGE_THRESHOLD 500
// Default voltage delta between cells (mV * 10)
#define BAL_DEFAULT_VOLTAGE_THRESHOLD 300
// Maximum voltage delta between cells (mV * 10)
#define BAL_MAX_VOLTAGE_THRESHOLD 2000

/**
* How much does a balancing cycle last (ms)
*/
#define BAL_CYCLE_LENGTH 30000
#define BAL_TIME_ON 1000
#define BAL_TIME_OFF 1000
// How much does a balancing cycle last (ms)
#define BAL_CYCLE_LENGTH 30000
#define BAL_TIME_ON 1000
#define BAL_TIME_OFF 1000

/**
* How much to wait for voltages to stabilize after a balancing cycle [ms]
*/
// How much to wait for voltages to stabilize after a balancing cycle [ms]
#define BAL_COOLDOWN_DELAY 5000

#define DISCHARGE_DUTY_CYCLE (((float)BAL_CYCLE_LENGTH*BAL_TIME_ON/(BAL_TIME_ON+BAL_TIME_OFF))/(BAL_CYCLE_LENGTH+BAL_COOLDOWN_DELAY))

// @section Pre-charge

#define AIRN_CHECK_TIMEOUT 1000
#define PRECHARGE_TIMEOUT 13000
#define AIRP_CHECK_TIMEOUT 1000
#define CELLBOARD_COMM_TIMEOUT 500

/** @brief Multiplexer feedbacks */
typedef enum {
Expand Down
1 change: 1 addition & 0 deletions mainboard/STM32Make.make
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ lib/micro-libs/llist/llist.c \
lib/micro-libs/m95256/m95256.c \
lib/micro-libs/priority-queue/priority_queue.c \
lib/micro-libs/priority-queue/priority_queue_fast_insert.c \
lib/micro-libs/priority-queue/priority_queue_heap.c \
lib/micro-libs/pwm/pwm.c \
lib/micro-libs/timer-utils/timer_utils.c

Expand Down
2 changes: 1 addition & 1 deletion mainboard/Src/bal.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
typedef struct {
voltage_t threshold;
} bal_params;
bal_params bal_params_default = { BAL_MAX_VOLTAGE_THRESHOLD };
bal_params bal_params_default = { BAL_DEFAULT_VOLTAGE_THRESHOLD };

config_t config;
uint8_t is_balancing;
Expand Down
24 changes: 21 additions & 3 deletions mainboard/Src/peripherals/can_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ HAL_StatusTypeDef can_car_send(uint16_t id) {

conv_volts.bus_voltage = CONVERT_VALUE_TO_INTERNAL_VOLTAGE(internal_voltage_get_tsp());
conv_volts.pack_voltage = CONVERT_VALUE_TO_INTERNAL_VOLTAGE(internal_voltage_get_bat());
conv_volts.max_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_max());
conv_volts.min_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_min());

primary_hv_voltage_conversion_to_raw_struct(&raw_volts, &conv_volts);

Expand All @@ -145,6 +143,22 @@ HAL_StatusTypeDef can_car_send(uint16_t id) {
return HAL_ERROR;
tx_header.DLC = data_len;
}
else if (id == PRIMARY_HV_CELL_VOLTAGE_FRAME_ID) {
primary_hv_cell_voltage_t raw_volts = { 0 };
primary_hv_cell_voltage_converted_t conv_volts = { 0 };

conv_volts.max_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_max());
conv_volts.min_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_min());
conv_volts.sum_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_sum());
conv_volts.avg_cell_voltage = CONVERT_VALUE_TO_VOLTAGE(cell_voltage_get_avg());

primary_hv_cell_voltage_conversion_to_raw_struct(&raw_volts, &conv_volts);

int data_len = primary_hv_cell_voltage_pack(buffer, &raw_volts, PRIMARY_HV_CELL_VOLTAGE_BYTE_SIZE);
if (data_len < 0)
return HAL_ERROR;
tx_header.DLC = data_len;
}
else if (id == PRIMARY_HV_CURRENT_FRAME_ID) {
primary_hv_current_t raw_curr = { 0 };
primary_hv_current_converted_t conv_curr = { 0 };
Expand Down Expand Up @@ -908,7 +922,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef * hcan) {

conv_fwd_version.canlib_build_time = conv_version.canlib_build_time;
conv_fwd_version.cellboard_id = conv_version.cellboard_id;
conv_fwd_version.component_build_time = conv_version.component_build_hash;
conv_fwd_version.component_version = conv_version.component_version;

primary_cellboard_version_conversion_to_raw_struct(&raw_fwd_version, &conv_fwd_version);

Expand Down Expand Up @@ -983,6 +997,10 @@ void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) {
}
primary_set_cell_balancing_status_raw_to_conversion_struct(&conv_bal_status, &raw_bal_status);

// Set threshold
uint16_t thr = conv_bal_status.balancing_threshold; // Received threshold is in mV
bal_set_threshold(thr * 10); // Expected threshold is in mV * 10

// Request for balancing start or stop
switch(conv_bal_status.set_balancing_status) {
case PRIMARY_SET_CELL_BALANCING_STATUS_SET_BALANCING_STATUS_ON_CHOICE:
Expand Down
2 changes: 1 addition & 1 deletion mainboard/lib/can
Submodule can updated 37 files
+4 βˆ’4 dbc/bms/bms.dbc
+176 βˆ’176 dbc/inverters/inverters.dbc
+31 βˆ’17 dbc/primary/primary.dbc
+85 βˆ’69 dbc/secondary/secondary.dbc
+37 βˆ’29 dbc/simulator/simulator.dbc
+35 βˆ’39 lib/bms/bms_network.c
+10 βˆ’10 lib/bms/bms_network.h
+718 βˆ’718 lib/inverters/inverters_network.c
+3,576 βˆ’3,576 lib/inverters/inverters_network.h
+2 βˆ’2 lib/inverters/inverters_watchdog.c
+4 βˆ’4 lib/inverters/inverters_watchdog.h
+611 βˆ’135 lib/primary/primary_network.c
+498 βˆ’108 lib/primary/primary_network.h
+23 βˆ’5 lib/primary/primary_watchdog.c
+59 βˆ’55 lib/primary/primary_watchdog.h
+2,166 βˆ’750 lib/secondary/secondary_network.c
+2,444 βˆ’746 lib/secondary/secondary_network.h
+19 βˆ’1 lib/secondary/secondary_watchdog.c
+5 βˆ’1 lib/secondary/secondary_watchdog.h
+461 βˆ’171 lib/simulator/simulator_network.c
+407 βˆ’110 lib/simulator/simulator_network.h
+20 βˆ’11 lib/simulator/simulator_watchdog.c
+3 βˆ’1 lib/simulator/simulator_watchdog.h
+1 βˆ’1 networks/bms/network.json
+51 βˆ’11 networks/primary/network.json
+66 βˆ’68 networks/secondary/network.json
+58 βˆ’23 networks/simulator/network.json
+1 βˆ’1 proto/bms/bms.proto
+2 βˆ’2 proto/bms/bms_proto_interface.h
+841 βˆ’841 proto/inverters/inverters.proto
+249 βˆ’249 proto/inverters/inverters_proto_interface.h
+75 βˆ’58 proto/primary/primary.proto
+60 βˆ’6 proto/primary/primary_proto_interface.h
+80 βˆ’64 proto/secondary/secondary.proto
+74 βˆ’16 proto/secondary/secondary_proto_interface.h
+9 βˆ’1 proto/simulator/simulator.proto
+34 βˆ’5 proto/simulator/simulator_proto_interface.h

0 comments on commit 33f95bf

Please sign in to comment.