pub struct Rocket { /* private fields */ }Expand description
A rocket: its design, its motor and its recovery devices.
It serializes, for a record of what was flown, but doesn’t deserialize: the builder’s methods
check what goes in, so a rocket is built with them, or read from a design with
Rocket::from_design.
use hpr::rocket::{Fins, Mass, MotorTube, Nose, Tube, material};
use hpr::{FinPlanform, Motor, NoseShape, Position, Rocket};
let mut rocket = Rocket::new("Small", 0.0563)?;
let ogive = NoseShape::Ogive { radius_ratio: 1.0 };
let planform = FinPlanform::Trapezoidal {
root_chord_m: 0.1,
tip_chord_m: 0.04,
span_m: 0.045,
sweep_m: 0.05,
};
rocket
.add_nose(Nose::hollow(ogive, 0.22, 0.0015, material("abs")?))?
.add_tube(Tube::new(0.9, 0.00115, material("kraft_phenolic")?))?
.add_fins(Fins::new(3, planform, 0.003175, material("birch_plywood")?))?
.add_motor_tube(MotorTube::new(0.2, 0.029, 0.001, material("kraft_phenolic")?))?
.set_motor(Motor::from_catalog("H54")?)?;
// Unstable as it stands: the motor's weight puts the center of gravity behind the center of
// pressure, and the margin, in calibres, is negative.
assert!(rocket.static_margin_cal(0.0, 0.3)?.is_some_and(|margin| margin < 0.0));
// 200 g near the top of the tube, a recovery bay, brings it forward of it.
rocket.add_mass(Mass::new(0.2, Position::Top { aft_offset_m: 0.07 }))?;
assert!(rocket.static_margin_cal(0.0, 0.3)?.is_some_and(|margin| margin > 1.0));Implementations§
Source§impl Rocket
impl Rocket
Sourcepub fn new(name: &str, diameter_m: f64) -> Result<Self, Error>
pub fn new(name: &str, diameter_m: f64) -> Result<Self, Error>
An empty rocket called name, of outer body diameter diameter_m: the nose’s base
diameter, and the first tube’s, unless they say otherwise (a catalog part states its
own). Its reference diameter, the one
the stability margin is counted in, is its largest body diameter.
§Errors
Error::Domain for a diameter that isn’t finite and positive.
Sourcepub fn from_design(
design: Rocket,
configuration_id: &str,
) -> Result<Self, Error>
pub fn from_design( design: Rocket, configuration_id: &str, ) -> Result<Self, Error>
A rocket from a design you already have, flown in its configuration configuration_id:
a design file read with serde_json, an OpenRocket file read with hpr_io::ork, or a
built rocket’s Rocket::design changed with hpr_design to hold what the builder
can’t, such as a cluster or pods. Parts can’t be added to it; recovery devices can.
§Errors
Error::NoSuchConfiguration if the design has no configuration of that id.
Sourcepub fn add_nose(&mut self, nose: Nose) -> Result<&mut Self, Error>
pub fn add_nose(&mut self, nose: Nose) -> Result<&mut Self, Error>
Adds the nose cone, which goes first.
§Errors
Error::Orderif a body part is already in place, or the rocket was read from a design.Error::Domainfor a diameter, length, wall or shoulder dimension that isn’t finite and positive, or a shoulder wall thicker than its stated radius;Error::Designfor a shape whose parameter is out of its range.
Sourcepub fn add_tube(&mut self, tube: Tube) -> Result<&mut Self, Error>
pub fn add_tube(&mut self, tube: Tube) -> Result<&mut Self, Error>
Adds a body tube behind the last body part.
§Errors
Error::Orderif the rocket was read from a design.Error::Domainfor a length, wall or diameter that isn’t finite and positive.
Sourcepub fn add_transition(
&mut self,
transition: Transition,
) -> Result<&mut Self, Error>
pub fn add_transition( &mut self, transition: Transition, ) -> Result<&mut Self, Error>
Adds a transition behind the last body part, starting at its diameter unless it states its own (a catalog part does).
§Errors
Error::Orderif there is no body part before it, or the rocket was read from a design.Error::Domainfor a length, wall, stated fore diameter or shoulder dimension that isn’t finite and positive, an aft diameter that is negative or not finite, or a shoulder wall thicker than its radius;Error::Designfor a shape whose parameter is out of its range.
Sourcepub fn add_fins(&mut self, fins: Fins) -> Result<&mut Self, Error>
pub fn add_fins(&mut self, fins: Fins) -> Result<&mut Self, Error>
Adds a fin set to the last body tube.
§Errors
Error::Orderif there is no body tube yet, or the rocket was read from a design.Error::Designfor fins the design refuses (FinSet::validate): no fins, a chord, span or thickness that isn’t finite and positive, and the like.Error::Domainfor a position that isn’t finite.
Sourcepub fn add_motor_tube(&mut self, tube: MotorTube) -> Result<&mut Self, Error>
pub fn add_motor_tube(&mut self, tube: MotorTube) -> Result<&mut Self, Error>
Adds the motor tube to the last body tube. A rocket has one.
§Errors
Error::Orderif there is no body tube yet, the rocket has a motor tube already, or it was read from a design.Error::Domainfor a length, bore or wall that isn’t finite and positive, an overhang that is negative or not finite, or a position that isn’t finite.
Sourcepub fn add_mass(&mut self, mass: Mass) -> Result<&mut Self, Error>
pub fn add_mass(&mut self, mass: Mass) -> Result<&mut Self, Error>
Adds a mass inside the last body tube.
§Errors
Error::Orderif there is no body tube yet, or the rocket was read from a design.Error::Domainfor a mass or packing that is negative or not finite, or a position that isn’t finite.
Sourcepub fn add_fitting(&mut self, fitting: Fitting) -> Result<&mut Self, Error>
pub fn add_fitting(&mut self, fitting: Fitting) -> Result<&mut Self, Error>
Adds a fitting to the last body tube: a coupler, a centering ring, a bulkhead, a launch lug, or a packed parachute or streamer.
§Errors
Error::Orderif there is no body tube yet, the rocket was read from a design, or the fitting holds a part of another kind (one read from a file).Error::Designfor a part the design can’t weigh: a size that is negative or not finite, a ring whose bore reaches its rim, a wall thicker than its tube’s radius, a material of the wrong kind. A tube with a wall of zero, or a parachute or streamer of no size, weighs nothing and is taken.Error::Domainfor a position that isn’t finite.
Sourcepub fn set_motor(&mut self, motor: Motor) -> Result<&mut Self, Error>
pub fn set_motor(&mut self, motor: Motor) -> Result<&mut Self, Error>
Puts motor in the motor tube, lit at launch, in place of any motor there before. The
design’s one configuration is named after its designation.
§Errors
Error::Order if there is no motor tube yet, or the rocket was read from a design.
Sourcepub fn add_parachute(&mut self, device: Device) -> &mut Self
pub fn add_parachute(&mut self, device: Device) -> &mut Self
Adds a recovery device: a parachute, a streamer or a tumble, with what opens it.
Trigger::MotorDelay with motor 0, the first motor, opens
it at the motor’s ejection charge, which needs the motor’s delay set
(Motor::with_delay_s). The device adds drag, not mass: add its mass with
Rocket::add_mass, or a catalog parachute’s with Fitting::from_catalog.
Sourcepub fn configuration_id(&self) -> Option<&str>
pub fn configuration_id(&self) -> Option<&str>
The configuration the rocket flies in: the motor’s designation for a built rocket, None
before it has a motor.
Sourcepub fn assemble(&self) -> Result<Assembly, Error>
pub fn assemble(&self) -> Result<Assembly, Error>
The parts placed and the motor in its tube (hpr_design::Rocket::assemble), once the
design’s checks (hpr_design::checks) find no errors: the same checks a flight runs
with the default settings, so what this weighs is what crate::Flight would fly. A
flight told to accept a design’s errors
(FlightSettings::accept_design_errors)
flies what this refuses; design().assemble(id) weighs it.
§Errors
Error::NoMotorbefore the rocket has a motor.Error::DesignCheckswith every finding if the checks find an error, such as a motor wider than its tube’s bore or a motor tube wider than the airframe.Error::Designfor a tree that doesn’t hold together.
Sourcepub fn mass_properties(&self, time_s: f64) -> Result<MassProperties, Error>
pub fn mass_properties(&self, time_s: f64) -> Result<MassProperties, Error>
The mass, center of gravity and inertia time_s seconds after the motor lights, the
motor burning as its thrust curve says. The center of gravity is in the body frame: z
points to the nose and is zero at its tip, so a point s meters aft of the tip is at
z = −s (docs/physics/frames.md).
§Errors
As Rocket::assemble, and Error::Domain for a time that is negative or not finite.
Sourcepub fn static_margin_cal(
&self,
time_s: f64,
mach: f64,
) -> Result<Option<f64>, Error>
pub fn static_margin_cal( &self, time_s: f64, mach: f64, ) -> Result<Option<f64>, Error>
The static stability margin time_s seconds after the motor lights, at Mach mach with
the air along the axis, in the rocket’s weakest plane (Rocket::margin), calibres of the
reference diameter: how far the center of pressure is behind the center of gravity. None
where hpr_sim::metrics::margin leaves it
undefined: a normal force that doesn’t restore, or a center of pressure too ill-conditioned
to place. Rocket::margin gives the rest of it.
§Errors
As Rocket::margin.
Sourcepub fn margin(&self, time_s: f64, mach: f64) -> Result<Margin, Error>
pub fn margin(&self, time_s: f64, mach: f64) -> Result<Margin, Error>
The center of pressure and the static margin time_s seconds after the motor lights, at
Mach mach with the air along the axis, in the weakest plane the air can cross the rocket
in (hpr_sim::metrics::weakest_margin): a rocket with a fin set of one or two fins has a
margin in each plane, and the least is the one to trust. Its center of pressure is a
station: meters aft of the nose tip, positive.
§Errors
As Rocket::mass_properties, Error::Aero for a rocket the aerodynamic model can’t
take, and Error::Sim for a Mach number out of its range.
Trait Implementations§
impl StructuralPartialEq for Rocket
Auto Trait Implementations§
impl Freeze for Rocket
impl RefUnwindSafe for Rocket
impl Send for Rocket
impl Sync for Rocket
impl Unpin for Rocket
impl UnsafeUnpin for Rocket
impl UnwindSafe for Rocket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more