-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflight.py
More file actions
71 lines (57 loc) · 2.03 KB
/
Copy pathflight.py
File metadata and controls
71 lines (57 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from typing import Self
import dill
from rocketpy.simulation.flight import Flight as RocketPyFlight
from src.services.environment import EnvironmentService
from src.services.rocket import RocketService
from src.models.flight import FlightModel
from src.views.flight import FlightSimulation
from src.utils import rocketpy_encoder, DiscretizeConfig
class FlightService:
_flight: RocketPyFlight
def __init__(self, flight: RocketPyFlight = None):
self._flight = flight
@classmethod
def from_flight_model(cls, flight: FlightModel) -> Self:
"""
Get the rocketpy flight object.
Returns:
FlightService containing the rocketpy flight object.
"""
rocketpy_env = EnvironmentService.from_env_model(
flight.environment
).environment
rocketpy_rocket = RocketService.from_rocket_model(flight.rocket).rocket
rocketpy_flight = RocketPyFlight(
rocket=rocketpy_rocket,
environment=rocketpy_env,
rail_length=flight.rail_length,
terminate_on_apogee=flight.terminate_on_apogee,
time_overshoot=flight.time_overshoot,
equations_of_motion=flight.equations_of_motion,
**flight.get_additional_parameters(),
)
return cls(flight=rocketpy_flight)
@property
def flight(self) -> RocketPyFlight:
return self._flight
@flight.setter
def flight(self, flight: RocketPyFlight):
self._flight = flight
def get_flight_simulation(self) -> FlightSimulation:
"""
Get the simulation of the flight.
Returns:
FlightSimulation
"""
attributes = rocketpy_encoder(
self.flight, DiscretizeConfig.for_flight()
)
flight_simulation = FlightSimulation(**attributes)
return flight_simulation
def get_flight_binary(self) -> bytes:
"""
Get the binary representation of the flight.
Returns:
bytes
"""
return dill.dumps(self.flight)