use crate::celestia::{Frame, Orbit};
use crate::dimensions::Vector3;
pub use super::thrustctrl::Mnvr;
pub trait DeltaVctrl
where
Self: Clone + Sized,
{
fn ctrl_vector(&self, state: &Orbit) -> Vector3<f64>;
fn next(&mut self, state: &Orbit);
}
#[derive(Clone, Debug)]
pub struct ImpulsiveBurns {
pub mnvrs: Vec<Mnvr>,
pub mnvr_no: usize,
}
impl ImpulsiveBurns {
pub fn from_mnvrs(mnvrs: Vec<Mnvr>) -> Self {
Self { mnvrs, mnvr_no: 0 }
}
}
impl DeltaVctrl for ImpulsiveBurns {
fn ctrl_vector(&self, state: &Orbit) -> Vector3<f64> {
if self.mnvr_no >= self.mnvrs.len() {
Vector3::zeros()
} else {
let next_mnvr = self.mnvrs[self.mnvr_no];
if next_mnvr.start <= state.dt && next_mnvr.end >= state.dt {
state.dcm_from_traj_frame(Frame::VNC).unwrap() * next_mnvr.vector
} else {
Vector3::zeros()
}
}
}
fn next(&mut self, state: &Orbit) {
if self.mnvr_no < self.mnvrs.len() {
let cur_mnvr = self.mnvrs[self.mnvr_no];
if state.dt >= cur_mnvr.end {
self.mnvr_no += 1;
}
}
}
}