use rockets_engine::{
ballistics::{Atmosphere, BallisticForces},
ControlInput, FlightState, IntegratorSettings, Motor, Rocket, Simulator, ThrustCurve,
ThrustPoint, Vec3,
};
fn main() -> Result<(), rockets_engine::Error> {
let curve = ThrustCurve::new(vec![
ThrustPoint {
time_s: 0.0,
thrust_n: 0.0,
},
ThrustPoint {
time_s: 0.1,
thrust_n: 20.0,
},
ThrustPoint {
time_s: 0.9,
thrust_n: 15.0,
},
ThrustPoint {
time_s: 1.0,
thrust_n: 0.0,
},
])?;
let motor = Motor::new(curve, 0.04, 0.2)?; let rocket = Rocket::new(0.18, Some(motor))?;
let forces = BallisticForces::new(
0.025,
vec![(0.0, 0.45), (0.8, 0.5), (1.2, 0.7), (3.0, 0.4)], Atmosphere::default(),
Vec3::new(2.0, 0.0, 0.0),
)?;
let simulator = Simulator::new(rocket, forces, IntegratorSettings::default())?;
let mut state = FlightState {
time_s: 0.0,
position_m: Vec3::new(0.0, 2.0, 0.0),
velocity_mps: Vec3::new(2.0, 8.0, 0.0),
};
for _ in 0..100 {
let result = simulator.step(&state, 0.05, ControlInput::along(Vec3::new(0.3, 1.0, 0.0)))?;
state = result.state;
if state.time_s % 0.5 < 1e-9 {
println!(
"t = {:4.1} s | altitude {:7.2} m | speed {:6.2} m/s | mass {:.3} kg",
state.time_s,
state.position_m.y,
state.velocity_mps.norm(),
result.rocket.mass_kg
);
}
}
Ok(())
}