diff --git a/rocket_twin/systems/control/controller.mo b/rocket_twin/systems/control/controller.mo index 7bbee21..e7064ba 100644 --- a/rocket_twin/systems/control/controller.mo +++ b/rocket_twin/systems/control/controller.mo @@ -2,11 +2,11 @@ model controller input Real ti; input Real weight; parameter Real weight_max; - parameter Real t0; + parameter Real tl; output Real w; output Boolean engine_on; equation - if (ti < t0) then + if (ti < tl) then engine_on = false; else engine_on = true; diff --git a/rocket_twin/systems/control/controller_fmu.py b/rocket_twin/systems/control/controller_fmu.py index d3af583..6634f7e 100644 --- a/rocket_twin/systems/control/controller_fmu.py +++ b/rocket_twin/systems/control/controller_fmu.py @@ -30,14 +30,15 @@ class ControllerFMU(System): def setup(self, model_path, model_name): self.add_inward("time_var", 0.0, desc="System time", unit="") - self.add_inward("t0", 0.0, desc="Launch time", unit="") + self.add_inward("time_int", 0.0, desc="Interval between fueling end and launch", unit="") + self.add_inward("time_lnc", 100000.0, desc="Launch time", unit="") self.add_transient("x", der="1") pulling = { "w": "w", "weight": "weight_p", "weight_max": "weight_max", - "t0": "t0", + "tl": "time_lnc", "ti": "time_var", } @@ -47,10 +48,18 @@ def setup(self, model_path, model_name): pulling=pulling, ) + self.add_event("full_tank", trigger="weight_p > 0.9999*weight_max") + def compute(self): self.time_var = self.time + def transition(self): + + if self.full_tank.present: + + self.time_lnc = self.time_var + self.time_int + def create_fmu(self, model_path, model_name): """Create an fmu file in the control folder from an mo file. diff --git a/rocket_twin/systems/control/rocket_controller.mo b/rocket_twin/systems/control/rocket_controller.mo index f45c525..bf47c65 100644 --- a/rocket_twin/systems/control/rocket_controller.mo +++ b/rocket_twin/systems/control/rocket_controller.mo @@ -2,11 +2,11 @@ model rocket_controller input Real ti; input Real weight; parameter Real weight_max; - parameter Real t0; + parameter Real tl; output Real w; output Boolean engine_on; equation - if (ti < t0) then + if (ti < tl) then engine_on = false; else engine_on = true; diff --git a/rocket_twin/systems/rocket/rocket.py b/rocket_twin/systems/rocket/rocket.py index c645b78..a80ea47 100644 --- a/rocket_twin/systems/rocket/rocket.py +++ b/rocket_twin/systems/rocket/rocket.py @@ -43,7 +43,7 @@ def setup(self): "flying", False, desc="Whether the rocket is flying or not", unit="" ) - self.add_event("Takeoff", trigger="dyn.a > 0") + self.add_event("Takeoff", trigger="engine.force > 0") def compute(self): self.a *= self.flying diff --git a/rocket_twin/tests/test_controller_fmu.py b/rocket_twin/tests/test_controller_fmu.py index 2c0f34f..12eb924 100644 --- a/rocket_twin/tests/test_controller_fmu.py +++ b/rocket_twin/tests/test_controller_fmu.py @@ -30,19 +30,20 @@ def test_controller_fmu(self): sys.rocket.controller.inwards, sys.rocket.tank.inwards, ["weight_max", "weight_p"] ) - driver = sys.add_driver(RungeKutta(order=4, time_interval=[0, 16], dt=0.01)) + driver = sys.add_driver(RungeKutta(order=4, time_interval=[0, 18], dt=0.01)) init = {"g_tank.weight_p": 10.0, "rocket.tank.weight_p": 0.0} values = { "g_tank.w_out_max": 1.0, "rocket.tank.w_out_max": 0.5, - "controller.t0": 5.99, - "rocket.controller.t0": 5.99, + "controller.time_int": 3.0, + "rocket.controller.time_int": 3.0, } driver.set_scenario(init=init, values=values) - driver.add_recorder(DataFrameRecorder(includes=["rocket.controller.weight_p"]), period=1.0) + driver.add_recorder(DataFrameRecorder(includes=["rocket.a", "rocket.dyn.a"]), period=1.0) sys.run_drivers() data = driver.recorder.export_data() + data = data.drop(["Section", "Status", "Error code"], axis=1) print(data) np.testing.assert_allclose(sys.rocket.a, 40.0, atol=10 ** (0))