Skip to content

Commit

Permalink
Fixed bug in state update after jump.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv1992 authored and rnijveld committed Sep 19, 2024
1 parent 9109d7b commit beadfb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ntp-proto/src/algorithm/kalman/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl<C: NtpClock, SourceId: Hash + Eq + Copy + Debug> KalmanClockController<C, S
.expect("Cannot adjust clock");
for (state, _) in self.sources.values_mut() {
if let Some(ref mut state) = state {
state.state.process_offset_steering(change);
state.state = state.state.process_offset_steering(change);
}
}
info!("Jumped offset by {}ms", change * 1e3);
Expand Down
10 changes: 10 additions & 0 deletions ntp-proto/src/algorithm/kalman/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub(super) struct MeasurementStats {
}

impl KalmanState {
#[must_use]
pub fn progress_time(&self, time: NtpTimestamp, wander: f64) -> KalmanState {
debug_assert!(!time.is_before(self.time));
if time.is_before(self.time) {
Expand All @@ -130,6 +131,7 @@ impl KalmanState {
}
}

#[must_use]
pub fn absorb_measurement(
&self,
measurement: Matrix<1, 2>,
Expand Down Expand Up @@ -164,6 +166,7 @@ impl KalmanState {
)
}

#[must_use]
pub fn merge(&self, other: &KalmanState) -> KalmanState {
debug_assert_eq!(self.time, other.time);

Expand All @@ -176,6 +179,7 @@ impl KalmanState {
}
}

#[must_use]
pub fn add_server_dispersion(&self, dispersion: f64) -> KalmanState {
KalmanState {
state: self.state,
Expand All @@ -184,22 +188,27 @@ impl KalmanState {
}
}

#[must_use]
pub fn offset(&self) -> f64 {
self.state.ventry(0)
}

#[must_use]
pub fn offset_variance(&self) -> f64 {
self.uncertainty.entry(0, 0)
}

#[must_use]
pub fn frequency(&self) -> f64 {
self.state.ventry(1)
}

#[must_use]
pub fn frequency_variance(&self) -> f64 {
self.uncertainty.entry(1, 1)
}

#[must_use]
pub fn process_offset_steering(&self, steer: f64) -> KalmanState {
KalmanState {
state: self.state - Vector::new_vector([steer, 0.0]),
Expand All @@ -208,6 +217,7 @@ impl KalmanState {
}
}

#[must_use]
pub fn process_frequency_steering(
&self,
time: NtpTimestamp,
Expand Down

0 comments on commit beadfb4

Please sign in to comment.