Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch frame information from loaded Almanac #18

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ use nalgebra::{Matrix3, Vector3};
use std::f64::consts::PI;
use thiserror::Error;

use nyx::cosmic::eclipse::{eclipse_state, EclipseState};
use nyx::cosmic::{
eclipse::{eclipse_state, EclipseState},
SPEED_OF_LIGHT_M_S,
};

use anise::{
almanac::metaload::MetaFile,
constants::{
frames::{EARTH_J2000, SUN_J2000},
SPEED_OF_LIGHT_KM_S,
Expand Down Expand Up @@ -213,16 +215,8 @@ impl<I: std::ops::Fn(Epoch, SV, usize) -> Option<InterpolationResult>> Solver<I>
/// in Fixed Altitude or Time Only modes.
/// - interpolator: function pointer to external method to provide 3D interpolation results.
pub fn new(cfg: &Config, initial: Option<Position>, interpolator: I) -> Result<Self, Error> {
// Regularly refer to https://github.com/nyx-space/anise/blob/master/data/ci_config.dhall for the latest CRC, although it should not change between minor versions!
// NB: a default almanac will soon be provided by ANISE directly
// this triggers a network access at least once
let almanac = Almanac::default()
.load_from_metafile(MetaFile {
uri: "http://public-data.nyxspace.com/anise/v0.4/pck08.pca".to_string(),
crc32: Some(3072159656), // Specifying the CRC allows only downloading the data once.
})
.map_err(Error::Almanac)?;

// Default Alamanac, valid until 2035
let almanac = Almanac::until_2035().map_err(Error::Almanac)?;
gwbres marked this conversation as resolved.
Show resolved Hide resolved
/*
* print more infos
*/
Expand Down Expand Up @@ -315,6 +309,8 @@ impl<I: std::ops::Fn(Epoch, SV, usize) -> Option<InterpolationResult>> Solver<I>
})
.collect();

let earth_j2000 = self.almanac.frame_from_uid(EARTH_J2000).unwrap();
gwbres marked this conversation as resolved.
Show resolved Hide resolved

/* interpolate positions */
let mut pool: Vec<Candidate> = pool
.iter()
Expand Down Expand Up @@ -384,12 +380,12 @@ impl<I: std::ops::Fn(Epoch, SV, usize) -> Option<InterpolationResult>> Solver<I>
if state.velocity.is_some() {
const EARTH_SEMI_MAJOR_AXIS_WGS84: f64 = 6378137.0_f64;
const EARTH_GRAVITATIONAL_CONST: f64 = 3986004.418 * 10.0E8;
let orbit = state.orbit(cd.t_tx, EARTH_J2000);
let orbit = state.orbit(cd.t_tx, earth_j2000);
let ea_rad = deg2rad(orbit.ea_deg().map_err(Error::Physics)?);
let gm = (EARTH_SEMI_MAJOR_AXIS_WGS84 * EARTH_GRAVITATIONAL_CONST).sqrt();
let bias = -2.0_f64 * orbit.ecc().map_err(Error::Physics)? * ea_rad.sin() * gm
/ SPEED_OF_LIGHT_KM_S
/ SPEED_OF_LIGHT_KM_S
/ SPEED_OF_LIGHT_M_S
/ SPEED_OF_LIGHT_M_S
* Unit::Second;
debug!("{} ({}) : relativistic clock bias: {}", cd.t, cd.sv, bias);
cd.clock_corr += bias;
Expand All @@ -404,7 +400,7 @@ impl<I: std::ops::Fn(Epoch, SV, usize) -> Option<InterpolationResult>> Solver<I>
if let Some(min_rate) = self.cfg.min_sv_sunlight_rate {
pool.retain(|cd| {
let state = cd.state.unwrap(); // infaillible
let orbit = state.orbit(cd.t, EARTH_J2000);
let orbit = state.orbit(cd.t, earth_j2000);
let state = eclipse_state(orbit, SUN_J2000, EARTH_J2000, &self.almanac).unwrap();
let eclipsed = match state {
EclipseState::Umbra => true,
Expand Down Expand Up @@ -538,7 +534,7 @@ impl<I: std::ops::Fn(Epoch, SV, usize) -> Option<InterpolationResult>> Solver<I>
q: output.q_covar4x4(),
timescale: self.cfg.timescale,
velocity: Vector3::<f64>::default(),
dt: Duration::from_seconds(x[3] / SPEED_OF_LIGHT_KM_S),
dt: Duration::from_seconds(x[3] / SPEED_OF_LIGHT_M_S),
};

// First solution
Expand Down
Loading