Skip to content

Commit

Permalink
Added function to create fmu files
Browse files Browse the repository at this point in the history
  • Loading branch information
luca7084 committed Jul 7, 2023
1 parent 2b8ecd2 commit 3bdff03
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ isort
black
pre-commit
cosapp_fmu @ git+ssh://[email protected]/twiinIT/cosapp-fmu.git@master
OMPython
Binary file removed rocket_twin/systems/control/controller.fmu
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions rocket_twin/systems/station/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from cosapp_fmu.FMUsystem import FMUSystem

from rocket_twin.systems import Clock, Pipe, Rocket, Tank
from rocket_twin.utils import create_FMU


class Station(System):
Expand All @@ -16,16 +17,17 @@ class Station(System):
------
"""

def setup(self, fmu_path=None):
def setup(self, model_path=None, model_name=None):
self.add_child(Tank("g_tank"))
self.add_child(Pipe("pipe"))
self.add_child(Rocket("rocket"))

self.connect(self.g_tank.outwards, self.pipe.inwards, {"w_out": "w_in"})
self.connect(self.pipe.outwards, self.rocket.inwards, {"w_out": "w_in"})

if fmu_path is not None:
if model_path is not None:
self.add_child(Clock("clock"))
fmu_path = create_FMU(model_path, model_name)
self.add_child(FMUSystem("controller", fmu_path=fmu_path))
self.connect(self.clock.outwards, self.controller.inwards, {"time_var": "ti"})
self.connect(self.controller.outwards, self.g_tank.inwards, {"wg": "w_command"})
Expand Down
4 changes: 3 additions & 1 deletion rocket_twin/tests/test_sequences_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
class TestSequencesFMU:
def test_sequence_fmu(self):

sys = Station("sys", fmu_path="rocket_twin/systems/control/controller.fmu")
model_path = r"rocket_twin\\systems\\control\\controller.mo"
model_name = "controller"
sys = Station("sys", model_path=model_path, model_name=model_name)
driver = sys.add_driver(RungeKutta(order=4, time_interval=[0, 15], dt=0.01))
init = {"g_tank.weight_p": 10.0, "rocket.tank.weight_p": 0.0}
values = {
Expand Down
3 changes: 2 additions & 1 deletion rocket_twin/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from rocket_twin.utils.run_sequences import run_sequences
from rocket_twin.utils.create_fmu import create_FMU

__all__ = ["run_sequences"]
__all__ = ["run_sequences", "create_FMU"]
19 changes: 19 additions & 0 deletions rocket_twin/utils/create_fmu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import rocket_twin.systems.control
from OMPython import ModelicaSystem

def create_FMU(model_path, model_name):

fmu_path = os.path.join(rocket_twin.systems.control.__path__[0], model_name)
try:
os.mkdir(fmu_path)
except OSError:
pass
os.chdir(fmu_path)
mod=ModelicaSystem(model_path,model_name)
fmu = mod.convertMo2Fmu()
for filename in os.listdir(fmu_path):
if filename != (model_name + ".fmu"):
os.remove(filename)

return fmu

0 comments on commit 3bdff03

Please sign in to comment.