-
Notifications
You must be signed in to change notification settings - Fork 1
/
battery.py
129 lines (90 loc) · 3.51 KB
/
battery.py
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
class BatteryCell:
def __init__(self, max_capacity):
self.max_capacity = max_capacity
self.remaining_capacity = self.max_capacity
def discharge(self, discharge_amount):
self.remaining_capacity -= discharge_amount
def full_recharge(self):
self.remaining_capacity = self.max_capacity
def get_voltage(self):
return (11.1 / 3)
def get_remaining_capacity(self):
return self.remaining_capacity
class BatteryPack:
def __init__(self, cells_in_series, max_capacity, weight):
self.cells_in_series = cells_in_series
self.max_capacity = max_capacity
self.weight = weight
self.cells = []
for _ in range(cells_in_series):
self.cells.append(BatteryCell(max_capacity))
def copy(self):
return BatteryPack(self.cells_in_series, self.max_capacity, self.weight)
def full_recharge(self):
for cell in self.cells:
cell.full_recharge()
def discharge(self, discharge_amount):
for cell in self.cells:
cell.discharge(discharge_amount)
def get_weight(self):
return self.weight
def get_voltage(self):
voltage = 0.0
for cell in self.cells:
voltage += cell.get_voltage()
return voltage
def get_max_capacity(self):
max_capacity = 0.0
for cell in self.cells:
max_capacity += cell.max_capacity
return max_capacity / self.cells_in_series
def get_remaining_capacity(self):
remaining_capacity = 0.0
for cell in self.cells:
remaining_capacity += cell.get_remaining_capacity()
return remaining_capacity / self.cells_in_series
class BatteryBank:
def __init__(self, pack, packs_in_series, packs_in_parallel):
self.packs_in_series = packs_in_series
self.packs_in_parallel = packs_in_parallel
self.bank = []
for _ in range(self.packs_in_parallel):
series_bank = []
for _ in range(self.packs_in_series):
series_bank.append(pack.copy())
self.bank.append(series_bank)
def get_voltage(self):
voltage_sum = 0
for series_pack in self.bank:
for pack in series_pack:
voltage_sum += pack.get_voltage()
return voltage_sum / self.packs_in_parallel
def get_remaining_capacity(self):
remaining_capacity = 0
for series_pack in self.bank:
for pack in series_pack:
remaining_capacity += pack.get_remaining_capacity()
return remaining_capacity / self.packs_in_series
def get_max_capacity(self):
max_capacity = 0
for series_pack in self.bank:
for pack in series_pack:
max_capacity += pack.get_max_capacity()
return max_capacity / self.packs_in_series
def get_charge_percentage(self):
return self.get_remaining_capacity() / self.get_max_capacity()
def get_weight(self):
weight_sum = 0
for series_pack in self.bank:
for pack in series_pack:
weight_sum += pack.get_weight()
return weight_sum
def full_recharge(self):
for series_pack in self.bank:
for pack in series_pack:
pack.full_recharge()
def discharge(self, discharge_amount):
series_discharge_amount = discharge_amount / self.packs_in_parallel
for series_pack in self.bank:
for pack in series_pack:
pack.discharge(series_discharge_amount)