Skip to content
Open
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
8 changes: 4 additions & 4 deletions examples/Anonymous--Alpha/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
},
"rail_buttons": {
"angular_position": 0.0,
"distance": 1.5,
"lower_position": 3.7849999999999997,
"distance": 1.205,
"lower_position": 3.465,
"name": "Rail Button",
"upper_position": 2.2849999999999997
"upper_position": 2.26
},
"rocket": {
"center_of_mass_without_propellant": 1.991,
Expand Down Expand Up @@ -118,7 +118,7 @@
"cant_angle": 0.0,
"name": "Trapezoidal fin set",
"number": 4,
"position": 3.2449999999999997,
"position": 3.195,
"root_chord": 0.26999999999999996,
"section": "airfoil",
"span": 0.1400000000000001,
Expand Down
4 changes: 2 additions & 2 deletions examples/Anonymous--Beta/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"cant_angle": 0.0,
"name": "Trapezoidal fin set",
"number": 4,
"position": 2.9109999999999996,
"position": 1.226,
"root_chord": 0.18,
"section": "square",
"span": 0.12512,
Expand All @@ -134,7 +134,7 @@
"cant_angle": 0.0,
"name": "Trapezoidal fin set",
"number": 4,
"position": 2.9109999999999996,
"position": 1.226,
"root_chord": 0.18,
"section": "square",
"span": 0.154,
Expand Down
14 changes: 7 additions & 7 deletions examples/Anonymous--Epsilon/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
},
"rail_buttons": {
"angular_position": -90.0,
"distance": 2.0800000000000005,
"lower_position": 3.0140000000000007,
"distance": 2.0240000000000005,
"lower_position": 2.9060000000000006,
"name": "Rail connection A",
"upper_position": 0.9340000000000002
"upper_position": 0.8820000000000001
},
"rocket": {
"center_of_mass_without_propellant": 1.629,
Expand Down Expand Up @@ -118,7 +118,7 @@
"cant_angle": 0.0,
"name": "Main fin set #2 #1 #1",
"number": 1,
"position": 2.7350000000000003,
"position": 2.6900000000000004,
"root_chord": 0.196,
"section": "square",
"span": 0.14,
Expand All @@ -130,7 +130,7 @@
"cant_angle": 0.0,
"name": "Main fin set #2 #1 #2",
"number": 1,
"position": 2.9290000000000003,
"position": 2.688,
"root_chord": 0.198,
"section": "square",
"span": 0.138,
Expand All @@ -142,7 +142,7 @@
"cant_angle": 0.0,
"name": "Main fin set #2 #1 #3",
"number": 1,
"position": 3.128,
"position": 2.689,
"root_chord": 0.197,
"section": "square",
"span": 0.136,
Expand All @@ -154,7 +154,7 @@
"cant_angle": 0.0,
"name": "Main fin set #2 #1 #4",
"number": 1,
"position": 3.3240000000000003,
"position": 2.688,
"root_chord": 0.198,
"section": "square",
"span": 0.138,
Expand Down
8 changes: 4 additions & 4 deletions examples/Anonymous--Eta/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
},
"rail_buttons": {
"angular_position": 0.0,
"distance": 1.5035000000000003,
"lower_position": 2.9560000000000004,
"distance": 1.2125000000000004,
"lower_position": 1.9690000000000003,
"name": "Launch lug",
"upper_position": 1.4525000000000001
"upper_position": 0.7565
},
"rocket": {
"center_of_mass_without_propellant": 1.458,
Expand Down Expand Up @@ -110,7 +110,7 @@
"cant_angle": 0.0,
"name": "Trapezoidal fin set",
"number": 3,
"position": 4.0120000000000005,
"position": 2.4930000000000003,
"root_chord": 0.23,
"section": "rounded",
"span": 0.185,
Expand Down
6 changes: 3 additions & 3 deletions examples/Anonymous--Gamma/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@
},
"rail_buttons": {
"angular_position": 0.0,
"distance": 1.4360000000000004,
"lower_position": 3.4889900000000003,
"distance": 0.746,
"lower_position": 2.04399,
"name": "Launch Rail Pin 1",
"upper_position": 2.05299
"upper_position": 1.29799
},
"rocket": {
"center_of_mass_without_propellant": 1.4557,
Expand Down
6 changes: 3 additions & 3 deletions examples/Anonymous--Iota/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
},
"rail_buttons": {
"angular_position": 45.0,
"distance": 0.75,
"lower_position": 1.85,
"distance": 0.7200000000000002,
"lower_position": 1.7200000000000002,
"name": "Launch lug",
"upper_position": 1.1
"upper_position": 1.0
},
"rocket": {
"center_of_mass_without_propellant": 1.108,
Expand Down
2 changes: 1 addition & 1 deletion examples/Anonymous--Mu/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"cant_angle": 0.0,
"name": "Trapezoidal fin set",
"number": 3,
"position": 1.8140000000000003,
"position": 1.015,
"root_chord": 0.055,
"section": "airfoil",
"span": 0.09,
Expand Down
2 changes: 1 addition & 1 deletion examples/Anonymous--Nu/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"cant_angle": 0.0,
"name": "Fins",
"number": 4,
"position": 4.386,
"position": 3.757,
"root_chord": 0.23,
"section": "rounded",
"span": 0.12,
Expand Down
2 changes: 1 addition & 1 deletion examples/Anonymous--Pi/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"cant_angle": 0.0,
"name": "Trapezoidal fin set",
"number": 4,
"position": 2.335,
"position": 1.7350000000000003,
"root_chord": 0.125,
"section": "square",
"span": 0.16,
Expand Down
2 changes: 1 addition & 1 deletion examples/Anonymous--Rho/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"cant_angle": 0.0,
"name": "Aletas trapezoidales",
"number": 4,
"position": 2.5949999999999993,
"position": 2.06,
"root_chord": 0.2,
"section": "airfoil",
"span": 0.115,
Expand Down
2 changes: 1 addition & 1 deletion examples/Anonymous--Sigma/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"cant_angle": 0.0,
"name": "Trapezoidal fin set",
"number": 3,
"position": 2.306,
"position": 2.248,
"root_chord": 0.2,
"section": "square",
"span": 0.27,
Expand Down
8 changes: 4 additions & 4 deletions examples/Anonymous--Theta/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
},
"rail_buttons": {
"angular_position": 0.0,
"distance": 0.5092290000000008,
"lower_position": 3.1340420000000004,
"distance": 0.7694999999999999,
"lower_position": 2.068313,
"name": "Launch lug",
"upper_position": 2.6248129999999996
"upper_position": 1.298813
},
"rocket": {
"center_of_mass_without_propellant": 1.1921,
Expand Down Expand Up @@ -118,7 +118,7 @@
"cant_angle": 0.0,
"name": "Trapezoidal fin set",
"number": 4,
"position": 2.131513,
"position": 1.9883130000000002,
"root_chord": 0.12,
"section": "square",
"span": 0.08,
Expand Down
8 changes: 4 additions & 4 deletions examples/Anonymous--Zeta/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
},
"rail_buttons": {
"angular_position": 45.0,
"distance": 1.3050000000000006,
"lower_position": 3.49,
"distance": 0.8000000000000003,
"lower_position": 2.95,
"name": "S.4.3 Launch lug",
"upper_position": 2.1849999999999996
"upper_position": 2.15
},
"rocket": {
"center_of_mass_without_propellant": 1.7723,
Expand Down Expand Up @@ -118,7 +118,7 @@
"cant_angle": 0.0,
"name": "S.5.2 Fins",
"number": 4,
"position": 2.9699999999999998,
"position": 2.8,
"root_chord": 0.37,
"section": "airfoil",
"span": 0.095,
Expand Down
2 changes: 1 addition & 1 deletion examples/NDRT--Rocket--2020/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"cant_angle": 0.0,
"name": "Trapezoidal fin set",
"number": 4,
"position": 3.3528000000000002,
"position": 3.048,
"root_chord": 0.15239999999999995,
"section": "rounded",
"span": 0.1651,
Expand Down
4 changes: 2 additions & 2 deletions examples/ProjetoJupiter--Valetudo--2019/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
},
"rail_buttons": {
"angular_position": 29.999999999999996,
"distance": 1.2515,
"lower_position": 2.399169,
"distance": 1.1934999999999998,
"lower_position": 2.341169,
"name": "Guia de lançamento",
"upper_position": 1.147669
},
Expand Down
6 changes: 3 additions & 3 deletions examples/WERT--Prometheus--2022/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
},
"rail_buttons": {
"angular_position": 0.0,
"distance": 0.5540000000000003,
"lower_position": 3.2256530000000003,
"distance": 0.5840000000000001,
"lower_position": 1.8085,
"name": "Launch lug",
"upper_position": 2.671653
"upper_position": 1.2245
},
"rocket": {
"center_of_mass_without_propellant": 1.266,
Expand Down
10 changes: 9 additions & 1 deletion rocketserializer/components/open_rocket_wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ def process_elements_position(
)
unique_id = hash(frozenset(element.items()))
elements[unique_id] = element

# The children of a rocket or stage are stacked one after the other. All the
# others are placed relative to the front of their own parent.
children_are_stacked = element["type"] in ["Rocket", "Stage", "AxialStage"]
if not children_are_stacked:
top_position = element["position"]

i = 0

while True:
Expand All @@ -93,7 +100,8 @@ def process_elements_position(
elements.update(new_elements)
logger.info("Child '%s' processed", child.getName())

top_position += child.getLength()
if children_are_stacked:
top_position += child.getLength()

i += 1
logger.info("Moving to the next child")
Expand Down
20 changes: 20 additions & 0 deletions tests/acceptance/test_ork_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ def test_ork_extractor(expected_results_file, fixture, request):
settings, expected_results = remove_sensitive_keys(settings, expected_results)


def test_positions_match_openrocket(settings_and_locations):
settings, locations = settings_and_locations

for fins, fin_type in [
("trapezoidal_fins", "TrapezoidFinSet"),
("elliptical_fins", "EllipticalFinSet"),
]:
for fin in settings[fins].values():
assert any(
fin["position"] == pytest.approx(x, abs=1e-6)
for x in locations[fin_type]
)

buttons = locations.get("LaunchLug", []) + locations.get("RailButton", [])
for key in ["upper_position", "lower_position"]:
if key in settings["rail_buttons"]:
position = settings["rail_buttons"][key]
assert any(position == pytest.approx(x, abs=1e-6) for x in buttons)


def remove_sensitive_keys(settings, expected):
"""Remove sensitive keys from the settings and expected_results dicts. This
is important to avoid problems with the paths to the files that are saved
Expand Down
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,20 @@ def get_settings(ork_path, output_path, ork_document):
return settings


def get_locations(component, locations=None):
"""Group the component locations calculated by OpenRocket by their type."""
locations = {} if locations is None else locations
component_type = str(component.getClass().getSimpleName())
location = float(component.getComponentLocations()[0].x)
locations.setdefault(component_type, []).append(location)
for i in range(component.getChildCount()):
get_locations(component.getChild(i), locations)
return locations


# Pre-compute all settings at import time using a single OpenRocket session
_cached_settings = {}
_cached_locations = {}

with OpenRocketSession(select_latest_openrocket_jar(ROOT_DIR), "OFF") as session:
for name, rel_path in EXAMPLES.items():
Expand All @@ -61,6 +73,12 @@ def get_settings(ork_path, output_path, ork_document):
output_dir = ROOT_DIR / "tests" / "acceptance" / Path(rel_path).name
ork_doc = session.load_doc(str(ork_filepath))
_cached_settings[name] = get_settings(ork_filepath, output_dir, ork_doc)
_cached_locations[name] = get_locations(ork_doc.getRocket())


@pytest.fixture(params=EXAMPLES)
def settings_and_locations(request):
return _cached_settings[request.param], _cached_locations[request.param]


# Create fixtures for each example
Expand Down