Skip to content

Commit

Permalink
fix: non steady clock and watchdog (#156)
Browse files Browse the repository at this point in the history
* fix: the callback was being called even though the updates were frequent. the cause was ros time not being steady (ptp?)

Signed-off-by: Kenzo Lobos-Tsunekawa <[email protected]>

* chore(watchdog_timer): add explanatory comment

---------

Signed-off-by: Kenzo Lobos-Tsunekawa <[email protected]>
Co-authored-by: Max Schmeller <[email protected]>
  • Loading branch information
knzo25 and mojomex authored Jun 6, 2024
1 parent 3398471 commit ddc7e50
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nebula_ros/include/nebula_ros/common/watchdog_timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ class WatchdogTimer
{
uint64_t now_ns = node_.get_clock()->now().nanoseconds();

bool is_late = (now_ns - last_update_ns_) > expected_update_interval_ns_;
// As the clock is not steady, the update timestamp can be newer than clock.now().
// Define that edge-case as not being late too.
bool is_late = (last_update_ns_ > now_ns)
? false
: (now_ns - last_update_ns_) > expected_update_interval_ns_;

callback_(!is_late);
}
Expand Down

0 comments on commit ddc7e50

Please sign in to comment.