Skip to main content

Rocket

Struct Rocket 

Source
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

Source

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.

Source

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.

Source

pub fn add_nose(&mut self, nose: Nose) -> Result<&mut Self, Error>

Adds the nose cone, which goes first.

§Errors
  • Error::Order if a body part is already in place, or the rocket was read from a design.
  • Error::Domain for a diameter, length, wall or shoulder dimension that isn’t finite and positive, or a shoulder wall thicker than its stated radius; Error::Design for a shape whose parameter is out of its range.
Source

pub fn add_tube(&mut self, tube: Tube) -> Result<&mut Self, Error>

Adds a body tube behind the last body part.

§Errors
  • Error::Order if the rocket was read from a design.
  • Error::Domain for a length, wall or diameter that isn’t finite and positive.
Source

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::Order if there is no body part before it, or the rocket was read from a design.
  • Error::Domain for 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::Design for a shape whose parameter is out of its range.
Source

pub fn add_fins(&mut self, fins: Fins) -> Result<&mut Self, Error>

Adds a fin set to the last body tube.

§Errors
  • Error::Order if there is no body tube yet, or the rocket was read from a design.
  • Error::Design for fins the design refuses (FinSet::validate): no fins, a chord, span or thickness that isn’t finite and positive, and the like.
  • Error::Domain for a position that isn’t finite.
Source

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::Order if there is no body tube yet, the rocket has a motor tube already, or it was read from a design.
  • Error::Domain for 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.
Source

pub fn add_mass(&mut self, mass: Mass) -> Result<&mut Self, Error>

Adds a mass inside the last body tube.

§Errors
  • Error::Order if there is no body tube yet, or the rocket was read from a design.
  • Error::Domain for a mass or packing that is negative or not finite, or a position that isn’t finite.
Source

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::Order if 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::Design for 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::Domain for a position that isn’t finite.
Source

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.

Source

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.

Source

pub fn design(&self) -> &Rocket

The design: the same tree a design file holds.

Source

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.

Source

pub fn recovery(&self) -> &[Device]

The recovery devices, in the order they were added.

Source

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::NoMotor before the rocket has a motor.
  • Error::DesignChecks with 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::Design for a tree that doesn’t hold together.
Source

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.

Source

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.

Source

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§

Source§

impl Clone for Rocket

Source§

fn clone(&self) -> Rocket

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rocket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Rocket

Source§

fn eq(&self, other: &Rocket) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Rocket

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Rocket

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.