|
1 | 1 | import math |
2 | 2 |
|
3 | 3 | import numpy as np |
| 4 | +from rocketpy.tools import find_obj_from_hash |
| 5 | +from typing import Iterable |
4 | 6 |
|
5 | 7 | from rocketpy.control.controller import _Controller |
6 | 8 | from rocketpy.mathutils.function import Function |
@@ -2070,17 +2072,32 @@ def from_dict(cls, data): |
2070 | 2072 | for parachute in data["parachutes"]: |
2071 | 2073 | rocket.parachutes.append(parachute) |
2072 | 2074 |
|
2073 | | - for air_brakes in data["air_brakes"]: |
2074 | | - rocket.add_air_brakes( |
2075 | | - drag_coefficient_curve=air_brakes["drag_coefficient_curve"], |
2076 | | - controller_function=air_brakes["controller_function"], |
2077 | | - sampling_rate=air_brakes["sampling_rate"], |
2078 | | - clamp=air_brakes["clamp"], |
2079 | | - reference_area=air_brakes["reference_area"], |
2080 | | - initial_observed_variables=air_brakes["initial_observed_variables"], |
2081 | | - override_rocket_drag=air_brakes["override_rocket_drag"], |
2082 | | - name=air_brakes["name"], |
2083 | | - controller_name=air_brakes["controller_name"], |
2084 | | - ) |
| 2075 | + for sensor, position in data["sensors"]: |
| 2076 | + rocket.add_sensor(sensor, position) |
| 2077 | + |
| 2078 | + for air_brake in data["air_brakes"]: |
| 2079 | + rocket.air_brakes.append(air_brake) |
| 2080 | + |
| 2081 | + for controller in data["_controllers"]: |
| 2082 | + if ( |
| 2083 | + interactive_objects_hash := getattr( |
| 2084 | + controller, "_interactive_objects_hash" |
| 2085 | + ) |
| 2086 | + ) is not None: |
| 2087 | + is_iterable = isinstance(interactive_objects_hash, Iterable) |
| 2088 | + if not is_iterable: |
| 2089 | + interactive_objects_hash = [interactive_objects_hash] |
| 2090 | + for hash_ in interactive_objects_hash: |
| 2091 | + if (hashed_obj := find_obj_from_hash(data, hash_)) is not None: |
| 2092 | + if not is_iterable: |
| 2093 | + controller.interactive_objects = hashed_obj |
| 2094 | + else: |
| 2095 | + controller.interactive_objects.append(hashed_obj) |
| 2096 | + else: |
| 2097 | + warnings.warn( |
| 2098 | + "Could not find controller interactive objects." |
| 2099 | + "Deserialization will proceed, results may not be accurate." |
| 2100 | + ) |
| 2101 | + rocket._add_controllers(controller) |
2085 | 2102 |
|
2086 | 2103 | return rocket |
0 commit comments