-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed clock, added cosapp controller
- Loading branch information
Showing
17 changed files
with
152 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from rocket_twin.systems.control.clock import Clock | ||
from rocket_twin.systems.control.cosapp_controller import CosappController | ||
|
||
__all__ = ["Clock"] | ||
from rocket_twin.systems.control.controller import Controller # isort: skip | ||
|
||
__all__ = ["CosappController", "Controller"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from cosapp.base import System | ||
from cosapp_fmu.FMUsystem import FMUSystem | ||
from rocket_twin.systems.control import CosappController | ||
|
||
from rocket_twin.utils import create_FMU | ||
|
||
class Controller(System): | ||
"""Controller of the command variables. | ||
Inputs | ||
------ | ||
model_path: string, | ||
the path to the .mo file, if any | ||
model_name: string | ||
the .fmu file name | ||
Outputs | ||
------ | ||
'f': float, | ||
command force | ||
'wr': float, | ||
command flow | ||
'wg' float, | ||
command flow | ||
""" | ||
|
||
def setup(self, model_path=None, model_name=None): | ||
|
||
self.add_inward('time_var', 0., desc="System time", unit='') | ||
self.add_transient('x', der='1') | ||
|
||
if model_path is None: | ||
self.add_child(CosappController('cos_control'), pulling=['f', 'wr', 'wg']) | ||
else: | ||
fmu_path = create_FMU(model_path, model_name) | ||
self.add_child(FMUSystem("fmu_controller", fmu_path=fmu_path), pulling={'f' : 'f', 'wr' : 'wr', 'wg' : 'wg', 'ti' : 'time_var'}) | ||
|
||
def compute(self): | ||
|
||
self.time_var = self.time | ||
'' |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from cosapp.base import System | ||
|
||
class CosappController(System): | ||
"""System which allows command through CoSApp sequences. | ||
Inputs | ||
------ | ||
Outputs | ||
------ | ||
'f': float, | ||
command force | ||
'wr': float, | ||
command flow | ||
'wg' float, | ||
command flow | ||
""" | ||
|
||
def setup(self): | ||
|
||
self.add_inward('f_temp', 0., desc="Ratio of command force to maximum force", unit='') | ||
self.add_inward('wr_temp', 0., desc="Ratio of command fuel flow to maximum flow", unit='') | ||
self.add_inward('wg_temp', 0., desc="Ratio of command fuel flow to maximum flow", unit='') | ||
|
||
self.add_outward('f', 0., desc="Ratio of command force to maximum force", unit='') | ||
self.add_outward('wr', 0., desc="Ratio of command fuel flow to maximum flow", unit='') | ||
self.add_outward('wg', 0., desc="Ratio of command fuel flow to maximum flow", unit='') | ||
|
||
def compute(self): | ||
|
||
self.f = self.f_temp | ||
self.wr = self.wr_temp | ||
self.wg = self.wg_temp | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,36 @@ | ||
from cosapp.base import System | ||
from cosapp_fmu.FMUsystem import FMUSystem | ||
|
||
from rocket_twin.systems import Clock, Pipe, Rocket, Tank | ||
from rocket_twin.utils import create_FMU | ||
from rocket_twin.systems import Controller, Pipe, Rocket, Tank | ||
|
||
|
||
class Station(System): | ||
"""A space station composed by a rocket, a tank and a pipe connecting them. | ||
Inputs | ||
------ | ||
fmu_path: string, | ||
the path to the .fmu file, if there is any | ||
model_path: string, | ||
the path to the .mo file, if any | ||
model_name: string | ||
the .fmu file name | ||
Outputs | ||
------ | ||
""" | ||
|
||
def setup(self, model_path=None, model_name=None): | ||
self.add_child(Controller("controller", model_path=model_path, model_name=model_name)) | ||
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 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"}) | ||
self.connect( | ||
self.controller.outwards, | ||
self.rocket.inwards, | ||
{"wr": "w_command", "f": "force_command"}, | ||
) | ||
|
||
self.exec_order = ["clock", "controller", "g_tank", "pipe", "rocket"] | ||
self.connect(self.controller.outwards, self.g_tank.inwards, {"wg": "w_command"}) | ||
self.connect( | ||
self.controller.outwards, | ||
self.rocket.inwards, | ||
{"wr": "w_command", "f": "force_command"}, | ||
) | ||
|
||
self.g_tank.weight_max = 10.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from rocket_twin.utils.run_sequences import run_sequences | ||
from rocket_twin.utils.create_fmu import create_FMU | ||
from rocket_twin.utils.run_sequences import run_sequences | ||
|
||
__all__ = ["run_sequences", "create_FMU"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,37 @@ | ||
import os | ||
import rocket_twin.systems.control | ||
|
||
from OMPython import ModelicaSystem | ||
|
||
import rocket_twin.systems.control | ||
|
||
|
||
def create_FMU(model_path, model_name): | ||
"""Create an fmu file in the control folder from an mo file. | ||
Inputs | ||
------ | ||
model_path: string | ||
the path of the .mo file | ||
model_name: string | ||
the name of the .fmu file to be created | ||
Outputs | ||
------ | ||
fmu: string | ||
the path to the .fmu file | ||
""" | ||
|
||
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() | ||
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 | ||
return fmu |