Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Your own rocket

Build your own rocket in Rust part by part, find its center of gravity, center of pressure and stability margin, then fly it.

This page builds a rocket from your dimensions, your materials, and a motor from HPR Sim’s bundled catalog. Then it finds the rocket’s center of gravity (CG), its center of pressure (CP) and its stability margin, and flies it. Last, it turns the rocket into a design file and back. It needs the setup from Getting started, and some Rust.

Running the example

Run the program, meet the rocket it builds, and read what it prints.

Run it

cargo run --example own_rocket -p fusionspace-hpr-sim

This runs crates/hpr-sim/examples/own_rocket.rs, which prints this:

My 54 mm rocket (Cesaroni 168H54-10A): 1.120 m long, 56.3 mm across
Not yet validated: see the Accuracy page before trusting these numbers.

                                   liftoff   burnout
mass (kg)                            0.675     0.579
center of gravity (m from nose)      0.671     0.610
center of pressure (m from nose)     0.779     0.779
stability margin (calibers)           1.92      2.99

Normal-force slope (per radian) and center of pressure, at Mach 0.3:
nose        2.00 at 0.102 m
fins        4.82 at 1.060 m
rocket      6.82 at 0.779 m

From a 1.8 m vertical rail, with no wind:
Rail exit:  21.7 m/s
Apogee:     1144.5 m above the pad, at 13.92 s
Top speed:  187 m/s (Mach 0.56)
Ejection:   at 13.50 s, at 5.5 m/s

The fin set, as the design file stores it:
{
  "id": "fins",
  "name": "",
  "part": {
    "fin_set": {
      "count": 3,
      "planform": {
        "kind": "trapezoidal",
        "root_chord_m": 0.1,
        "tip_chord_m": 0.04,
        "span_m": 0.045,
        "sweep_m": 0.05
      },
      "thickness_m": 0.003175,
      "cross_section": "rounded",
      "tab": null,
      "cant_rad": 0.0,
      "base_angle_rad": 0.0,
      "material": {
        "name": "Birch plywood",
        "density": {
          "kind": "bulk",
          "kg_m3": 680.0
        }
      }
    }
  },
  "position": {
    "from": "bottom",
    "aft_offset_m": 0.0
  }
}

Like the first flight’s in Getting started, this output is committed in own_rocket.output.txt. CI (the project’s automated checks) runs the program on macOS, Windows and Linux, and fails if it prints anything else.

To fly your own rocket, change the numbers in the program and run it again. Or copy it to a new file in the same folder, say my_rocket.rs, and run that with cargo run --example my_rocket -p fusionspace-hpr-sim.

The rocket

The rocket has a 54 mm (2.1 in) airframe (the tube’s inside diameter). It flies on a Cesaroni H54, a 29 mm reloadable motor (a propellant load for a reusable case). These are the program’s inputs:

partRust typein the program
nose coneNoseConea tangent ogive (Shapes) 0.22 m (8.7 in) long, of ABS with a 1.5 mm (0.059 in) wall, and a 6 cm (2.4 in) shoulder that slides into the tube
airframeBodyTube0.9 m (35 in) of kraft phenolic tube, outer radius 0.02815 m (1.108 in), 56.3 mm (2.2 in) across, 1.15 mm (0.045 in) wall
motor mountInnerTube0.2 m (7.9 in) long, outer radius 0.0155 m (0.610 in), 1 mm (0.039 in) wall, so a 29 mm (1.1 in) bore; flush with the airframe’s aft end, with the nozzle 5 mm (0.20 in) past it
finsFinSetthree trapezoidal fins of 1/8 in (3.175 mm) birch plywood with rounded edges: root chord 0.1 m (3.9 in), tip chord 0.04 m (1.6 in), span 0.045 m (1.77 in), and the tip’s leading edge 0.05 m (2.0 in) aft of the root’s
recovery bayMassComponent200 g standing in for the parachute, shock cord and altimeter, packed as a cylinder 0.15 m (5.9 in) long and 50 mm (2.0 in) across (packing), 7 cm (2.8 in) below the airframe’s top
motorMountedMotorthe Cesaroni 168H54-10A from the bundled catalog, with a 10 s ejection delay

Every size is in meters, and every round part takes a radius, not a diameter: halve the diameters on your drawings.

What it printed

Mass, center of gravity and center of pressure

