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

Timed takeoff #18

Merged
merged 2 commits into from
Jul 21, 2023
Merged
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
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.0, 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")
luca7084 marked this conversation as resolved.
Show resolved Hide resolved
self.add_event("Takeoff", trigger="engine.force > 0")

def compute(self):
self.a *= self.flying
Expand Down
9 changes: 5 additions & 4 deletions rocket_twin/tests/test_controller_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ 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.0,
"rocket.controller.time_int": 3.0,
}
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))
Expand Down