From 2eb710941697d9178894815bfcc386f309b20ee1 Mon Sep 17 00:00:00 2001 From: "Jasper v. Blanckenburg" Date: Sun, 25 Jun 2023 15:28:53 +0200 Subject: [PATCH] Revert "Implementation of SoC Prediction" This reverts commit c4543e7e01b5c1c8fa448855ed63b13944a06a2c. --- Core/Inc/shunt_monitoring.h | 2 - Core/Inc/slave_monitoring.h | 1 - Core/Inc/soc_estimation.h | 9 +--- Core/Src/main.c | 15 ++---- Core/Src/shunt_monitoring.c | 5 -- Core/Src/slave_monitoring.c | 11 ----- Core/Src/soc_estimation.c | 95 ++----------------------------------- 7 files changed, 8 insertions(+), 130 deletions(-) diff --git a/Core/Inc/shunt_monitoring.h b/Core/Inc/shunt_monitoring.h index e4152b9..67001c1 100644 --- a/Core/Inc/shunt_monitoring.h +++ b/Core/Inc/shunt_monitoring.h @@ -28,6 +28,4 @@ void shunt_check(); void shunt_handle_can_msg(uint16_t id, const uint8_t *data); -int32_t shunt_getcurrent(); - #endif // INC_SHUNT_MONITORING_H diff --git a/Core/Inc/slave_monitoring.h b/Core/Inc/slave_monitoring.h index 215eec1..6a807e1 100644 --- a/Core/Inc/slave_monitoring.h +++ b/Core/Inc/slave_monitoring.h @@ -49,6 +49,5 @@ void slaves_check(); void slaves_handle_panic(const uint8_t *data); void slaves_handle_status(const uint8_t *data); void slaves_handle_log(const uint8_t *data); -uint16_t slaves_get_minimum_voltage(); #endif // INC_SLAVE_MONITORING_H diff --git a/Core/Inc/soc_estimation.h b/Core/Inc/soc_estimation.h index f341836..83d06c6 100644 --- a/Core/Inc/soc_estimation.h +++ b/Core/Inc/soc_estimation.h @@ -5,14 +5,7 @@ extern uint8_t current_soc; - -#define N_MODELPARAMETERS 11 -#define BATTERYCAPACITYAs (21000.0*3600) //TODO Check if value is correct Cap in Ah * 3600 (Convert to As) - - void soc_init(); -void soc_update(int32_t shunt_current); -void soe_update(); -void soap_update(); +void soc_update(); #endif // INC_SOC_ESTIMATION_H diff --git a/Core/Src/main.c b/Core/Src/main.c index d1170d0..435abfe 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -50,7 +50,6 @@ /* Private variables ---------------------------------------------------------*/ ADC_HandleTypeDef hadc2; - CAN_HandleTypeDef hcan; UART_HandleTypeDef huart1; @@ -92,7 +91,7 @@ static void loop_delay() { */ int main(void) { /* USER CODE BEGIN 1 */ - uint8_t soc_init_complete = 0; + /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ @@ -122,6 +121,7 @@ int main(void) { slaves_init(); shunt_init(); ts_sm_init(); + soc_init(); HAL_GPIO_WritePin(AMS_NERROR_GPIO_Port, AMS_NERROR_Pin, GPIO_PIN_SET); /* USER CODE END 2 */ @@ -138,17 +138,10 @@ int main(void) { slaves_check(); shunt_check(); ts_sm_update(); - if(soc_init_complete){ - soc_update(shunt_getcurrent()); - } - else - { - soc_init(); - soc_init_complete = 1; - } + soc_update(); can_send_status(); - loop_delay(); + loop_delay(); } /* USER CODE END 3 */ } diff --git a/Core/Src/shunt_monitoring.c b/Core/Src/shunt_monitoring.c index 7c3ed0c..8a92045 100644 --- a/Core/Src/shunt_monitoring.c +++ b/Core/Src/shunt_monitoring.c @@ -70,8 +70,3 @@ void shunt_handle_can_msg(uint16_t id, const uint8_t *data) { break; } } - -int32_t shunt_getcurrent() -{ - return shunt_data.current; -} \ No newline at end of file diff --git a/Core/Src/slave_monitoring.c b/Core/Src/slave_monitoring.c index f0d85d4..e3811eb 100644 --- a/Core/Src/slave_monitoring.c +++ b/Core/Src/slave_monitoring.c @@ -136,14 +136,3 @@ void slaves_handle_status(const uint8_t *data) { void slaves_handle_log(const uint8_t *data) { // TODO } - -uint16_t slaves_get_minimum_voltage() -{ - uint16_t minvoltage = 50000; - for(uint8_t idx = 0; idx < N_SLAVES;idx++){ - if(slaves->min_voltage < minvoltage){ - min_voltage = slaves->min_voltage; - } - } - return minvoltage; -} diff --git a/Core/Src/soc_estimation.c b/Core/Src/soc_estimation.c index f9ef758..64f22d5 100644 --- a/Core/Src/soc_estimation.c +++ b/Core/Src/soc_estimation.c @@ -1,103 +1,14 @@ #include "soc_estimation.h" #include -#include "slave_monitoring.h" -#include "stm32f3xx_hal.h" - -//------------------------------------Battery RC and OCV-SoC Parameters----------------------------------------- -//@Note Parameters were obtained by EIS Measurements at the start of the season -//If the errror with this values is to large, consider retesting some cells -const float SOC[N_MODELPARAMETERS]={0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1}; -const float R0[N_MODELPARAMETERS]={0.0089,0.0087,0.0090,0.0087,0.0087,0.0087,0.0088,0.0088,0.0087,0.0088,0.0089}; -const float R1[N_MODELPARAMETERS]={0.0164,0.0063,0.0050,0.0055,0.0051,0.0052,0.0057,0.0048,0.0059,0.0055,0.0061}; -const float C1[N_MODELPARAMETERS]={2.5694,0.2649,0.2876,0.2594,0.2415,0.2360,0.2946,0.2558,0.2818,0.2605,0.2763}; -const float OCV_Data[N_MODELPARAMETERS]={2.762504,3.326231,3.460875,3.57681,3.655326,3.738444,3.835977,3.925841,4.032575,4.078275,4.191449}; - -//--------------------------------------------------------------------------------------------------------------- - - - -float soc_approxparameterbysoc(float,float*, uint8_t); -float soc_approxsocbyocv(float); uint8_t current_soc; -float current_floatsoc; -float batterycapacity; - - -/** - * @brief This Function initializes the SoC Prediction - * @note Because SoC is initalized using the OCV-Curve of the Cell, it is necessary to obtain a valid value - * for the lowest cell voltage before calling this function - */ void soc_init() { - float minvoltage = ((float)slaves_get_minimum_voltage())/1000; - current_floatsoc = soc_approxsocbyocv(minvoltage); - batterycapacity = BATTERYCAPACITYAs*current_floatsoc; - current_soc = (uint8_t)(current_floatsoc*100); -} - -/** - * @brief Update Function for the State of Charge. Call this Function every time the shunt sends a new current - * @note The SoC Prediction works using a Coulomb Counter to track the SoC. Alternativly and maybe more elegant - * would be to track the SoC using the integrated current counter of the shunt. - * @param shunt_current - */ -void soc_update(int32_t shunt_current) { + current_soc = 0; // TODO - static uint32_t lasttick = 0; - - if(lasttick != 0) - { - uint32_t dt = HAL_GetTick() - lasttick; - batterycapacity += batterycapacity + ((float) dt*shunt_current)/1000; - current_floatsoc = batterycapacity/BATTERYCAPACITYAs; - current_soc = (uint8_t) (current_floatsoc*100); - } - - lasttick=HAL_GetTick(); - } -void soe_update() -{ - //TODO +void soc_update() { + // TODO } -void soap_update() -{ - //TODO -} - -float soc_approxparameterbysoc(float soc,float* lut, uint8_t lutlen) -{ - //TODO - return 0; -} - -float soc_approxsocbyocv(float ocv) -{ - - if(ocv < OCV_Data[0]) - return 0; - - if(ocv > OCV_Data[N_MODELPARAMETERS]) - return 1; - //Iterate through OCV Lookup - uint8_t ocvindex = 0; - for(uint8_t i = 0; i < (N_MODELPARAMETERS-1);i++) - { - if((OCV_Data[i] <= ocv) && (OCV_Data[i+1] > ocv)) - { - ocvindex = i; - } - } - - float m = (ocv-OCV_Data[ocvindex])/(OCV_Data[ocvindex+1]-OCV_Data[ocvindex]); - - float soc = (SOC[ocvindex+1] - SOC[ocvindex])*m + SOC[ocvindex]; - - return soc; - - -} \ No newline at end of file