-
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.
Changed fmu control loop to speed execution
- Loading branch information
Showing
24 changed files
with
314 additions
and
115 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 was deleted.
Oops, something went wrong.
Binary file not shown.
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
Binary file modified
BIN
-2.05 KB
(100%)
rocket_twin/systems/control/rocket_controller/rocket_controller.fmu
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
model stage_controller | ||
input Boolean is_on; | ||
output Real w; | ||
equation | ||
if (is_on == true) then | ||
w = 1.; | ||
else | ||
w = 0.; | ||
end if; | ||
end stage_controller; |
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,77 @@ | ||
import os | ||
|
||
from cosapp.base import System | ||
from cosapp_fmu.FMUsystem import FMUSystem | ||
from OMPython import ModelicaSystem | ||
|
||
import rocket_twin.systems.control | ||
|
||
|
||
class StageControllerFMU(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 | ||
is_on: boolean, | ||
whether the system is in fueling phase or not | ||
weight_prop: float, | ||
stage fuel weight | ||
weight_max: float, | ||
stage maximum fuel weight | ||
Outputs | ||
------ | ||
w: float, | ||
command flux | ||
""" | ||
|
||
def setup(self, model_path, model_name): | ||
|
||
self.add_inward("weight_prop", 0.0, desc="Stage propellant weight", unit="kg") | ||
self.add_inward("weight_max", 1.0, desc="Stage maximum propellant weight", unit="kg") | ||
self.add_inward("is_on", False, desc="Whether the stage is on or not") | ||
|
||
fmu_path = self.create_fmu(model_path, model_name) | ||
self.add_child( | ||
FMUSystem("fmu_controller", fmu_path=fmu_path), | ||
pulling=['is_on', 'w'], | ||
) | ||
|
||
self.add_event("full", trigger="weight_prop == weight_max") | ||
|
||
def create_fmu(self, 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) | ||
model_path = os.path.join(rocket_twin.__path__[0], model_path) | ||
model_path = model_path.replace("\\", "/") | ||
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 |
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,10 @@ | ||
model station_controller | ||
input Boolean fueling; | ||
output Real w; | ||
equation | ||
if (fueling == true) then | ||
w = 1.; | ||
else | ||
w = 0.; | ||
end if; | ||
end station_controller; |
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
Oops, something went wrong.