STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
backend.routers.flight Namespace Reference

Classes

class  EnvironmentConfig
class  FinsConfig
class  RocketConfig
class  TankConfig
class  FlightSimRequest
class  FlightTrajectory
class  TruncationInfo
class  MassCapInfo
class  PropellantDiagnostics
class  FlightSimResponse
class  FlightOptimizeRequest
class  FlightOptimizeResponse

Functions

tuple _propellant_densities (config)
float calculate_tank_capacity (float height, float radius, float density, float fill_factor=0.95)
 convert_numpy (obj)
Optional[str] generate_rocket_diagram (flight_obj)
 extract_flight_series (flight_obj, float elevation=0.0)
 build_flight_config (base_config, FlightSimRequest request)
tuple[dict, dict, float|None, float|None, float] _apply_propellant_mass_caps (dict config_dict, base_config)
float _integrate_series (np.ndarray times, np.ndarray values)
MassCapInfo _build_mass_cap_info (str branch, float requested_kg, float effective_kg, float tank_volume_m3, float max_fill_kg, float fill_factor)
PropellantDiagnostics _compute_propellant_diagnostics (*, np.ndarray times, np.ndarray thrust_array, np.ndarray mdot_O_array, np.ndarray mdot_F_array, float lox_requested, float fuel_requested, float lox_effective, float fuel_effective, Optional[float] lox_tank_max, Optional[float] fuel_tank_max, Optional[TruncationInfo] truncation, dict mass_caps, Optional[float] target_apogee_m, Optional[float] propellant_tank_fill_factor=None)
float _thrust_reference_pressure (base_config, FlightSimRequest request)
Optional[float] ceiling_agl_m (design_requirements, float elevation_m)
Optional[dict] _ceiling_check (flight_config, pressure_curves, float burn_time, float nominal_apogee_agl)
FlightSimResponse _execute_flight_simulation (base_config, FlightSimRequest request, *, Optional[np.ndarray] time_array=None, Optional[np.ndarray] thrust_array=None, Optional[np.ndarray] mdot_O_array=None, Optional[np.ndarray] mdot_F_array=None, Optional[float] lox_mass_kg=None, Optional[float] fuel_mass_kg=None, bool check_ceiling=True)
 simulate_flight (FlightSimRequest request, UserSession session=Depends(get_session))
FlightSimResponse _simulate_flight (FlightSimRequest request, config)
 optimize_flight_altitude (FlightOptimizeRequest request, UserSession session=Depends(get_session))
FlightOptimizeResponse _optimize_flight_altitude (FlightOptimizeRequest request, config)
 check_rocketpy ()

Variables

 router = APIRouter(prefix="/api/flight", tags=["flight"])
float PSI_TO_PA = 6894.76
float PA_TO_PSI = 1.0 / PSI_TO_PA
float LOX_DENSITY_FALLBACK = 1141.0
float FUEL_DENSITY_FALLBACK = 800.0

Detailed Description

Flight simulation endpoints.

Function Documentation

◆ _apply_propellant_mass_caps()

tuple[dict, dict, float | None, float | None, float] backend.routers.flight._apply_propellant_mass_caps ( dict config_dict,
base_config )
protected
Cap LOX/fuel masses to tank capacity. Returns (mass_adjustments, lox_max, fuel_max, fill_factor).

Definition at line 433 of file flight.py.

References _propellant_densities(), and min.

Referenced by _execute_flight_simulation().

◆ _build_mass_cap_info()

MassCapInfo backend.routers.flight._build_mass_cap_info ( str branch,
float requested_kg,
float effective_kg,
float tank_volume_m3,
float max_fill_kg,
float fill_factor )
protected

Definition at line 505 of file flight.py.

Referenced by _compute_propellant_diagnostics().

◆ _ceiling_check()

Optional[dict] backend.routers.flight._ceiling_check ( flight_config,
pressure_curves,
float burn_time,
float nominal_apogee_agl )
protected
Apogee against the ceiling at its high-apogee corner.

The corner is the most vertical, lowest-drag flight the config admits: the rail at 90 deg, the
windless ISA, and -- when drag is the build-up -- a hydraulically smooth skin (roughness 0), the
floor of turbulent friction. A user's drag table has no band and is flown as given.

Definition at line 672 of file flight.py.

References ceiling_agl_m().

Referenced by _execute_flight_simulation().

◆ _compute_propellant_diagnostics()

PropellantDiagnostics backend.routers.flight._compute_propellant_diagnostics ( * ,
np.ndarray times,
np.ndarray thrust_array,
np.ndarray mdot_O_array,
np.ndarray mdot_F_array,
float lox_requested,
float fuel_requested,
float lox_effective,
float fuel_effective,
Optional[float] lox_tank_max,
Optional[float] fuel_tank_max,
Optional[TruncationInfo] truncation,
dict mass_caps,
Optional[float] target_apogee_m,
Optional[float] propellant_tank_fill_factor = None )
protected

Definition at line 523 of file flight.py.

References _build_mass_cap_info(), and _integrate_series().

Referenced by _execute_flight_simulation().

◆ _execute_flight_simulation()

FlightSimResponse backend.routers.flight._execute_flight_simulation ( base_config,
FlightSimRequest request,
* ,
Optional[np.ndarray] time_array = None,
Optional[np.ndarray] thrust_array = None,
Optional[np.ndarray] mdot_O_array = None,
Optional[np.ndarray] mdot_F_array = None,
Optional[float] lox_mass_kg = None,
Optional[float] fuel_mass_kg = None,
bool check_ceiling = True )
protected

