diff --git a/.gitignore b/.gitignore index e6105fe..f7acbbb 100644 --- a/.gitignore +++ b/.gitignore @@ -250,4 +250,7 @@ $RECYCLE.BIN/ # Cosapp Systems representations **.html +# Command sequences +*.fmu + # End of https://www.gitignore.io/api/git,linux,macos,python,windows,pycharm,jupyternotebook diff --git a/rocket_twin/systems/control/controller.mo b/rocket_twin/systems/control/controller.mo index 358fcc5..7bbee21 100644 --- a/rocket_twin/systems/control/controller.mo +++ b/rocket_twin/systems/control/controller.mo @@ -1,8 +1,18 @@ model controller input Real ti; + input Real weight; + parameter Real weight_max; + parameter Real t0; output Real w; + output Boolean engine_on; equation - if (ti < 5.) then + if (ti < t0) then + engine_on = false; + else + engine_on = true; + end if; + + if (weight < weight_max and engine_on == false) then w = 1.; else w = 0.; diff --git a/rocket_twin/systems/control/controller/controller.fmu b/rocket_twin/systems/control/controller/controller.fmu deleted file mode 100644 index 9d290cb..0000000 Binary files a/rocket_twin/systems/control/controller/controller.fmu and /dev/null differ diff --git a/rocket_twin/systems/control/controller_fmu.py b/rocket_twin/systems/control/controller_fmu.py index 1698a56..d3af583 100644 --- a/rocket_twin/systems/control/controller_fmu.py +++ b/rocket_twin/systems/control/controller_fmu.py @@ -30,12 +30,21 @@ 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_transient("x", der="1") + pulling = { + "w": "w", + "weight": "weight_p", + "weight_max": "weight_max", + "t0": "t0", + "ti": "time_var", + } + fmu_path = self.create_fmu(model_path, model_name) self.add_child( FMUSystem("fmu_controller", fmu_path=fmu_path), - pulling={"w": "w", "ti": "time_var"}, + pulling=pulling, ) def compute(self): diff --git a/rocket_twin/systems/control/rocket_controller.mo b/rocket_twin/systems/control/rocket_controller.mo index 40e76f5..f45c525 100644 --- a/rocket_twin/systems/control/rocket_controller.mo +++ b/rocket_twin/systems/control/rocket_controller.mo @@ -1,8 +1,18 @@ model rocket_controller input Real ti; + input Real weight; + parameter Real weight_max; + parameter Real t0; output Real w; + output Boolean engine_on; equation - if (5. < ti and ti < 15.) then + if (ti < t0) then + engine_on = false; + else + engine_on = true; + end if; + + if (weight > 0. and engine_on == true) then w = 1.; else w = 0.; diff --git a/rocket_twin/systems/control/rocket_controller/rocket_controller.fmu b/rocket_twin/systems/control/rocket_controller/rocket_controller.fmu deleted file mode 100644 index 11151e1..0000000 Binary files a/rocket_twin/systems/control/rocket_controller/rocket_controller.fmu and /dev/null differ diff --git a/rocket_twin/systems/rocket/rocket.py b/rocket_twin/systems/rocket/rocket.py index d161d95..c645b78 100644 --- a/rocket_twin/systems/rocket/rocket.py +++ b/rocket_twin/systems/rocket/rocket.py @@ -17,7 +17,7 @@ class Rocket(System): def setup(self): self.add_child(ControllerCoSApp("controller")) - self.add_child(Tank("tank"), pulling=["w_in"]) + self.add_child(Tank("tank"), pulling=["w_in", "weight_max", "weight_p"]) self.add_child(Engine("engine")) self.add_child( Dynamics( diff --git a/rocket_twin/tests/test_controller_fmu.py b/rocket_twin/tests/test_controller_fmu.py index a96af0c..5c88c00 100644 --- a/rocket_twin/tests/test_controller_fmu.py +++ b/rocket_twin/tests/test_controller_fmu.py @@ -23,11 +23,18 @@ def test_controller_fmu(self): sys.rocket.controller, ControllerFMU("controller", model_path=model_path_r, model_name=model_name_r), ) - driver = sys.add_driver(RungeKutta(order=4, time_interval=[0, 15], dt=0.01)) + sys.connect(sys.controller.inwards, sys.rocket.inwards, ["weight_max", "weight_p"]) + sys.rocket.connect( + 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)) 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, } driver.set_scenario(init=init, values=values) sys.run_drivers() diff --git a/rocket_twin/tests/test_flying_rocket.py b/rocket_twin/tests/test_flying_rocket.py index c81995c..8d0c932 100644 --- a/rocket_twin/tests/test_flying_rocket.py +++ b/rocket_twin/tests/test_flying_rocket.py @@ -16,7 +16,7 @@ def test_run_once(self): "rocket.flying": True, "controller.w_temp": 0.0, "rocket.controller.w_temp": 1.0, - "rocket.tank.weight_p": "rocket.tank.weight_max", + "rocket.weight_p": "rocket.tank.weight_max", "rocket.tank.w_out_max": 3.0, "g_tank.w_in": 0.0, "g_tank.weight_p": 0.0, diff --git a/rocket_twin/tests/test_mission.py b/rocket_twin/tests/test_mission.py index 4dc4f28..48ef1f8 100644 --- a/rocket_twin/tests/test_mission.py +++ b/rocket_twin/tests/test_mission.py @@ -12,7 +12,7 @@ def test_run_once(self): dt = 0.1 init = { - "rocket.tank.weight_p": 0.0, + "rocket.weight_p": 0.0, "rocket.controller.w_temp": 0.0, "controller.w_temp": 1.0, "g_tank.weight_p": "g_tank.weight_max", diff --git a/rocket_twin/tests/test_refuel_rocket.py b/rocket_twin/tests/test_refuel_rocket.py index fc7cd6f..be0160f 100644 --- a/rocket_twin/tests/test_refuel_rocket.py +++ b/rocket_twin/tests/test_refuel_rocket.py @@ -12,7 +12,7 @@ def test_run_once(self): dt = 0.1 init = { - "rocket.tank.weight_p": 0.0, + "rocket.weight_p": 0.0, "rocket.controller.w_temp": 0.0, "controller.w_temp": 1.0, "g_tank.weight_p": "g_tank.weight_max",