use astrodyn_dynamics::mass::MassPropertiesTyped;
use astrodyn_dynamics::rotational::RotationalStateTyped;
use astrodyn_dynamics::state::TranslationalStateTyped;
use astrodyn_dynamics::{MassProperties, RotationalState, TranslationalState};
use astrodyn_quantities::aliases::{AngularVelocity, InertiaTensor, Position, Velocity};
use astrodyn_quantities::body_attitude::BodyAttitude;
use astrodyn_quantities::frame::{
BodyFrame, Frame, Planet, PlanetInertial, RootInertial, SelfRef, StructuralFrame, Vehicle,
};
use uom::si::f64::Mass;
use uom::si::mass::kilogram;
#[inline]
pub fn mass_typed_to_raw<V: Vehicle>(m: &MassPropertiesTyped<V>) -> MassProperties {
MassProperties {
mass: m.mass.get::<kilogram>(),
inverse_mass: m.inverse_mass,
inertia: m.inertia.as_dmat3(),
inverse_inertia: m.inverse_inertia,
position: m.center_of_mass.raw_si(),
t_parent_this: m.t_parent_this,
dirty: m.dirty,
}
}
#[inline]
pub fn mass_raw_to_typed<V: Vehicle>(mp: &MassProperties) -> MassPropertiesTyped<V> {
MassPropertiesTyped::<V>::with_inertia(
Mass::new::<kilogram>(mp.mass),
InertiaTensor::<BodyFrame<V>>::from_dmat3_unchecked(mp.inertia), Position::<StructuralFrame<V>>::from_raw_si(mp.position), )
.with_t_parent_this(mp.t_parent_this)
}
#[inline]
pub fn rot_typed_to_raw<V: Vehicle>(s: &RotationalStateTyped<V>) -> RotationalState {
RotationalState {
quaternion: s.q_inertial_body.to_jeod_quat(),
ang_vel_body: s.ang_vel_body.raw_si(),
}
}
#[inline]
pub fn rot_raw_to_typed<V: Vehicle>(s: &RotationalState) -> RotationalStateTyped<V> {
RotationalStateTyped::<V>::new(
BodyAttitude::from_jeod_quat(s.quaternion),
AngularVelocity::<BodyFrame<V>>::from_raw_si(s.ang_vel_body), )
}
#[inline]
pub fn trans_typed_to_raw<F: Frame>(s: &TranslationalStateTyped<F>) -> TranslationalState {
TranslationalState {
position: s.position.raw_si(),
velocity: s.velocity.raw_si(),
}
}
#[inline]
pub fn trans_raw_to_typed<F: Frame>(s: &TranslationalState) -> TranslationalStateTyped<F> {
TranslationalStateTyped::<F> {
position: Position::<F>::from_raw_si(s.position), velocity: Velocity::<F>::from_raw_si(s.velocity), }
}
#[inline]
pub fn trans_raw_to_root(s: &TranslationalState) -> TranslationalStateTyped<RootInertial> {
trans_raw_to_typed::<RootInertial>(s)
}
#[inline]
pub fn trans_raw_to_planet<P: Planet>(
s: &TranslationalState,
) -> TranslationalStateTyped<PlanetInertial<P>> {
trans_raw_to_typed::<PlanetInertial<P>>(s)
}
#[inline]
pub fn rot_raw_to_self_ref(s: &RotationalState) -> RotationalStateTyped<SelfRef> {
rot_raw_to_typed::<SelfRef>(s)
}
#[inline]
pub fn mass_raw_to_self_ref(mp: &MassProperties) -> MassPropertiesTyped<SelfRef> {
mass_raw_to_typed::<SelfRef>(mp)
}