Skip to content

Commit

Permalink
Added launch timer
Browse files Browse the repository at this point in the history
  • Loading branch information
luca7084 committed Jul 21, 2023
1 parent 249ffa1 commit 3367ca1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions rocket_twin/systems/control/controller.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ model controller
input Real ti;
input Real weight;
parameter Real weight_max;
parameter Real t0;
parameter Real tl;
output Real w;
output Boolean engine_on;
equation
if (ti < t0) then
if (ti < tl) then
engine_on = false;
else
engine_on = true;
Expand Down
13 changes: 11 additions & 2 deletions rocket_twin/systems/control/controller_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ 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_inward("time_int", 0.0, desc="Interval between fueling end and launch", unit="")
self.add_inward("time_lnc", 100000., desc="Launch time", unit='')
self.add_transient("x", der="1")

pulling = {
"w": "w",
"weight": "weight_p",
"weight_max": "weight_max",
"t0": "t0",
"tl": "time_lnc",
"ti": "time_var",
}

Expand All @@ -47,10 +48,18 @@ def setup(self, model_path, model_name):
pulling=pulling,
)

self.add_event("full_tank", trigger="weight_p > 0.9999*weight_max")

def compute(self):

self.time_var = self.time

def transition(self):

if self.full_tank.present:

self.time_lnc = self.time_var + self.time_int

def create_fmu(self, model_path, model_name):
"""Create an fmu file in the control folder from an mo file.
Expand Down
4 changes: 2 additions & 2 deletions rocket_twin/systems/control/rocket_controller.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ model rocket_controller
input Real ti;
input Real weight;
parameter Real weight_max;
parameter Real t0;
parameter Real tl;
output Real w;
output Boolean engine_on;
equation
if (ti < t0) then
if (ti < tl) then
engine_on = false;
else
engine_on = true;
Expand Down
2 changes: 1 addition & 1 deletion rocket_twin/systems/rocket/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setup(self):
"flying", False, desc="Whether the rocket is flying or not", unit=""
)

self.add_event("Takeoff", trigger="dyn.a > 0")
self.add_event("Takeoff", trigger="engine.force > 0")

def compute(self):
self.a *= self.flying
Expand Down
11 changes: 6 additions & 5 deletions rocket_twin/tests/test_controller_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ def test_controller_fmu(self):
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))
driver = sys.add_driver(RungeKutta(order=4, time_interval=[0, 18], 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,
"controller.time_int": 3.,
"rocket.controller.time_int": 3.,
}
driver.set_scenario(init=init, values=values)
driver.add_recorder(DataFrameRecorder(includes=["rocket.controller.weight_p"]), period=1.0)
driver.add_recorder(DataFrameRecorder(includes=["rocket.a", "rocket.dyn.a"]), period=1.0)

sys.run_drivers()
data = driver.recorder.export_data()
data = data.drop(["Section", "Status", "Error code"], axis=1)
print(data)

np.testing.assert_allclose(sys.rocket.a, 40.0, atol=10 ** (0))
np.testing.assert_allclose(sys.rocket.a, 41.0, atol=10 ** (0))
np.testing.assert_allclose(sys.g_tank.weight_p, 5.0, atol=10 ** (0))
np.testing.assert_allclose(sys.rocket.tank.weight_p, 0.0, atol=10 ** (0))

0 comments on commit 3367ca1

Please sign in to comment.