Skip to main content

rockets_engine/
lib.rs

1//! Powered, three-dimensional point-mass flight, using SI units and simulation time.
2//!
3//! Prescribed motors supply thrust and consume propellant in proportion to impulse;
4//! [`Stage`]s add serial or parallel staging with scheduled separations. [`Simulator`]
5//! integrates translation while [`ForceModel`] supplies environmental acceleration and
6//! [`Guidance`] supplies optional control commands. [`UniformGravity`] covers local
7//! flat-frame flight and [`CentralGravity`] covers planet-scale arcs; the default
8//! `ballistics` feature reuses ballistics-engine's atmosphere and drag kernel.
9//!
10//! Coordinates are right-handed; the conventional local frame is X/downrange, Y/up,
11//! Z/lateral, but [`CentralGravity`] works in an Earth-centered frame of the caller's
12//! choosing. No time compression occurs inside this crate. This is a point-mass model,
13//! not an attitude, actuator or aerodynamic-lift simulation.
14//!
15//! See the README and `examples/boost_coast.rs` for integration and model assumptions.
16
17// wasm-bindgen generates unsafe blocks, so the wasm build cannot keep the forbid.
18#![cfg_attr(not(feature = "wasm"), forbid(unsafe_code))]
19#![warn(missing_docs)]
20#![doc = include_str!("../README.md")]
21
22#[cfg(any(feature = "cli", feature = "wasm"))]
23mod analysis;
24#[cfg(feature = "ballistics")]
25pub mod ballistics;
26#[cfg(any(feature = "cli", feature = "wasm"))]
27pub mod command;
28#[cfg(feature = "ballistics")]
29mod dynamics;
30mod error;
31mod flight;
32#[cfg(feature = "model")]
33pub mod geometry;
34mod guidance;
35#[cfg(feature = "model")]
36pub mod model_rocket;
37mod motor;
38#[cfg(feature = "wasm")]
39pub mod wasm;
40
41#[cfg(feature = "ballistics")]
42pub use dynamics::{RollDynamics, Weathercock, WeathercockParams};
43pub use error::{Error, Result};
44pub use flight::{
45    AltitudeSwitch, BoxedForces, CentralGravity, FlightState, ForceModel, IntegratorSettings,
46    RailForces, Simulator, StepResult, UniformGravity, EARTH_MU_M3_S2,
47};
48pub use guidance::{
49    BoxedGuidance, ControlInput, FixedDirection, Guidance, GuidanceContext, ProgradeDirection,
50    SteeringLag, ThrustMisalignment,
51};
52#[cfg(feature = "model")]
53pub use model_rocket::MotorFile;
54#[cfg(all(feature = "model", feature = "ballistics"))]
55pub use model_rocket::{Airframe, RecoveryForces};
56pub use motor::{
57    Motor, MotorPhase, MotorSample, Rocket, RocketSample, Stage, ThrustCurve, ThrustPoint,
58};
59
60/// Three-dimensional SI vector in the fixed world frame.
61pub type Vec3 = nalgebra::Vector3<f64>;
62
63pub(crate) fn finite_vec(value: &Vec3) -> bool {
64    value.iter().all(|x| x.is_finite())
65}
66
67pub(crate) fn nonnegative(value: f64, field: &'static str) -> Result<()> {
68    if !value.is_finite() || value < 0.0 {
69        return Err(Error::invalid(field, "must be finite and nonnegative"));
70    }
71    Ok(())
72}
73
74pub(crate) fn positive(value: f64, field: &'static str) -> Result<()> {
75    if !value.is_finite() || value <= 0.0 {
76        return Err(Error::invalid(field, "must be finite and positive"));
77    }
78    Ok(())
79}