Skip to content

Commit

Permalink
Refine time comparison
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <methylDragon@gmail.com>
  • Loading branch information
methylDragon committed Nov 9, 2022
1 parent eb1ef49 commit 96fabdd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions fuse_optimizers/src/batch_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ void BatchOptimizer::transactionCallback(
{
purge_time = start_time_;
}
// NOTE(CH3): In this case we're okay with uninitialized time since it's just used
// for comparison
// prevent a bad subtraction
else if (rclcpp::Time(0, 0, transaction_clock_type) + params_.transaction_timeout < last_pending_time)
else if (rclcpp::Time(params_.transaction_timeout.nanoseconds, last_pending_time.get_clock_type())
< last_pending_time)
{
purge_time = last_pending_time - params_.transaction_timeout;
}
Expand Down
5 changes: 2 additions & 3 deletions fuse_optimizers/src/fixed_lag_smoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,8 @@ void FixedLagSmoother::transactionCallback(
auto last_pending_time = pending_transactions_.front().stamp();

// rclcpp::Time doesn't allow negatives
// NOTE(CH3): In this case we're okay with uninitialized time since it's just used
// for comparison
if (rclcpp::Time(0, 0, RCL_ROS_TIME) + params_.transaction_timeout < last_pending_time)
if (rclcpp::Time(params_.transaction_timeout.nanoseconds, last_pending_time.get_clock_type())
< last_pending_time)
{
purge_time = last_pending_time - params_.transaction_timeout;
}
Expand Down

0 comments on commit 96fabdd

Please sign in to comment.