Skip to content

Commit

Permalink
Merge pull request #321 from nyx-space/320-support-spk-type-3-chebysh…
Browse files Browse the repository at this point in the history
…ev-position-and-velocity

Support SPK Type 3 chebyshev position and velocity
  • Loading branch information
ChristopherRabotin authored Sep 24, 2024
2 parents 4fbd5b5 + 91bdc93 commit a28d790
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 48 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
wget -O data/de430.bsp http://public-data.nyxspace.com/anise/de430.bsp
wget -O data/de440s.bsp http://public-data.nyxspace.com/anise/de440s.bsp
wget -O data/de440.bsp http://public-data.nyxspace.com/anise/de440.bsp
wget -O data/de440_type3.bsp http://public-data.nyxspace.com/anise/de440_type3.bsp
wget -O data/pck08.pca http://public-data.nyxspace.com/anise/v0.4/pck08.pca
wget -O data/pck11.pca http://public-data.nyxspace.com/anise/v0.4/pck11.pca
wget -O data/moon_fk.epa http://public-data.nyxspace.com/anise/v0.4/moon_fk.epa
Expand Down Expand Up @@ -112,6 +113,7 @@ jobs:
wget -O data/de430.bsp http://public-data.nyxspace.com/anise/de430.bsp
wget -O data/de440s.bsp http://public-data.nyxspace.com/anise/de440s.bsp
wget -O data/de440.bsp http://public-data.nyxspace.com/anise/de440.bsp
wget -O data/de440_type3.bsp http://public-data.nyxspace.com/anise/de440_type3.bsp
wget -O data/pck08.pca http://public-data.nyxspace.com/anise/v0.4/pck08.pca
wget -O data/pck11.pca http://public-data.nyxspace.com/anise/v0.4/pck11.pca
wget -O data/gmat-hermite.bsp http://public-data.nyxspace.com/anise/ci/gmat-hermite.bsp
Expand Down Expand Up @@ -182,6 +184,7 @@ jobs:
wget -O data/de430.bsp http://public-data.nyxspace.com/anise/de430.bsp
wget -O data/de440s.bsp http://public-data.nyxspace.com/anise/de440s.bsp
wget -O data/de440.bsp http://public-data.nyxspace.com/anise/de440.bsp
wget -O data/de440_type3.bsp http://public-data.nyxspace.com/anise/de440_type3.bsp
wget -O data/pck08.pca http://public-data.nyxspace.com/anise/v0.4/pck08.pca
wget -O data/pck11.pca http://public-data.nyxspace.com/anise/v0.4/pck11.pca
wget -O data/gmat-hermite.bsp http://public-data.nyxspace.com/anise/ci/gmat-hermite.bsp
Expand Down Expand Up @@ -214,6 +217,7 @@ jobs:
cargo llvm-cov test --no-report validate_bpc_to_iau_rotations -- --nocapture --ignored
cargo llvm-cov test --no-report validate_jplde_de440s_no_aberration --features spkezr_validation -- --nocapture --ignored
cargo llvm-cov test --no-report validate_jplde_de440s_aberration_lt --features spkezr_validation -- --nocapture --ignored
cargo llvm-cov test --no-report validate_jplde_de440_type3_no_aberration --features spkezr_validation -- --nocapture --ignored
cargo llvm-cov test --no-report validate_hermite_type13_from_gmat --features spkezr_validation -- --nocapture --ignored
cargo llvm-cov test --no-report validate_lagrange_type9_with_varying_segment_sizes --features spkezr_validation -- --nocapture --ignored
cargo llvm-cov test --no-report ut_embed --features embed_ephem
Expand Down
14 changes: 13 additions & 1 deletion anise/src/ephemerides/translate_to_parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use crate::ephemerides::EphemInterpolationSnafu;
use crate::hifitime::Epoch;
use crate::math::cartesian::CartesianState;
use crate::math::Vector3;
use crate::naif::daf::datatypes::{HermiteSetType13, LagrangeSetType9, Type2ChebyshevSet};
use crate::naif::daf::datatypes::{
HermiteSetType13, LagrangeSetType9, Type2ChebyshevSet, Type3ChebyshevSet,
};
use crate::naif::daf::{DAFError, DafDataType, NAIFDataSet, NAIFSummaryRecord};
use crate::prelude::Frame;

