Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mass controller v2 #17

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion rocket_twin/systems/control/controller.mo
Original file line number Diff line number Diff line change
@@ -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.;
Expand Down
Binary file not shown.
11 changes: 10 additions & 1 deletion rocket_twin/systems/control/controller_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 11 additions & 1 deletion rocket_twin/systems/control/rocket_controller.mo
Original file line number Diff line number Diff line change
@@ -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.;
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion rocket_twin/systems/rocket/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion rocket_twin/tests/test_controller_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion rocket_twin/tests/test_flying_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion rocket_twin/tests/test_mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion rocket_twin/tests/test_refuel_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down