◆ _integrate_series()

float backend.routers.flight._integrate_series ( np.ndarray times,
np.ndarray values )
protected

Definition at line 497 of file flight.py.

Referenced by _compute_propellant_diagnostics().

◆ _optimize_flight_altitude()

FlightOptimizeResponse backend.routers.flight._optimize_flight_altitude ( FlightOptimizeRequest request,
config )
protected

Definition at line 961 of file flight.py.

References _execute_flight_simulation(), and ceiling_agl_m().

◆ _propellant_densities()

tuple backend.routers.flight._propellant_densities ( config)
protected
(oxidizer, fuel) liquid densities [kg/m³] from the loaded config's fluids, so propellant
mass-capping follows the selected propellant rather than a hardcoded fuel. Falls back to generic
densities only if the config doesn't carry them.

Definition at line 28 of file flight.py.

Referenced by _apply_propellant_mass_caps().

◆ _simulate_flight()

FlightSimResponse backend.routers.flight._simulate_flight ( FlightSimRequest request,
config )
protected

Definition at line 922 of file flight.py.

References _execute_flight_simulation().

◆ _thrust_reference_pressure()

float backend.routers.flight._thrust_reference_pressure ( base_config,
FlightSimRequest request )
protected
The ambient pressure the thrust curve was computed at [Pa].

The time series ran on the SESSION config, so its elevation (not an elevation the Flight tab
overrides afterwards) sets the reference; the request can state it outright.

Definition at line 641 of file flight.py.

Referenced by _execute_flight_simulation().

◆ build_flight_config()

backend.routers.flight.build_flight_config ( base_config,
FlightSimRequest request )
Build a flight-ready config by merging base config with request overrides.

Definition at line 339 of file flight.py.

Referenced by _execute_flight_simulation().

◆ calculate_tank_capacity()

float backend.routers.flight.calculate_tank_capacity ( float height,
float radius,
float density,
float fill_factor = 0.95 )
Calculate max propellant mass for a cylindrical tank.

Args:
    height: Tank height in meters
    radius: Tank radius in meters
    density: Fluid density in kg/m³
    fill_factor: Fill factor (default 95% to avoid overfill)

Returns:
    Maximum propellant mass in kg

Definition at line 43 of file flight.py.

◆ ceiling_agl_m()

Optional[float] backend.routers.flight.ceiling_agl_m ( design_requirements,
float elevation_m )
design_requirements.max_apogee_m as metres above the pad, or None when no ceiling is set.

Definition at line 659 of file flight.py.

Referenced by _ceiling_check(), and _optimize_flight_altitude().

◆ check_rocketpy()

backend.routers.flight.check_rocketpy ( )
Check if RocketPy is available for flight simulation.

Definition at line 1109 of file flight.py.

◆ convert_numpy()

backend.routers.flight.convert_numpy ( obj)
Recursively convert numpy types to Python native types.

Definition at line 60 of file flight.py.

References convert_numpy().

Referenced by _execute_flight_simulation(), and convert_numpy().

◆ extract_flight_series()

backend.routers.flight.extract_flight_series ( flight_obj,
float elevation = 0.0 )
Extract flight time series from RocketPy flight object.

Returns:
    Tuple of (time_array, altitude_agl_array, velocity_array)

Definition at line 311 of file flight.py.

Referenced by _execute_flight_simulation().

◆ generate_rocket_diagram()

Optional[str] backend.routers.flight.generate_rocket_diagram ( flight_obj)
Generate rocket diagram as base64-encoded PNG.

Returns:
    Base64-encoded PNG string, or None if generation fails.

Definition at line 270 of file flight.py.

References decode().

Referenced by _execute_flight_simulation().

◆ optimize_flight_altitude()

backend.routers.flight.optimize_flight_altitude ( FlightOptimizeRequest request,
UserSession session = Depends(get_session) )
Find minimum-fuel burn time to reach a target apogee for the loaded time-series curve.

In the thread pool: the search flies a dozen RocketPy flights (~7 s on the LE4 stand), and
inline on the event loop /api/health went unanswered for all of it. Every flight of the
search uses the one config read here.

Definition at line 945 of file flight.py.

◆ simulate_flight()

backend.routers.flight.simulate_flight ( FlightSimRequest request,
UserSession session = Depends(get_session) )
Run flight simulation using time-series data.

Uses provided thrust/mdot arrays from time-series analysis.
Returns apogee, max velocity, and flight trajectory.

In the thread pool: a RocketPy flight is about a second of CPU, and inline on the event loop
it froze every other request (/api/health included) for as long. The config is read once.

Definition at line 904 of file flight.py.

Variable Documentation

◆ FUEL_DENSITY_FALLBACK

float backend.routers.flight.FUEL_DENSITY_FALLBACK = 800.0

Definition at line 25 of file flight.py.

◆ LOX_DENSITY_FALLBACK

float backend.routers.flight.LOX_DENSITY_FALLBACK = 1141.0

Definition at line 24 of file flight.py.

◆ PA_TO_PSI

float backend.routers.flight.PA_TO_PSI = 1.0 / PSI_TO_PA

Definition at line 19 of file flight.py.

◆ PSI_TO_PA

float backend.routers.flight.PSI_TO_PA = 6894.76

Definition at line 18 of file flight.py.

◆ router

backend.routers.flight.router = APIRouter(prefix="/api/flight", tags=["flight"])

Definition at line 14 of file flight.py.