Expand Down Expand Up @@ -64,6 +66,16 @@ impl Almanac {
data.evaluate(epoch, summary)
.context(EphemInterpolationSnafu)?
}
DafDataType::Type3ChebyshevSextuplet => {
let data =
spk_data
.nth_data::<Type3ChebyshevSet>(idx_in_spk)
.context(SPKSnafu {
action: "fetching data for interpolation",
})?;
data.evaluate(epoch, summary)
.context(EphemInterpolationSnafu)?
}
DafDataType::Type9LagrangeUnequalStep => {
let data = spk_data
.nth_data::<LagrangeSetType9>(idx_in_spk)
Expand Down
30 changes: 30 additions & 0 deletions anise/src/math/interpolation/chebyshev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,33 @@ pub fn chebyshev_eval(
let deriv = (w[0] + normalized_time * dw[0] - dw[1]) / spline_radius_s;
Ok((val, deriv))
}

/// Attempts to evaluate a Chebyshev polynomial given the coefficients, returning only the value
///
/// # Notes
/// 1. At this point, the splines are expected to be in Chebyshev format and no verification is done.
pub fn chebyshev_eval_poly(
normalized_time: f64,
spline_coeffs: &[f64],
eval_epoch: Epoch,
degree: usize,
) -> Result<f64, InterpolationError> {
// Workspace array
let mut w = [0.0_f64; 3];

for j in (2..=degree + 1).rev() {
w[2] = w[1];
w[1] = w[0];
w[0] = (spline_coeffs
.get(j - 1)
.ok_or(InterpolationError::MissingInterpolationData { epoch: eval_epoch })?)
+ (2.0 * normalized_time * w[1] - w[2]);
}

let val = (spline_coeffs
.first()
.ok_or(InterpolationError::MissingInterpolationData { epoch: eval_epoch })?)
+ (normalized_time * w[0]);

Ok(val)
}
2 changes: 1 addition & 1 deletion anise/src/math/interpolation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod chebyshev;
mod hermite;
mod lagrange;

pub use chebyshev::chebyshev_eval;
pub use chebyshev::{chebyshev_eval, chebyshev_eval_poly};
pub use hermite::hermite_eval;
use hifitime::Epoch;
pub use lagrange::lagrange_eval;
Expand Down
45 changes: 0 additions & 45 deletions anise/src/naif/daf/datatypes/chebyshev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,51 +271,6 @@ impl<'a> NAIFDataRecord<'a> for Type2ChebyshevRecord<'a> {
}
}

#[derive(PartialEq)]
pub struct Type3ChebyshevRecord<'a> {
pub midpoint: Epoch,
pub radius: Duration,
pub x_coeffs: &'a [f64],
pub y_coeffs: &'a [f64],
pub z_coeffs: &'a [f64],
pub vx_coeffs: &'a [f64],
pub vy_coeffs: &'a [f64],
pub vz_coeffs: &'a [f64],
}

impl<'a> fmt::Display for Type3ChebyshevRecord<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"start: {}\tend: {}\nx: {:?}\ny: {:?}\nz: {:?}\nvx: {:?}\nvy: {:?}\nvz: {:?}",
self.midpoint - self.radius,
self.midpoint + self.radius,
self.x_coeffs,
self.y_coeffs,
self.z_coeffs,
self.vx_coeffs,
self.vy_coeffs,
self.vz_coeffs
)
}
}

impl<'a> NAIFDataRecord<'a> for Type3ChebyshevRecord<'a> {
fn from_slice_f64(slice: &'a [f64]) -> Self {
let num_coeffs = (slice.len() - 2) / 6;
Self {
midpoint: Epoch::from_et_seconds(slice[0]),
radius: slice[1].seconds(),
x_coeffs: &slice[2..num_coeffs],
y_coeffs: &slice[2 + num_coeffs..num_coeffs * 2],
z_coeffs: &slice[2 + num_coeffs * 2..num_coeffs * 3],
vx_coeffs: &slice[2 + num_coeffs * 3..num_coeffs * 4],
vy_coeffs: &slice[2 + num_coeffs * 4..num_coeffs * 5],
vz_coeffs: &slice[2 + num_coeffs * 5..],
}
}
}

#[cfg(test)]
mod chebyshev_ut {
use crate::{
Expand Down
Loading

0 comments on commit a28d790

Please sign in to comment.