The liftoff column is the rocket on the pad, with the motor full. The burnout column is the rocket with the motor spent. Its case and nozzle are still aboard.

  • Mass: 0.675 kg on the pad and 0.579 kg at burnout. The 0.096 kg between them is the propellant; the catalog lists 96.6 g for this motor.
  • Center of gravity: where the mass balances, as a station: meters aft of the nose tip. It moves forward, from 0.671 m (26.4 in) to 0.610 m (24.0 in), as the propellant in the tail burns away.
  • Center of pressure: where the air’s sideways push acts, 0.779 m (30.7 in) aft of the tip. It depends on the rocket’s shape and speed, not its mass, so it’s the same in both columns. Both use Mach 0.3, with the air straight along the rocket’s axis.
  • Stability margin: how far the CP lies behind the CG, in calibers, in body diameters. At liftoff it’s (0.779 − 0.671) m ÷ 0.0563 m ≈ 1.9; the program works from the unrounded values and prints 1.92. At burnout the CG has moved forward, so the margin has grown to 2.99. This program works the margin out by hand. The simulator also gives it from the rail exit to apogee or the first deployment, with an optimum ejection delay, as Flight metrics shows.

A positive margin means that when something tips the rocket, the air turns its nose back into the oncoming air. That oncoming air is the relative wind: the airflow the rocket feels, from its motion over the ground combined with the wind. In a crosswind, the same turn swings the rocket upwind (weathercocking).

The simulator doesn’t judge whether a margin is enough; your club’s or range’s rules do.

Where the center of pressure comes from

Barrowman’s method works out each nose cone, transition and fin set on its own. Each gets a CP and a normal-force slope: how fast its sideways push grows with the angle of attack, per radian. A plain body tube has no line of its own: its sideways push appears only at larger angles, so its slope is zero. The rocket’s CP is the average of the parts’ CPs, each weighted by its slope:

partslope (per rad)CP (m from the nose tip)slope × CP (m/rad)
nose2.000.1020.204
fins4.821.0605.109
rocket6.825.313

So the CP is 5.313 ÷ 6.82 ≈ 0.779 m (30.7 in). The fins sit far aft and have more than twice the nose’s slope, so they pull the CP toward the tail. Moving the CP aft (bigger fins, or fins farther aft) or the CG forward (a heavier nose) raises the margin.

How speed moves the CP. In the simulator, only a fin set’s terms change with the Mach number (Aerodynamics). The fin set’s slope grows as the rocket speeds up toward Mach 1, and from Mach 0.8 its own CP moves aft too.

  • With the fins at the tail, as here, the growing fin slope pulls the rocket’s CP aft as it speeds up.
  • With canards (a second fin set near the nose), their slope grows too and pulls the CP forward. So which way the CP moves depends on both fin sets.
  • HPR Sim keeps fin sets’ CPs a quarter of the way along their mean aerodynamic chords, a kind of average chord, up to Mach 0.8. From there it moves each CP aft, toward where supersonic linear theory puts it (Aerodynamics). Niskanen’s 2009 thesis, which the simulator’s aerodynamics also draw on, starts moving the fins’ CP at Mach 0.5. NASA’s wind tunnel found an Arcas Robin rocket’s CP moving forward, not aft, between Mach 0.6 and 0.8, so HPR Sim doesn’t. This rocket’s top speed, Mach 0.56, is well below either.

Flow::axial(0.0) in place of Flow::axial(0.3) gives the low-speed value Barrowman’s method gives by hand.

The flight

The rocket flies from a 1.8 m (5.9 ft) vertical rail, 1,400 m (4,593 ft) up in New Mexico, with no wind. It has one parachute, 0.9 m (35 in) across (nominal diameter), which opens when the motor’s ejection charge fires.

  • Rail exit: 21.7 m/s (71 ft/s). The design has no rail buttons, so the simulator takes the rocket as off the rail when its aft end passes the top (rail exit).
  • Apogee: 1,144.5 m (3,755 ft) above the pad, 13.92 s after ignition (apogee).
  • Top speed: 187 m/s (614 ft/s), Mach 0.56: the fastest airspeed at the end of any time step. With no wind, the airspeed is also the speed over the ground.
  • Ejection: at 13.50 s, at 5.5 m/s (18 ft/s). The charge fires the 10 s delay after burnout. In the simulator, burnout is the thrust curve’s last point, 3.50 s for this motor. The ejection comes 0.42 s before apogee, while the rocket is still climbing slowly.

This motor has three times near the end of its burn, and they measure different things:

timewhat it iswhere it comes from
3.12 sthe burn time ThrustCurve.org publishes for the motorthe bundled catalog, which copies ThrustCurve.org’s values
3.13 sthe burn time the simulator works out from this motor’s thrust curve, by the same NFPA 1125 rule: from when the thrust first reaches 5% of its peak to when it last falls to 5%Solid motors lists it
3.50 sburnout: the curve’s last point, where the thrust reaches zerothe thrust curve; the ejection delay counts from here
  • The first two differ by 0.01 s. The simulator bundles a motor only if its computed burn time is within 1% of ThrustCurve.org’s (Solid motors).
  • From 3.13 s to 3.50 s the motor still pushes, with under 5% of its peak thrust. The curve’s peak is 103 N, so that’s under about 5 N. The burn time leaves that tail out; the flight doesn’t.

