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