1use anise::errors::{AlmanacError, PhysicsError};
20pub use anise::prelude::*;
21
22pub use crate::cosmic::{DragData, GuidanceMode, Mass, SRPData, Spacecraft};
23use crate::dynamics::DynamicsError;
24pub use crate::errors::NyxError;
25use crate::errors::StateError;
26use crate::linalg::allocator::Allocator;
27use crate::linalg::{DefaultAllocator, DimName, OMatrix, OVector};
28use crate::md::StateParameter;
29use snafu::Snafu;
30use std::fmt;
31
32pub trait TimeTagged {
34 fn epoch(&self) -> Epoch;
36 fn set_epoch(&mut self, epoch: Epoch);
38}
39
40pub trait State: Default + Copy + PartialEq + fmt::Display + fmt::LowerExp + Send + Sync
43where
44 Self: Sized,
45 DefaultAllocator:
46 Allocator<Self::Size> + Allocator<Self::Size, Self::Size> + Allocator<Self::VecLength>,
47{
48 type Size: DimName;
50 type VecLength: DimName;
51
52 fn zeros() -> Self {
55 unimplemented!()
56 }
57
58 fn to_vector(&self) -> OVector<f64, Self::VecLength>;
60
61 fn stm(&self) -> Result<OMatrix<f64, Self::Size, Self::Size>, DynamicsError> {
64 Err(DynamicsError::StateTransitionMatrixUnset)
65 }
66
67 fn reset_stm(&mut self) {
70 unimplemented!()
71 }
72
73 fn unset_stm(&mut self);
75
76 fn set(&mut self, epoch: Epoch, vector: &OVector<f64, Self::VecLength>);
78
79 fn set_with_delta_seconds(
82 mut self,
83 delta_t_s: f64,
84 vector: &OVector<f64, Self::VecLength>,
85 ) -> Self
86 where
87 DefaultAllocator: Allocator<Self::VecLength>,
88 {
89 self.set(self.epoch() + delta_t_s, vector);
90 self
91 }
92
93 fn epoch(&self) -> Epoch;
95 fn set_epoch(&mut self, epoch: Epoch);
97
98 fn add(self, _other: OVector<f64, Self::Size>) -> Self {
100 unimplemented!()
101 }
102
103 fn value(&self, param: StateParameter) -> Result<f64, StateError> {
105 Err(StateError::Unavailable { param })
106 }
107
108 fn set_value(&mut self, param: StateParameter, _val: f64) -> Result<(), StateError> {
111 Err(StateError::Unavailable { param })
112 }
113
114 fn orbit(&self) -> Orbit;
116
117 fn set_orbit(&mut self, _orbit: Orbit) {}
119}
120
121pub fn assert_orbit_eq_or_abs(left: &Orbit, right: &Orbit, epsilon: f64, msg: &str) {
122 if !left.eq_within(right, epsilon, epsilon) {
123 panic!(
124 r#"assertion failed: {}
125 left: `{:?}`,
126 right: `{:?}`"#,
127 msg, left, right
128 )
129 }
130}
131
132#[derive(Debug, PartialEq, Snafu)]
133#[snafu(visibility(pub(crate)))]
134pub enum AstroError {
135 #[snafu(display("B Plane jacobian invariant must be either VX, VY or VZ"))]
136 BPlaneInvariant,
137 #[snafu(display("operation requires a local frame"))]
138 NotLocalFrame,
139 #[snafu(display("partial derivatives not defined for this parameter"))]
140 PartialsUndefined,
141 #[snafu(display("Orbit is not hyperbolic so there is no hyperbolic anomaly."))]
142 NotHyperbolic,
143 #[snafu(display("physics error occured during astro computation: {source}"))]
144 AstroPhysics { source: PhysicsError },
145 #[snafu(display("ANISE Almanac error occured during astro computation: {source}"))]
146 AstroAlmanac {
147 #[snafu(source(from(AlmanacError, Box::new)))]
148 source: Box<AlmanacError>,
149 },
150}
151
152mod orbitdual;
154pub use self::orbitdual::*;
155
156mod bplane;
158pub use self::bplane::*;
159
160mod spacecraft;
162pub use self::spacecraft::*;
163
164pub mod eclipse;
166
167pub const SPEED_OF_LIGHT_M_S: f64 = SPEED_OF_LIGHT_KM_S * 1e3;
169pub use anise::constants::SPEED_OF_LIGHT_KM_S;
170
171pub const AU: f64 = 149_597_870.700;
173
174pub const STD_GRAVITY: f64 = 9.80665;