The fin set as a design file

The last lines are the fin set in a design file’s JSON. As a design file explains the form.

The program, step by step

This is the whole program, line for line the file CI runs.

//! Your own rocket: a 54 mm rocket built part by part in Rust, with a motor from the bundled
//! catalog. It prints the rocket's mass, center of gravity, center of pressure and stability
//! margin, then flies it.
//!
//! Run it from anywhere in the repository:
//!
//! ```text
//! cargo run --example own_rocket -p fusionspace-hpr-sim
//! ```
//!
//! The documentation site's *Your own rocket* page (`docs/your-own-rocket.md`) walks through it.
//! What it prints is kept next to it in `own_rocket.output.txt`, and CI checks that the two still
//! agree (`cargo xtask examples --check`).

#![allow(
    clippy::print_stdout,
    reason = "the project's lints forbid printing in library code, and this program exists to print"
)]

use std::error::Error;

use hpr_aero::{AeroModel, Flow};
use hpr_core::geodesy::Geodetic;
use hpr_design::{
    AutoDimension, BodyTube, Component, Configuration, FinCrossSection, FinPlanform, FinSet,
    Ignition, InnerTube, MassComponent, Material, MotorMount, MountedMotor, NoseCone, NoseShape,
    Overrides, Packing, Part, Position, ReferenceDiameter, Rocket, Shoulder, Stage, Wall,
    materials,
};
use hpr_motor::{Catalog, Delay};
use hpr_sim::{
    CanopyType, Channel, Device, DeviceDrag, Environment, EventKind, FlightSettings, Rail,
    Recorder, Simulation, Trigger,
};

