-
Notifications
You must be signed in to change notification settings - Fork 0
/
SOC.h
75 lines (73 loc) · 2.15 KB
/
SOC.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
struct SocDataStruct {
float* voltageDataPtr;
float* currentDataPtr;
float* SOCDataPtr;
float* maxCurrDataPtr;
float* minCurrDataPtr;
float* maxVoltDataPtr;
float* minVoltDataPtr;
float* maxSOC;
float* minSOC;
bool* maxCurrFlag;
bool* minCurrFlag;
bool* maxVolFlag;
bool* minVolFlag;
bool* maxSOCFlag;
bool* minSOCFlag;
};
typedef struct SocDataStruct SocData;
float Rbatt = 0.5;
void socTaskFnc(void* arg)
{
SocData* localDataPtr = arg;
//Calculating SOC based on the voltage range
float volt = *(localDataPtr->voltageDataPtr);
float Curr = *(localDataPtr->currentDataPtr);
float voltOpenCircuit = volt + Curr*Rbatt;
float SOC = 0.0;
if (volt >= 200.0 && volt <= 250.0) {
SOC = 0;
} else if (volt > 250.0 && volt <= 300.0) {
SOC = (voltOpenCircuit - 250.0) * 2/5;
} else if (volt > 300.0 && volt <= 350.0) {
SOC = (voltOpenCircuit - 300.0) * 6/5;
} else if (volt > 350.0 && volt <= 400.0) {
SOC = (voltOpenCircuit - 350.0) * 2/5;
}
*(localDataPtr->SOCDataPtr) = SOC;
//Setting the max and min values for each measurment
//Voltage
float maxVolt = *(localDataPtr->maxVoltDataPtr);
float minVolt = *(localDataPtr->minVoltDataPtr);
if (volt > maxVolt) {
*(localDataPtr->maxVoltDataPtr) = volt;
*(localDataPtr->maxVolFlag) = true;
}
if (volt < minVolt) {
*(localDataPtr->minVoltDataPtr) = volt;
*(localDataPtr->minVolFlag) = true;
}
//current
float curr = *(localDataPtr->currentDataPtr);
float maxCurr = *(localDataPtr->maxCurrDataPtr);
float minCurr = *(localDataPtr->minCurrDataPtr);
if (curr > maxCurr) {
*(localDataPtr->maxCurrDataPtr) = curr;
*(localDataPtr->maxCurrFlag) = true;
}
if (curr < minCurr) {
*(localDataPtr->minCurrDataPtr) = curr;
*(localDataPtr->minCurrFlag) = true;
}
//SOC
float maxSOC = *(localDataPtr->maxSOC);
float minSOC = *(localDataPtr->minSOC);
if (SOC > maxSOC) {
*(localDataPtr->maxSOC) = SOC;
*(localDataPtr->maxSOCFlag) = true;
}
if (SOC < minSOC) {
*(localDataPtr->minSOC) = SOC;
*(localDataPtr->minSOCFlag) = true;
}
};