STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
config.py
Go to the documentation of this file.
1
from
__future__
import
annotations
2
3
from
dataclasses
import
dataclass, field, asdict
4
from
pathlib
import
Path
5
from
typing
import
Any, Dict, List, Optional
6
7
import
yaml
8
9
10
@dataclass
11
class
LUTAxisConfig
:
12
"""
13
Configuration for a single LUT axis.
14
15
The `name` should match a physical or controller variable. For interoperability
16
with existing controller / engine_sim code, the following names are
17
recommended for axes:
18
19
- Pressures (Pa): ``P_copv``, ``P_reg``, ``P_u_fuel``, ``P_u_ox``,
20
``P_d_fuel``, ``P_d_ox``
21
- Navigation: ``h`` (altitude [m]), ``vz`` (vertical velocity [m/s]),
22
``theta`` (tilt [rad]), ``mass_estimate`` [kg]
23
- Commands: ``thrust_desired`` [N], ``altitude_goal`` [m]
24
"""
25
26
name: str
27
values: List[float]
28
units: str =
""
29
description: str =
""
30
31
32
@dataclass
33
class
ControllerLUTConfig
:
34
"""
35
High-dimensional controller LUT configuration.
36
37
This describes:
38
- Which axes (state / command variables) span the LUT
39
- Which engine/controller quantities are stored as outputs
40
- Where to find the underlying engine configuration
41
"""
42
43
axes: List[LUTAxisConfig]
44
outputs: List[str]
45
engine_config_path: str
46
controller_config_path: Optional[str] =
None
47
engine_lut_path: Optional[str] =
None
# Precomputed engine LUT for fast DDP
48
metadata: Dict[str, Any] = field(default_factory=dict)
49
50
@classmethod
51
def
from_yaml
(cls, path: str | Path) ->
"ControllerLUTConfig"
:
52
"""Load a LUT configuration from a YAML file."""
53
path = Path(path)
54
with
path.open(
"r"
)
as
f:
55
raw: Dict[str, Any] = yaml.safe_load(f)
56
57
axes_cfg = [
58
LUTAxisConfig
(
59
name=a[
"name"
],
60
values=list(a[
"values"
]),
61
units=a.get(
"units"
,
""
),
62
description=a.get(
"description"
,
""
),
63
)
64
for
a
in
raw.get(
"axes"
, [])
65
]
66
67
return
cls(
68
axes=axes_cfg,
69
outputs=list(raw.get(
"outputs"
, [])),
70
engine_config_path=str(raw[
"engine_config_path"
]),
71
controller_config_path=raw.get(
"controller_config_path"
),
72
engine_lut_path=raw.get(
"engine_lut_path"
),
73
metadata=dict(raw.get(
"metadata"
, {})),
74
)
75
76
def
to_dict
(self) -> Dict[str, Any]:
77
"""Convert to a plain dict suitable for JSON/YAML serialization."""
78
data = asdict(self)
79
# Flatten axes dataclasses to simple dicts
80
data[
"axes"
] = [asdict(axis)
for
axis
in
self.
axes
]
81
return
data
controller_lut.config.ControllerLUTConfig
Definition
config.py:33
controller_lut.config.ControllerLUTConfig.to_dict
Dict[str, Any] to_dict(self)
Definition
config.py:76
controller_lut.config.ControllerLUTConfig.axes
List axes
Definition
config.py:43
controller_lut.config.ControllerLUTConfig.from_yaml
"ControllerLUTConfig" from_yaml(cls, str|Path path)
Definition
config.py:51
controller_lut.config.LUTAxisConfig
Definition
config.py:11
daq-server
tools
controller_lut
config.py
Generated by
1.15.0