fn main() -> Result<(), Box<dyn Error>> {
    // The nose: a 22 cm tangent ogive of ABS with a 1.5 mm wall and a 6 cm shoulder. Its base
    // radius and its shoulder's radius are automatic: they fit the tube behind it.
    let mut nose = component(
        "nose",
        Part::NoseCone(NoseCone {
            shape: NoseShape::Ogive { radius_ratio: 1.0 },
            length_m: 0.22,
            base_radius_m: 0.0,
            wall: Wall::Shell {
                thickness_m: 0.0015,
            },
            shoulder: Some(Shoulder {
                length_m: 0.06,
                outer_radius_m: 0.0,
                thickness_m: 0.0015,
                capped: true,
            }),
            material: material("abs")?,
        }),
        None,
    );
    nose.auto = vec![AutoDimension::BaseRadius, AutoDimension::ShoulderRadius];

    // The airframe: 90 cm of kraft phenolic tube, 56.3 mm across, with a 1.15 mm wall.
    let mut airframe = component(
        "airframe",
        Part::BodyTube(BodyTube {
            length_m: 0.9,
            outer_radius_m: 0.02815,
            thickness_m: 0.00115,
            material: material("kraft_phenolic")?,
        }),
        None,
    );

    // Inside it, flush with its aft end, a 20 cm motor mount tube with a 29 mm bore. The motor's
    // nozzle will stick out 5 mm past it.
    let mut mount = component(
        "motor-mount",
        Part::InnerTube(InnerTube {
            length_m: 0.2,
            outer_radius_m: 0.0155,
            thickness_m: 0.001,
            radial_offset_m: 0.0,
            angle_rad: 0.0,
            material: material("kraft_phenolic")?,
            cluster_m: Vec::new(),
        }),
        Some(Position::Bottom { aft_offset_m: 0.0 }),
    );
    mount.motor_mount = Some(MotorMount { overhang_m: 0.005 });

    // Three trapezoidal fins of 1/8 in birch plywood, flush with the aft end.
    let fins = component(
        "fins",
        Part::FinSet(FinSet {
            count: 3,
            planform: FinPlanform::Trapezoidal {
                root_chord_m: 0.1,
                tip_chord_m: 0.04,
                span_m: 0.045,
                sweep_m: 0.05,
            },
            thickness_m: 0.003175,
            cross_section: FinCrossSection::Rounded,
            tab: None,
            fillet: None,
            cant_rad: 0.0,
            base_angle_rad: 0.0,
            material: material("birch_plywood")?,
        }),
        Some(Position::Bottom { aft_offset_m: 0.0 }),
    );

    // The parachute, shock cord and altimeter, as one 200 g mass 7 cm below the tube's top, clear
    // of the nose's shoulder. Its packing is the cylinder the mass fills: 15 cm long, 5 cm across.
    let packing = Packing {
        length_m: 0.15,
        radius_m: 0.025,
        radial_offset_m: 0.0,
        angle_rad: 0.0,
    };
    let bay = MassComponent {
        mass_kg: 0.2,
        packing,
    };
    let top = Position::Top { aft_offset_m: 0.07 };
    let bay = component("recovery-bay", Part::MassComponent(bay), Some(top));
    // The fin set as a design file stores it, to print at the end.
    let fins_json = serde_json::to_string_pretty(&fins)?;
    airframe.children = vec![mount, fins, bay];

    // The motor: a Cesaroni H54 from the bundled catalog, found by its designation, with the
    // catalog's size, masses and thrust curve, and the 10 s delay its designation names.
    let catalog = Catalog::bundled()?;
    let entry = catalog
        .find("168H54-10A")
        .next()
        .ok_or("not in the catalog")?;
    let motor = MountedMotor {
        mount: "motor-mount".to_owned(),
        designation: entry.designation.clone(),
        diameter_m: entry.diameter_mm / 1000.0,
        length_m: entry.length_mm / 1000.0,
        motor: entry.bundled_motor()?,
        delay: Some(Delay::Seconds(10.0)),
        ignition: Ignition::Launch,
        failed_tubes: Vec::new(),
    };

    // The rocket: one stage, and one configuration, "h54", with that motor in the mount.
    let rocket = Rocket {
        name: "My 54 mm rocket".to_owned(),
        stages: vec![Stage {
            id: "sustainer".to_owned(),
            name: String::new(),
            components: vec![nose, airframe],
            overrides: Overrides::default(),
            override_rule: Default::default(),
            added_mass: None,
            drag_override: None,
            parallel: None,
        }],
        reference_diameter: ReferenceDiameter::Maximum {},
        configurations: vec![Configuration {
            id: "h54".to_owned(),
            name: String::new(),
            motors: vec![motor],
        }],
    };

    // Place the parts and the motor, and find the mass properties with the motor full and spent.
    // A point `s` meters aft of the nose tip is at z = -s in the body frame.
    let assembly = rocket.assemble("h54")?;
    let full = assembly.mass_properties(0.0);
    let spent = assembly.dry_mass_properties();
    let (cg_liftoff_m, cg_burnout_m) = (-full.cg_m.z, -spent.cg_m.z);

    // The center of pressure by Barrowman's method, at Mach 0.3 with the air straight along the
    // axis. Barrowman's slopes are the small-angle limit, so this is the CP at small angles.
    let flow = Flow::axial(0.3);
    let aero = AeroModel::new(&assembly.layout)?;
    let total = aero.normal_force(&flow)?;
    let cp_m = total.cp_station_m.ok_or("no normal force")?;
    let calibers = |cg_m: f64| (cp_m - cg_m) / assembly.layout.reference_diameter_m;

    println!(
        "{} ({} {}): {:.3} m long, {:.1} mm across",
        rocket.name,
        entry.manufacturer_abbrev,
        entry.designation,
        assembly.layout.length_m,
        assembly.layout.reference_diameter_m * 1000.0,
    );
    println!("Not yet validated: see the Accuracy page before trusting these numbers.");
    println!();
    println!("                                   liftoff   burnout");
    let (m0, m1) = (full.mass_kg, spent.mass_kg);
    println!("mass (kg)                          {m0:>7.3} {m1:>9.3}");
    println!("center of gravity (m from nose)    {cg_liftoff_m:>7.3} {cg_burnout_m:>9.3}");
    println!("center of pressure (m from nose)   {cp_m:>7.3} {cp_m:>9.3}");
    let (s0, s1) = (calibers(cg_liftoff_m), calibers(cg_burnout_m));
    println!("stability margin (calibers)        {s0:>7.2} {s1:>9.2}");
    println!();
    println!("Normal-force slope (per radian) and center of pressure, at Mach 0.3:");
    for part in aero.components(&flow)? {
        let force = part.normal_force;
        if let Some(station_m) = force.cp_station_m {
            let (id, slope) = (&part.id, force.slope_per_rad);
            println!("{id:<10} {slope:>5.2} at {station_m:.3} m");
        }
    }
    let slope = total.slope_per_rad;
    println!("{:<10} {slope:>5.2} at {cp_m:.3} m", "rocket");

    // Fly it from a 1.8 m vertical rail, 1,400 m up in New Mexico, with no wind. The parachute
    // opens when the motor's ejection charge fires, 10 s after burnout.
    let site = Geodetic::from_degrees(32.99, -106.97, 1400.0)?;
    let parachute = Device::new(
        "parachute",
        DeviceDrag::canopy(CanopyType::FlatCircular, 0.9),
        Trigger::MotorDelay { motor: 0 },
    );
    let simulation = Simulation::new(
        &rocket,
        "h54",
        Environment::standard(site)?,
        Rail::vertical(1.8),
        FlightSettings::default(),
    )?
    .with_recovery(vec![parachute])?;

    // A recorder keeps the airspeed and the Mach number at the end of every step.
    let mut recorder = Recorder::new(vec![Channel::Airspeed, Channel::Mach], None)?;
    let flight = simulation.run(&mut recorder)?;
    let rows = recorder.rows();
    let fastest = rows.iter().max_by(|a, b| a[0].total_cmp(&b[0]));
    let fastest = fastest.ok_or("no steps")?;
    let rail_exit = flight.event(EventKind::RailExit).ok_or("no rail exit")?;
    let apogee = flight.event(EventKind::Apogee).ok_or("no apogee")?;
    let ejection = flight.event(EventKind::Trigger(0)).ok_or("no ejection")?;
    let (rail_exit, apogee, ejection) = (rail_exit.sample, apogee.sample, ejection.sample);

    println!();
    println!("From a 1.8 m vertical rail, with no wind:");
    let speed_m_s = rail_exit.cg_velocity_enu_m_s.length();
    println!("Rail exit:  {speed_m_s:.1} m/s");
    let (height_m, time_s) = (apogee.height_above_ground_m, apogee.time_s);
    println!("Apogee:     {height_m:.1} m above the pad, at {time_s:.2} s");
    println!("Top speed:  {:.0} m/s (Mach {:.2})", fastest[0], fastest[1]);
    let (time_s, speed_m_s) = (ejection.time_s, ejection.cg_velocity_enu_m_s.length());
    println!("Ejection:   at {time_s:.2} s, at {speed_m_s:.1} m/s");

    // The whole rocket as a design file's text, JSON, and read back from it.
    let text = serde_json::to_string_pretty(&rocket)?;
    let read_back: Rocket = serde_json::from_str(&text)?;
    if read_back != rocket {
        return Err("the design file doesn't read back as the same rocket".into());
    }
    println!();
    println!("The fin set, as the design file stores it:");
    println!("{fins_json}");
    Ok(())
}

