1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
//! Position solving candidate
use hifitime::Unit;
use log::debug;
// use itertools::Itertools;
use crate::{
bias::spaceborn::SatelliteClockCorrection,
constants::SPEED_OF_LIGHT_M_S,
navigation::state::State,
prelude::{Almanac, Config, Duration, Epoch, Error, Orbit, Vector3, SV},
};
use anise::errors::AlmanacResult;
mod bias;
mod ppp;
mod rtk;
mod signal;
pub(crate) mod combination;
pub(crate) mod differences;
pub(crate) mod single_diff;
#[cfg(test)]
mod tests;
pub use crate::{candidate::signal::Observation, prelude::Carrier};
/// Position solving candidate
#[derive(Clone, Debug)]
pub struct Candidate {
/// [SV]
pub sv: SV,
/// Sampling [Epoch]
pub epoch: Epoch,
/// Transmission [Epoch]
pub(crate) tx_epoch: Epoch,
/// [Orbit]al state
pub(crate) orbit: Option<Orbit>,
/// elevation at reception time
pub(crate) elevation_deg: Option<f64>,
/// azimuth at reception time
pub(crate) azimuth_deg: Option<f64>,
/// Total group delay.
pub(crate) tgd: Duration,
/// Troposphere delay (meters)
pub(crate) tropod: f64,
/// Ionosphere delay (meters)
pub(crate) ionod: f64,
// /// Phase wind up in cycles
// pub(crate) windup: f64,
/// [SatelliteClockCorrection]
pub(crate) clock_corr: SatelliteClockCorrection,
/// Signal [Observation]s
pub(crate) observations: Vec<Observation>,
/// Possible time system correction
pub(crate) system_correction: Option<Duration>,
/// Estimated relativistic path range
pub(crate) relativistic_path_range: f64,
}
impl Candidate {
/// Basic candidate definition, to propose to the navigation solver. Each candidate is to be
/// This is the most simplistic definition (bare minimum).
/// It is certainly not enough for PPP navigation and will require
/// you provide more information (see other customization methods),
/// especially if you want to achieve accurate results.
/// ## Input
/// - sv: [SV] Identity
/// - epoch: sampling [Epoch]
/// - observations: provide signals observations.
/// You have to provide observations that match your navigation method.
pub fn new(sv: SV, epoch: Epoch, observations: Vec<Observation>) -> Self {
Self {
sv,
epoch,
ionod: 0.0,
tropod: 0.0,
observations,
tx_epoch: epoch,
tgd: Duration::ZERO,
orbit: Default::default(),
// windup: Default::default(),
azimuth_deg: Default::default(),
clock_corr: Default::default(),
elevation_deg: Default::default(),
system_correction: Default::default(),
relativistic_path_range: Default::default(),
}
}
// /// Designs a measured frequency iterator
// fn frequencies_iter(&self) -> Box<dyn Iterator<Item = Carrier> + '_> {
// Box::new(self.observations.iter().map(|obs| obs.carrier).unique())
// }
/// Update pseudo range observation (in meters) for this frequency.
pub fn set_pseudo_range_m(&mut self, carrier: Carrier, pr_m: f64) {
if let Some(observation) = self
.observations
.iter_mut()
.filter_map(|obs| {
if obs.carrier == carrier && obs.pseudo_range_m.is_some() {
Some(obs)
} else {
None
}
})
.reduce(|k, _| k)
{
observation.pseudo_range_m = Some(pr_m);
} else {
self.observations
.push(Observation::pseudo_range(carrier, pr_m, None));
}
}
/// Update with ambiguous range observation (in meters) for this frequency.
pub fn set_ambiguous_phase_range_m(&mut self, carrier: Carrier, pr_m: f64) {
if let Some(observation) = self
.observations
.iter_mut()
.filter_map(|obs| {
if obs.carrier == carrier && obs.phase_range_m.is_some() {
Some(obs)
} else {
None
}
})
.reduce(|k, _| k)
{
observation.phase_range_m = Some(pr_m);
} else {
self.observations
.push(Observation::ambiguous_phase_range(carrier, pr_m, None));
}
}
/// Computes phase windup correction term.
pub(crate) fn phase_windup_correction(
&mut self,
_rx_state: &State,
_r_sun: Vector3<f64>,
_past_correction: Option<f64>,
) {
// let sv_state = self.orbit.unwrap_or_else(|| {
// panic!("internal error: phase windup while state is not fully resolved");
// });
// let r_sv = sv_state.to_cartesian_pos_vel() * 1.0E3;
// // todo self.yaw_attitude();
// let r_rx = rx_state.to_position_ecef_m();
// let r_sv = Vector3::new(r_sv[0], r_sv[1], r_sv[2]);
// let r_rr_rs = r_rx - r_sv;
// let e_r_rs = r_rr_rs.norm();
// self.windup = 0.0; // TODO
}
/// Computes signal transmission instant, as [Epoch].
pub(crate) fn transmission_time(&mut self, name: &str, cfg: &Config) -> Result<(), Error> {
let mut t_tx = self.epoch;
let (_, pr) = self.best_snr_range_m().ok_or(Error::MissingPseudoRange)?;
t_tx -= pr / SPEED_OF_LIGHT_M_S * Unit::Second;
if cfg.modeling.sv_total_group_delay {
t_tx -= self.tgd;
}
if cfg.modeling.sv_clock_bias {
t_tx -= self.clock_corr.duration;
}
assert!(
t_tx < self.epoch,
"Physical non sense - {} rx={} prior tx={}",
name,
self.epoch,
t_tx
);
self.tx_epoch = t_tx;
debug!(
"{}({}) {} - time of flight: {}",
self.sv,
self.epoch,
name,
self.signal_time_of_flight()
);
Ok(())
}
pub(crate) fn signal_time_of_flight(&self) -> Duration {
self.epoch - self.tx_epoch
}
/// Fix [Orbit]al attitude.
pub(crate) fn orbital_attitude_fixup(
&mut self,
almanac: &Almanac,
rx_orbit: Orbit,
) -> AlmanacResult<()> {
let orbit = self
.orbit
.expect("internal error: undefined orbital state (badop)");
let elazrg = almanac.azimuth_elevation_range_sez(orbit, rx_orbit, None, None)?;
self.azimuth_deg = Some(elazrg.azimuth_deg);
self.elevation_deg = Some(elazrg.elevation_deg);
Ok(())
}
/// Returns (elevation, azimuth) in decimal degrees.
pub(crate) fn attitude(&self) -> Option<(f64, f64)> {
let el = self.elevation_deg?;
let az = self.azimuth_deg?;
Some((el, az))
}
// /// Creates [Candidate] with elevation degree
// pub(crate) fn with_elevation_deg(&self, el: f64) -> Self {
// let mut s = self.clone();
// s.elevation_deg = Some(el);
// s
// }
// /// Creates [Candidate] with azimuth degree
// pub(crate) fn with_azimuth_deg(&self, az: f64) -> Self {
// let mut s = self.clone();
// s.azimuth_deg = Some(az);
// s
// }
#[cfg(test)]
pub fn set_orbit(&mut self, orbit: Orbit) {
self.orbit = Some(orbit);
}
}
#[cfg(test)]
mod test {
use crate::prelude::{Candidate, Carrier, Epoch, Observation, SV};
#[test]
fn cpp_compatibility() {
{
let (observations, cpp_compatible) = (
vec![
Observation {
snr_dbhz: Some(1.0),
pseudo_range_m: Some(1.0),
phase_range_m: Some(2.0),
ambiguity: None,
doppler: None,
carrier: Carrier::L1,
},
Observation {
snr_dbhz: Some(1.0),
pseudo_range_m: Some(2.0),
phase_range_m: Some(2.0),
ambiguity: None,
doppler: None,
carrier: Carrier::L5,
},
],
true,
);
let cd = Candidate::new(SV::default(), Epoch::default(), observations);
assert_eq!(cd.cpp_compatible(), cpp_compatible);
}
}
}