-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathChargeAlgorithmCCCVCurrent.cc
97 lines (85 loc) · 3.36 KB
/
ChargeAlgorithmCCCVCurrent.cc
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#include "ChargeAlgorithmCCCVCurrent.h"
/**
* Constructor, calculates the eulerConstant, which provides the system precision
*/
ChargeAlgorithmCCCVCurrent::ChargeAlgorithmCCCVCurrent(double current, int cccvShiftPercentage)
{
this->current = current;
this->cccvShiftPercentage = cccvShiftPercentage;
}
/**
* @return chargeAmount in mAh
*/
double ChargeAlgorithmCCCVCurrent::calculateChargeAmount(double remaining, double capacity, double seconds)
{
bool inCcStage = remaining < capacity / 100 * cccvShiftPercentage;
double stageCurrent = 0;
if (inCcStage) {
stageCurrent = current;
}
else {
double ccStageCharge = capacity / 100 * cccvShiftPercentage;
double cvStageCharge = capacity - ccStageCharge;
double cvStageTime = getCVTime(capacity);
double cvStageProgressSeconds = cvStageTime / cvStageCharge * (remaining - ccStageCharge);
double currentDropOffsetFactor = 0.95;
stageCurrent = current - current / cvStageTime * ((cvStageProgressSeconds + seconds / 2) * currentDropOffsetFactor);
}
double amount = stageCurrent * 1000 * seconds / 3600;
return amount;
}
/**
* @return chargeTime in seconds
*/
double ChargeAlgorithmCCCVCurrent::calculateChargeTime(double remaining, double capacity, double targetPercentage)
{
double remainingPercentage = 100 / capacity * remaining;
double timeInCC = 0;
double timeInCV = 0;
if (targetPercentage <= remainingPercentage) return 0;
if (remainingPercentage < cccvShiftPercentage) {
if (targetPercentage <= cccvShiftPercentage) {
timeInCC = getCCTime(capacity) / cccvShiftPercentage * (targetPercentage - remainingPercentage);
}
else {
timeInCC = getCCTime(capacity) / cccvShiftPercentage * (cccvShiftPercentage - remainingPercentage);
//TODO not correct
timeInCV = getCVTime(capacity) / (100 - cccvShiftPercentage) * (targetPercentage - cccvShiftPercentage);
}
}
else {
//TODO not correct
timeInCV = getCVTime(capacity) / (100 - cccvShiftPercentage) * (targetPercentage - remainingPercentage);
}
return timeInCC + timeInCV;
}
double ChargeAlgorithmCCCVCurrent::getFastChargePercentage(double maxCapacity)
{
return cccvShiftPercentage;
}
double ChargeAlgorithmCCCVCurrent::getCCTime(double capacity)
{
double ccStageCharge = capacity / 100 * cccvShiftPercentage;
double seconds = (ccStageCharge / (current * 1000)) * 3600;
return seconds;
}
double ChargeAlgorithmCCCVCurrent::getCVTime(double capacity)
{
double cvStageCharge = capacity / 100 * (100 - cccvShiftPercentage);
double seconds = (cvStageCharge / (current / 2 * 1000)) * 3600;
return seconds;
}