/// A built-in material by its id; `hpr_design::materials` lists them, each with its source.
fn material(id: &str) -> Result<Material, String> {
    materials::find(id)
        .map(|builtin| builtin.material())
        .ok_or_else(|| format!("no built-in material `{id}`"))
}

/// A node of the design tree holding `part`, placed at `position` along its parent. Body
/// components (nose cones, body tubes and transitions) have no position: they stack from the nose.
fn component(id: &str, part: Part, position: Option<Position>) -> Component {
    Component {
        id: id.to_owned(),
        name: String::new(),
        part,
        position,
        auto: Vec::new(),
        motor_mount: None,
        finish: None,
        overrides: Overrides::default(),
        overrides_include_children: false,
        drag_override: None,
        children: Vec::new(),
    }
}

It has eight steps.

  1. The parts. Each part is a Rust value from the hpr_design crate, wrapped in a Component. A component is a node of the design tree, with an id, the part, and where it sits. The component helper at the program’s end fills in the fields a part seldom needs: a display name, a surface finish, mass overrides and children. Part lists every kind of part.
  2. Where each part sits. Nose cones, body tubes and transitions are body components. They go in a stage’s list, nose first, and stack from the nose tip aft, so they have no position. Every other part hangs from a body component, or from an inner tube, and has a Position. A position is Top, Middle, Bottom, After or Absolute, with an offset in meters, positive aft (Positions). The mount and the fins are at Bottom with no offset, flush with the aft end.
    • A dimension named in a component’s auto list is taken from the parts around it, and the value stored for it (0 here) is ignored. The nose’s base radius and its shoulder’s radius follow the airframe (Automatic dimensions). Other parts can take theirs the same way: a tube fin set’s outer_radius_m, for one, can be automatic. Then three tubes or more are wide enough to touch the body and each other, and no wider, closing the ring. One or two tubes take the body’s radius.
    • Setting motor_mount makes a body tube or inner tube a motor mount. Its overhang_m is how far the nozzle sits aft of the mount’s end.
    • A MassComponent is a mass and its Packing: the size of the solid cylinder the simulator spreads the mass through. Here it’s 0.15 m (5.9 in) long with radius_m 0.025, so 50 mm (2.0 in) across, inside the airframe’s 54 mm (2.1 in) bore.
      • The length places the mass. Its CG is the cylinder’s middle, 0.145 m (5.71 in) below the airframe’s top, since the cylinder starts 7 cm (2.8 in) down.
      • Of the mass properties, the radius changes only the moments of inertia: how hard the mass is to turn.
      • A cylinder a little wider than the tube’s bore, within the fit tolerance, gets a warning; any wider is an error. AutoDimension::PackedRadius in the component’s auto list fits it to the bore instead.
      • radial_offset_m and angle_rad move it off the rocket’s axis. Parachutes, streamers and shock cords have a packing too.
  3. Materials. material("abs") looks up one of the simulator’s 49 built-in materials by its id, each with the source of its density (Mass properties). The materials page of the API reference lists them. For a material of your own, Material::bulk(name, kg_m3) takes a name and a density in kg/m³.
  4. The motor. Catalog::bundled() is the catalog of ThrustCurve.org’s 1,004 solid motors that comes with the simulator. find looks one up by its designation or common name, ignoring case, spaces and hyphens, so "h54" finds this one too. bundled_motor() builds the motor from its thrust curve and the catalog’s size and masses.
    • The MountedMotor names the mount by its id, and carries the ejection delay and the case’s diameter and length. It says when the motor lights: Ignition::Launch here, and a later time for an air start or a sustainer (Staging).
    • The design checks compare the case with its mount. A case wider than the mount’s bore is an error. But a nominal 29 mm motor in a 1.140 in (28.956 mm) tube only warns. That’s because the real case is narrower than its name (a nominal motor in its matching tube).
    • While the motor burns, the simulator also uses the case’s diameter for the base drag, the drag on the rocket’s flat aft end. The part of that end the burning case covers gets none.
    • Solid motors describes the bundled motors, and shows how to use a motor file of your own, such as one from ThrustCurve.org, instead.
  5. The rocket. A Rocket holds its stages (one here), how its reference diameter is chosen, and its configurations. ReferenceDiameter::Maximum {} takes the diameter of the widest body part, the 56.3 mm (2.2 in) airframe. The margin and the aerodynamic coefficients are measured by that diameter (reference area). A configuration is one choice of motors, at most one per mount, under an id; this rocket has one, "h54". Add another to compare motors in the same rocket.
  6. Mass, CG and CP.
    • assemble places every part and the configuration’s motor, and returns an Assembly.
    • Its mass_properties(t) is the whole rocket t seconds after ignition, and dry_mass_properties() is the rocket with every motor spent.
    • Each gives a mass, a CG and the moments of inertia, which the flight needs. The CG, cg_m, is in the body frame, whose origin is the nose tip and whose z axis points forward, out through the nose. So a point s meters aft of the tip has z=−s, and the CG’s station is −cg_m.z.
    • AeroModel::new builds the aerodynamic model from the placed parts. Its normal_force, at Flow::axial(0.3) (Mach 0.3, with the air straight along the axis), returns the rocket’s slope and its CP, cp_station_m. Barrowman’s slopes are the small-angle limit, so this is the CP at small angles of attack. components, at the same flow, returns each part’s share.
    • The margin is the CP’s station less the CG’s, divided by the reference diameter, assembly.layout.reference_diameter_m.
  7. The flight. This is as in Getting started, with three differences.
    • Simulation::new names the configuration to fly, "h54", and runs the design’s checks first (Checks).
    • The parachute’s trigger is Trigger::MotorDelay { motor: 0 }: the ejection charge of the configuration’s first motor (Recovery).
    • A Recorder keeps the airspeed and the Mach number at the end of every step, and the program takes the row with the highest airspeed. Recording a trajectory explains recorders.
  8. The design file. The end of the program writes the rocket as JSON, reads it back, and prints the fin set’s part of it. As a design file explains.

