From 4b1a76541d3b0d3d9ace2bf039b3cd2608ebfe89 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sun, 9 Feb 2025 11:00:30 +0100 Subject: [PATCH] Initial commit --- README.md | 0 mppt.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 README.md create mode 100644 mppt.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/mppt.py b/mppt.py new file mode 100644 index 0000000..20a74c9 --- /dev/null +++ b/mppt.py @@ -0,0 +1,61 @@ +import random + +from matplotlib import pyplot as plot +import numpy as np + +def calc_p(U0, Ri, Rl): + I = U0 / (Ri + Rl) + Ul = I * Rl + P = Ul * I + + return P + + +U0 = 10 +Ri = 3.14 +Rl_min = 0.1 +Rl_max = 10. +Rl_step_start = 1 +Rl_step_stop = 0.01 + +Rl = np.linspace(Rl_min, Rl_max, 100, dtype=float) + +# -------------------------------------------------- +# MPPT search +Rl_s = np.random.uniform()*(Rl_max - Rl_min) + Rl_min +Rl_step = Rl_step_start +dir = "inc" +dir_last = dir +while Rl_step > Rl_step_stop: + p0 = calc_p(U0, Ri, Rl_s) + p1 = p0 + if "inc" in dir: + Rl_s = min(Rl_max, Rl_s + Rl_step) + p1 = calc_p(U0, Ri, Rl_s) + if p0 > p1: + if 'inc' in dir_last: + Rl_step /= 2 + dir = 'dec' + + elif "dec" in dir: + Rl_s = max(Rl_min, Rl_s - Rl_step) + p1 = calc_p(U0, Ri, Rl_s) + if p0 > p1: + if 'dec' in dir_last: + Rl_step /= 2 + dir = 'inc' + + dir_last = dir + print(f"p1 = {p1}, Rl_s = {Rl_s}, Rl_step {Rl_step}") + +# -------------------------------------------------- + +P = calc_p(U0, Ri, Rl) +plot.plot(Rl, P) + +plot.ylabel("Power [W]") +plot.xlabel("RL [Ohms]") +plot.title("Power vs RL") +plot.legend("RL [Ohms]") +plot.grid() +plot.show()