From 26775f57dfe52923eb9a5751e4a69a19516e9b20 Mon Sep 17 00:00:00 2001 From: ermolaev_p Date: Mon, 23 Dec 2024 15:30:09 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D1=81=D0=BC=D1=8B=D0=BA=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BD=D0=B0=20=D0=B8=D0=B4=D0=B5=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D0=B9=20=D1=82=D1=80=D0=B0=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OptAlgorithm/OptTimeCalculator.py | 12 ++++---- src/testAlgo.py | 43 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 src/testAlgo.py diff --git a/src/OptAlgorithm/OptTimeCalculator.py b/src/OptAlgorithm/OptTimeCalculator.py index e893334..30f8ccb 100644 --- a/src/OptAlgorithm/OptTimeCalculator.py +++ b/src/OptAlgorithm/OptTimeCalculator.py @@ -22,7 +22,7 @@ class OptTimeCalculator(AutoConfigClass): t2t = max(0, (h1 - (self.a_max_1 * t1 * t1 /2)) / v0) T1 = t1 + t2t - t21 = sqrt(h2/self.a_max_2) + t21 = sqrt(h2/(self.a_max_2)) t21 = min(self.v_max_2/self.a_max_2, t21) t22 = max(0, (h2 - (self.a_max_2 * t21 * t21)) / self.v_max_2) T2 = t22 + 2 * t21 @@ -207,26 +207,26 @@ class OptTimeCalculator(AutoConfigClass): v0q = min(sqrt(2 * self.a_max_1 * s), self.v_max_1) v0 = min(v0q, sqrt(1/(self.k_hardness_1*self.mass_1))* self.Ftogrow) t1 = T - sqrt(max(0, T**2 - 2 * s / self.a_max_1)) - t1 = min(t1, v0 / self.a_max_1) + assert t1 < v0 / self.a_max_1 t2 = max(0, (s - self.a_max_1*t1**2/2) / (self.a_max_1*t1)) return t1, t2 def calcFirstOpen(self, T : float, s : float) -> tuple[float, float]: t1 = T / 2 - sqrt(max(0, T**2 - 4 * s / self.a_max_1)) / 2 - t1 = min(t1, self.v_max_1 / self.a_max_1) + assert t1 < self.v_max_1 / self.a_max_1 t2 = max(0, (s - self.a_max_1*t1**2/2) / (self.a_max_1*t1)) return t1, t2 def calcSecondOpen(self, T : float, s : float) -> tuple[float, float]: t1 = T / 2 - sqrt(max(0, T**2 - 4 * s / self.a_max_2)) / 2 - t1 = min(t1, self.v_max_2 / self.a_max_2) + assert t1 < self.v_max_2 / self.a_max_2 t2 = max(0, (s - self.a_max_2*t1**2/2) / (self.a_max_2*t1)) return t1, t2 def calcSecondClose(self, T : float, s : float) -> tuple[float, float]: t1 = T / 2 - sqrt(max(0, T**2 - 4 * s / self.a_max_2)) / 2 - t1 = min(t1, self.v_max_2 / self.a_max_2) - t2 = max(0, (s - self.a_max_2*t1**2/2) / (self.a_max_2*t1)) + assert t1 < self.v_max_2 / self.a_max_2 + t2 = max(0, (s - self.a_max_2*t1**2) / (self.a_max_2*t1)) return t1, t2 def calcSecondOpenOffset(self, t1 : float, t2 : float, sq : float) -> float: diff --git a/src/testAlgo.py b/src/testAlgo.py new file mode 100644 index 0000000..8405a4a --- /dev/null +++ b/src/testAlgo.py @@ -0,0 +1,43 @@ +from src.OptAlgorithm.OptAlgorithm import OptAlgorithm +from src.utils import read_json + +from matplotlib import pyplot as plt, use + +from numpy import cos, sin, sqrt, cbrt, arcsin, linspace, array + +if __name__ == "__main__": + + tq = 1 + ts = linspace(0, tq, 200000) + + operator_params = read_json("params/operator_params.json") + system_params = read_json("params/system_params.json") + + non_array_operator_params = {} + i = 1 + for key, value in operator_params.items(): + if hasattr(value, "__len__"): + if len(value) > i: + non_array_operator_params[key] = value[i] + else: + non_array_operator_params[key] = value[0] + else: + non_array_operator_params[key] = value + + non_array_system_params = {} + for key, value in system_params.items(): + if hasattr(value, "__len__"): + if len(value) > i: + non_array_system_params[key] = value[i] + else: + non_array_system_params[key] = value[0] + else: + non_array_system_params[key] = value + + + opt = OptAlgorithm(non_array_operator_params, non_array_system_params) + Xs = array([opt.getVar("X2", t) for t in ts]) + + + plt.plot(ts, Xs) + plt.show() \ No newline at end of file