Design files

Write the rocket as a design file, and see what else a design can hold.

As a design file

A design file is a rocket written as text, to keep, share or edit outside Rust. Here it’s the rocket’s JSON. That’s also the rocket key of a document of the HPR design format. That form adds a versioned header, the motor configurations, recovery and what a .ork held. To write the JSON and read it back:

  • serde_json::to_string_pretty(&rocket) gives the text, and std::fs::write saves it to a file.
  • serde_json::from_str::<Rocket>(&text) reads it back. The program checks that the rocket it reads back is the one it wrote.

The JSON follows the Rust types, so the API reference documents every key. The fin set at the end of the output shows the rules:

in Rustin the JSONin the output
a struct’s fielda key with the field’s name"thickness_m": 0.003175
the unit in the nameSI units: _m meters, _kg kilograms, _rad radians, kg_m3 kg/m³"span_m": 0.045
a Partan object with one key, the kind of part"part": { "fin_set": { … } }
a shape, planform, wall, density, finish or delayan object whose "kind" names it"planform": { "kind": "trapezoidal", … }
a Positionan object whose "from" names it"position": { "from": "bottom", "aft_offset_m": 0.0 }
a choice with no valuesa string"cross_section": "rounded"
Nonenull"tab": null
  • Some keys can be left out, and take a default: a component’s name, or a fin set’s tab, fillet and cant_rad, for example. cant_rad is the fins’ cant in radians, 0 by default; a cant spins the rocket (Roll: forcing and damping). fillet gives the fins’ fillets, a radius and a material. It isn’t written when there are none, so the output above has no fillet key. In Rust it’s, for example, fillet: Some(FinFillet { radius_m: 0.005, material: material("epoxy")? }), with FinFillet added to the use hpr_design::{…} list.
  • A key the simulator doesn’t know is refused, so a misspelt key is an error rather than silently ignored.
  • A mounted motor is stored whole: its thrust curve, masses and size. Its designation is only a label, so a design file doesn’t depend on the catalog.

