-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmppt_algorithm.py
More file actions
37 lines (28 loc) · 902 Bytes
/
Copy pathmppt_algorithm.py
File metadata and controls
37 lines (28 loc) · 902 Bytes
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
"""
mppt_algorithm.py
Perturb & Observe (P&O) MPPT Algorithm.
"""
class PerturbObserveMPPT:
def __init__(self, step_size=0.5, V_init=15.0):
self.step_size = step_size
self.V = V_init
self.P_prev = 0.0
def track(self, panel, G, T_celsius):
P_now = panel.get_power(self.V, G, T_celsius)
if P_now > self.P_prev:
self.V = self.V + self.step_size
else:
self.step_size = -self.step_size
self.V = self.V + self.step_size
self.P_prev = P_now
return self.V, P_now
if __name__ == "__main__":
from solar_panel import SolarPanel
panel = SolarPanel()
mppt = PerturbObserveMPPT(step_size=0.5, V_init=10.0)
G = 1000
T = 25
print("Step | Voltage(V) | Power(W)")
for step in range(40):
V, P = mppt.track(panel, G, T)
print(f"{step:4} | {V:10.2f} | {P:8.2f}")