foxBMS-UnitTests  1.0.0
The foxBMS Unit Tests API Documentation
sof.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der
4  * angewandten Forschung e.V. All rights reserved.
5  *
6  * BSD 3-Clause License
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * We kindly request you to use one or more of the following phrases to refer
31  * to foxBMS in your hardware, software, documentation or advertising
32  * materials:
33  *
34  * ″This product uses parts of foxBMS®″
35  *
36  * ″This product includes parts of foxBMS®″
37  *
38  * ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file sof.h
44  * @author foxBMS Team
45  * @date 2020-10-07 (date of creation)
46  * @updated 2020-10-07 (date of last update)
47  * @ingroup APPLICATION
48  * @prefix SOX
49  *
50  * @brief Header for SOX module, responsible for current derating calculation
51  *
52  */
53 
54 #ifndef FOXBMS__SOF_H_
55 #define FOXBMS__SOF_H_
56 
57 /*========== Includes =======================================================*/
58 #include "sof_cfg.h"
59 
60 /*========== Macros and Definitions =========================================*/
61 /**
62  * struct definition for 4 different values: in two current directions (charge,
63  * discharge) for two use cases (peak and continuous)
64  */
65 typedef struct SOF_CURRENT_LIMITS {
66  float continuousChargeCurrent_mA; /*!< maximum current for continues charging */
67  float peakChargeCurrent_mA; /*!< maximum current for peak charging */
68  float continuousDischargeCurrent_mA; /*!< maximum current for continues discharging */
69  float peakDischargeCurrent_mA; /*!< maximum current for peak discharging */
71 
72 /**
73  * struct definition for calculating the linear SOF curve. The SOF curve is
74  * voltage, temperature and charge/discharge dependent.
75  */
76 typedef struct SOF_CURVE {
77  float slopeLowTemperatureDischarge; /*!< low temperature dependent derating slope for discharge current */
78  float offsetLowTemperatureDischarge; /*!< discharge current offset for low temperature dependent derating */
79  float slopeHighTemperatureDischarge; /*!< high temperature dependent derating slope for discharge current */
80  float offsetHighTemperatureDischarge; /*!< discharge current offset for high temperature dependent derating */
81 
82  float slopeLowTemperatureCharge; /*!< low temperature dependent derating slope for charge current */
83  float offsetLowTemperatureCharge; /*!< charge current offset for low temperature dependent derating */
84  float slopeHighTemperatureCharge; /*!< high temperature dependent derating slope for charge current */
85  float offsetHighTemperatureCharge; /*!< charge current offset for high temperature dependent derating */
86 
87  float slopeUpperCellVoltage; /*!< upper cell voltage derating slope for charge and discharge current */
88  float offsetUpperCellVoltage; /*!< charge/discharge current offset for upper voltage derating */
89  float slopeLowerCellVoltage; /*!< lower cell voltage derating slope for charge and discharge current */
90  float offsetLowerCellVoltage; /*!< charge/discharge current offset for lower voltage derating */
92 
93 /*========== Extern Constant and Variable Declarations ======================*/
94 
95 /*========== Extern Function Prototypes =====================================*/
96 /**
97  * @brief initializes the area for SOF (where derating starts and is fully
98  * active).
99  * @details Pseudocode for linear function parameter extraction with 2 points:
100  * - slope = (y2 - y1) / (x2-x1)
101  * - offset = y1 - (slope) * x1
102  * - function y= slope * x + offset
103  */
104 extern void SOF_Init(void);
105 
106 /**
107  * @brief triggers SOF calculation
108  * @details TODO
109  */
110 extern void SOF_Calculation(void);
111 
112 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
113 #ifdef UNITY_UNIT_TEST
115  int16_t minimumCellVoltage_mV,
116  int16_t maximumCellVoltage_mV,
117  SOF_CURRENT_LIMITS_s *pAllowedVoltageBasedCurrent,
118  const SOF_CONFIG_s *pConfigLimitValues,
119  SOF_CURVE_s *pCalculatedSofCurves);
121  int16_t minimumCellTemperature_ddegC,
122  int16_t maximumCellTemperature_ddegC,
123  SOF_CURRENT_LIMITS_s *pAllowedTemperatureBasedCurrent,
124  const SOF_CONFIG_s *pConfigLimitValues,
125  SOF_CURVE_s *pCalculatedSofCurves);
127  SOF_CURRENT_LIMITS_s voltageBasedLimits,
128  SOF_CURRENT_LIMITS_s temperatureBasedLimits);
129 #endif /* UNITY_UNIT_TEST */
130 #endif /* FOXBMS__SOF_H_ */
SOF_CURRENT_LIMITS
Definition: sof.h:65
SOF_Init
void SOF_Init(void)
initializes the area for SOF (where derating starts and is fully active).
Definition: sof.c:342
SOF_CURVE::offsetHighTemperatureDischarge
float offsetHighTemperatureDischarge
Definition: sof.h:80
SOF_CURVE::offsetUpperCellVoltage
float offsetUpperCellVoltage
Definition: sof.h:88
SOF_CURVE::offsetHighTemperatureCharge
float offsetHighTemperatureCharge
Definition: sof.h:85
SOF_CURVE::slopeHighTemperatureDischarge
float slopeHighTemperatureDischarge
Definition: sof.h:79
SOF_CURRENT_LIMITS_s
struct SOF_CURRENT_LIMITS SOF_CURRENT_LIMITS_s
TEST_SOF_CalculateTemperatureBasedCurrentLimit
void TEST_SOF_CalculateTemperatureBasedCurrentLimit(int16_t minimumCellTemperature_ddegC, int16_t maximumCellTemperature_ddegC, SOF_CURRENT_LIMITS_s *pAllowedTemperatureBasedCurrent, const SOF_CONFIG_s *pConfigLimitValues, SOF_CURVE_s *pCalculatedSofCurves)
Definition: sof.c:526
SOF_CURVE::slopeLowTemperatureCharge
float slopeLowTemperatureCharge
Definition: sof.h:82
SOF_CURVE::offsetLowTemperatureCharge
float offsetLowTemperatureCharge
Definition: sof.h:83
SOF_CURVE::slopeLowerCellVoltage
float slopeLowerCellVoltage
Definition: sof.h:89
SOF_CURVE::slopeLowTemperatureDischarge
float slopeLowTemperatureDischarge
Definition: sof.h:77
TEST_SOF_MinimumOfTwoSofValues
SOF_CURRENT_LIMITS_s TEST_SOF_MinimumOfTwoSofValues(SOF_CURRENT_LIMITS_s voltageBasedLimits, SOF_CURRENT_LIMITS_s temperatureBasedLimits)
Definition: sof.c:539
TEST_SOF_CalculateVoltageBasedCurrentLimit
void TEST_SOF_CalculateVoltageBasedCurrentLimit(int16_t minimumCellVoltage_mV, int16_t maximumCellVoltage_mV, SOF_CURRENT_LIMITS_s *pAllowedVoltageBasedCurrent, const SOF_CONFIG_s *pConfigLimitValues, SOF_CURVE_s *pCalculatedSofCurves)
Definition: sof.c:513
SOF_CURVE::offsetLowerCellVoltage
float offsetLowerCellVoltage
Definition: sof.h:90
SOF_CURVE
Definition: sof.h:76
SOF_CURRENT_LIMITS::continuousDischargeCurrent_mA
float continuousDischargeCurrent_mA
Definition: sof.h:68
sof_cfg.h
Header for SOF configuration.
SOF_CURVE::offsetLowTemperatureDischarge
float offsetLowTemperatureDischarge
Definition: sof.h:78
SOF_Calculation
void SOF_Calculation(void)
triggers SOF calculation
Definition: sof.c:358
SOF_CURVE::slopeUpperCellVoltage
float slopeUpperCellVoltage
Definition: sof.h:87
SOF_CURVE::slopeHighTemperatureCharge
float slopeHighTemperatureCharge
Definition: sof.h:84
SOF_CONFIG
Definition: sof_cfg.h:321
SOF_CURRENT_LIMITS::peakDischargeCurrent_mA
float peakDischargeCurrent_mA
Definition: sof.h:69
SOF_CURVE_s
struct SOF_CURVE SOF_CURVE_s
SOF_CURRENT_LIMITS::continuousChargeCurrent_mA
float continuousChargeCurrent_mA
Definition: sof.h:66
SOF_CURRENT_LIMITS::peakChargeCurrent_mA
float peakChargeCurrent_mA
Definition: sof.h:67