@@ -2,12 +2,14 @@ use crate::{cli::Context, positioning::BufferTrait};
2
2
use std:: collections:: HashMap ;
3
3
4
4
use gnss_rtk:: prelude:: {
5
- Arc , Bodies , Cosm , Epoch , Frame , InterpolationResult as RTKInterpolationResult , LightTimeCalc ,
6
- TimeScale , Vector3 , SV ,
5
+ Almanac , Epoch , InterpolationResult as RTKInterpolationResult , TimeScale , Vector3 , EARTH_J2000 ,
6
+ SPK , SUN_J2000 , SV ,
7
7
} ;
8
8
9
9
use rinex:: carrier:: Carrier ;
10
10
11
+ use anise:: almanac:: metaload:: MetaFile ;
12
+
11
13
#[ derive( Debug ) ]
12
14
struct Buffer {
13
15
inner : Vec < ( Epoch , ( f64 , f64 , f64 ) ) > ,
@@ -49,13 +51,13 @@ impl BufferTrait<(f64, f64, f64)> for Buffer {
49
51
/*
50
52
* Evaluates Sun / Earth vector in meters ECEF at "t"
51
53
*/
52
- fn sun_unit_vector ( ref_frame : & Frame , cosmic : & Arc < Cosm > , t : Epoch ) -> Vector3 < f64 > {
53
- let sun_body = Bodies :: Sun ; // This only works in the solar system..
54
- let orbit = cosmic . celestial_state ( sun_body . ephem_path ( ) , t , * ref_frame , LightTimeCalc :: None ) ;
54
+ fn sun_unit_vector ( almanac : & Almanac , t : Epoch ) -> Vector3 < f64 > {
55
+ let earth2sun = almanac . transform ( EARTH_J2000 , SUN_J2000 , t , None ) . unwrap ( ) ;
56
+
55
57
Vector3 :: new (
56
- orbit . x_km * 1000.0 ,
57
- orbit . y_km * 1000.0 ,
58
- orbit . z_km * 1000.0 ,
58
+ earth2sun . radius_km . x * 1000.0 ,
59
+ earth2sun . radius_km . y * 1000.0 ,
60
+ earth2sun . radius_km . z * 1000.0 ,
59
61
)
60
62
}
61
63
@@ -68,9 +70,15 @@ pub struct Orbit<'a> {
68
70
69
71
impl < ' a > Orbit < ' a > {
70
72
pub fn from_ctx ( ctx : & ' a Context , order : usize ) -> Self {
71
- let cosmic = Cosm :: de438 ( ) ;
73
+ let meta = MetaFile {
74
+ uri : "http://public-data.nyxspace.com/anise/v0.4/de440s.bsp" . to_string ( ) ,
75
+ crc32 : Some ( 3072159656 ) , // Specifying the CRC allows only downloading the data once.
76
+ } ;
77
+ let almanac = Almanac :: default ( )
78
+ . load_from_metafile ( meta)
79
+ . unwrap_or_else ( |e| panic ! ( "failed to build Almanac: {}" , e) ) ;
80
+
72
81
let sp3 = ctx. data . sp3 ( ) . unwrap ( ) ;
73
- let earth_frame = cosmic. frame ( "EME2000" ) ; // this only works on planet Earth..
74
82
Self {
75
83
order,
76
84
epochs : 0 ,
@@ -85,7 +93,7 @@ impl<'a> Orbit<'a> {
85
93
let k = -r_sat
86
94
/ ( r_sat[ 0 ] . powi ( 2 ) + r_sat[ 1 ] . powi ( 2 ) + r_sat[ 3 ] . powi ( 2 ) ) . sqrt ( ) ;
87
95
88
- let r_sun = sun_unit_vector ( & earth_frame , & cosmic , t) ;
96
+ let r_sun = sun_unit_vector ( & almanac , t) ;
89
97
let norm = ( ( r_sun[ 0 ] - r_sat[ 0 ] ) . powi ( 2 )
90
98
+ ( r_sun[ 1 ] - r_sat[ 1 ] ) . powi ( 2 )
91
99
+ ( r_sun[ 2 ] - r_sat[ 2 ] ) . powi ( 2 ) )
0 commit comments