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 #16

Merged
merged 13 commits into from
Jul 21, 2023
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is something to do to manage valve status and connection status instead of engine status : an idea ?

w = 1.;
else
w = 0.;
Expand Down
Binary file modified rocket_twin/systems/control/controller/controller.fmu
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
luca7084 marked this conversation as resolved.
Show resolved Hide resolved
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
15 changes: 14 additions & 1 deletion rocket_twin/tests/test_controller_fmu.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
from cosapp.drivers import RungeKutta
from cosapp.recorders import DataFrameRecorder
from maintenance.utils import swap_system

from rocket_twin.systems import ControllerFMU, Station
Expand All @@ -23,14 +24,26 @@ 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)
driver.add_recorder(DataFrameRecorder(includes=["rocket.controller.weight_p"]), period=1.0)

sys.run_drivers()
data = driver.recorder.export_data()
print(data)

np.testing.assert_allclose(sys.rocket.a, 40.0, atol=10 ** (0))
np.testing.assert_allclose(sys.g_tank.weight_p, 5.0, atol=10 ** (0))
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
Loading