For a complete file of a similar rocket, see synthetic-54mm-three-fin.json. The rocket has centering rings, rail buttons, a parachute and a shock cord as parts, and flies on a 38 mm Cesaroni I175. A program in the repository writes the files in that folder, so edit a copy rather than the file.

The file holds the rocket alone. It’s the rocket key of the open design format, a documented and versioned design file with a schema, without the rest of a .hpr file. The repository’s own designs are still kept this way.

What else a design can hold

The example leaves out several kinds of part and setting a design can have:

  • More parts: transitions, centering rings (whose radii can be automatic), launch lugs, rail buttons, parachutes, streamers and shock cords. Fins can be elliptical or freeform too (The design tree).
  • With rail buttons or launch lugs, the rocket leaves the rail when its last rail guide passes the top, not its aft end.
  • Weighed masses go in an Overrides. It sets a part’s mass, CG or inertia to measured values, for the part alone or with everything attached to it (Overrides).
  • hpr_design::checks::check lists a design’s problems (Checks). Errors, such as a motor wider than its mount, describe a rocket that can’t exist, and a simulation refuses them. Put the 38 mm motor H170M in this program’s 29 mm mount and it stops with MotorWiderThanMount. Warnings, such as a step in the body’s radius, don’t stop a flight.

Limits and next steps

What the example can’t do yet, and where to go from here.

What it can’t do yet

  • A rocket is built only in code or in JSON. The builder builds the same rocket in fewer lines of Rust, and the Python bindings build one from Python. hpr sim flies the JSON file from a terminal, but opens no parachute. A design file can carry a parachute’s weight as a mass part, but not the parachute itself or when it opens.
  • HPR Sim imports designs from one other program. OpenRocket .ork files are read (.ork design files). On a file’s own curves and the bundled motors alone, most motor configurations fly. hpr sim looks up a missing curve once and keeps what it finds (how many fly). Their parachutes and streamers fly as OpenRocket flies them. RockSim .rkt files can’t be read yet (RockSim import).
  • Drag near and past Mach 1 is lightly checked. Since drag through Mach 1 was built, the simulator’s own drag carries a flight from Mach 0 to 5, like its normal force. A flight that reaches Mach 5 stops with an error. Near and above the speed of sound, the drag has been checked against one wind tunnel, which measured from Mach 0.6 to 4.63. The simulator reads high there at every Mach number the tunnel measured, most of all with fins past Mach 1 (Aerodynamics).
  • Against a worked example in a U.S. Army design handbook, the body alone reads a little low faster than sound. Against RASAero II’s drag for Calisto, a rocket with a short, steep boattail, the whole rocket reads low faster than sound. From Mach 1.05 to 2, where the comparison stops, it reads 5% to 15% low (Aerodynamics). It read about a quarter low until the simulator modeled a boattail’s drag faster than sound, and the rest is only partly explained.
  • If your rocket goes supersonic, its drag there may be off either way. It may read low with a steep boattail. With thin, sharp fins, the drag of all but the base read 29.8% to 154.1% high from Mach 1.2 against the wind tunnel above. Treat a supersonic flight’s apogee as rough.
  • Staging needs its settings. A motor lights at launch unless its ignition says otherwise. So a two-stage design flies with both stages burning at once, until you give the sustainer its ignition and the flight a separation (Staging). A .ork file’s own ignitions and powered separations are read for you. The ignitions come with the rocket, but the separations don’t.
  • Turn the configuration’s stagings() into the flight’s separations with hpr::ork::separations, and pass them to the flight. Give each part a recovery device too, since the simulator refuses the flight without them. The example ork_two_stage.rs does both. The flights of OpenRocket’s two-stage, three-stage, cluster, air-start and parallel-booster examples are within 5% of OpenRocket’s apogee and largest speed, with three cluster apogees compared with OpenRocket’s flight without the cluster’s parachute, which opened before apogee (a two-stage and a cluster design against OpenRocket; results). One of a pod example’s staged flights isn’t: in the conditions of OpenRocket’s recorded flight its sustainer turns over before apogee in both programs, and reads 37.93% low (Design files).
  • Pieces that land on their own are yours to declare. A nose cone on a shock cord comes down with its rocket, and that’s what the simulator flies unless you say otherwise. To fly a nose cone, a section or a payload that leaves and lands on its own, give the flight an Ejection for each. Give each piece a recovery device too: a parachute, or its own tumble (Simulation::tumbling_piece). An ejection can push the pieces apart with the charge’s impulse (Ejection::with_impulse).
  • A .ork file’s recovery settings don’t make these ejections for you. A stage whose mass is overridden can’t be parted inside: remove the override, or put it on the components instead. Ejected pieces are checked against exact answers only (Recovery: ejected pieces, with the example ejected_pieces.rs).
  • Mass that moves in flight is yours to declare too. To slide ballast or a payload along the airframe, give the flight a MassShift for it with Simulation::with_shifts. A shift gives the part’s id, how far it moves (positive toward the tail), how long it takes, and a trigger. The triggers are the same kinds a parachute has. The center of mass, the inertia and the stability margin follow it, and Simulation::mass_properties gives them at any time.
  • A shift must start after the rocket leaves the rail. A flight that separates or ejects pieces can’t have one yet. Moving mass is checked against exact answers only (Moving mass, with the example moving_ballast.rs).
  • Mass released in flight is yours to declare too. To let ballast or a payload go, give it a MassRelease with Simulation::with_releases. A release gives the part’s id, a trigger, and the part’s own drag area once it’s out. The rest flies on without it, and the part falls to the ground on its own (FlightResult::released).
  • A release must come after the rocket leaves the rail. A flight can’t combine one with a separation, ejected pieces or a mass shift yet. Check the stability margin after a release: the simulator doesn’t warn. Released mass is checked against exact answers only (Released mass, with the example released_ballast.rs).
  • The simulator flies commercial solid motors only (COTS motors). With only catalog data, a motor’s own CG stays at its mid-length, full or spent (Solid motors).
  • Tube fins fly as ring wings, below Mach 0.8, with three tubes or more. Tube fins are open tubes that run along the body, touching it, in place of flat fins. Each tube’s slope comes from a cited ring-wing formula. Its center of pressure comes from Fletcher’s wind-tunnel rings for short tubes. For tubes longer than 1.5 diameters, the center of pressure comes from this project’s own derivation, a judgment.
  • The tube fins’ drag applies the flat fins’ rules. No tube fin rocket has been checked against a measurement. HPR Sim’s tube-fin drag probably reads low, so treat an apogee as high. On OpenRocket’s example HPR Sim’s margin is 0.79 calibers against OpenRocket’s 1.87; nothing measured says which is right.
  • A flight that reaches Mach 0.8 stops with the tube-fin model’s error. The simulator also refuses fewer than three tubes, solid tubes, and tubes that overlap each other. It refuses a tube shorter than a third of its diameter, and tube fins on a pod or a tumbling airframe (aerodynamics: Tube fins).
  • Pods fly on Barrowman’s rules, without their interference with the body. A pod set gives each pod’s parts their own normal force and drag, once per pod. It’s as if the airframe didn’t disturb the air around them. Nothing measured checks the pods yet, and a single pod’s off-axis moments are left out (aerodynamics: Pods). Canted fins on a pod are refused.
  • Two nose shapes have no drag of the simulator’s own, on a nose cone or a widening transition, since no drag data covers them. One is a bulged secant ogive: NoseShape::Ogive with a radius_ratio below 1, which bulges wider than the body just ahead of its base. The other is a Haack shape whose parameter C is above 1/3, past the LV-Haack (Shapes).
  • Since drag through Mach 1 was built, the drag buildup refuses those two nose shapes, naming the part. The CP still works, and so does a flight on a drag table from another tool. A flight on the simulator’s own drag stops with that error.
  • Faster than sound, every fin section takes a blunt leading edge’s drag. The square section takes a flat face’s, and the rounded and airfoil sections a rounded edge’s. The airfoil section differs from the rounded only in having no trailing-edge base drag. A blunt edge’s drag reads far high for thin, sharp fins. The one wind tunnel the simulator was measured against tested only double-wedge fins, so how well square or rounded edges fare is unmeasured (Drag limits).

Where next

FusionSpace HPRVersion 0.1.0Issued 2026-11-21In preparationAbout HPR Sim