Skip to content

Commit

Permalink
Positive forward, negative backward
Browse files Browse the repository at this point in the history
  • Loading branch information
sloretz committed Aug 27, 2018
1 parent 2c9bbc8 commit 7da5d95
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
8 changes: 4 additions & 4 deletions rcl/include/rcl/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ typedef struct rcl_jump_threshold_t
{
/// True to call callback when the clock type changes.
bool on_clock_change;
/// A positive duration indicating the minimum magnitude of a jump forwards to be considered
/// exceeded, or zero to disable.
/// A positive duration indicating the minimum jump forwards to be considered exceeded, or zero
/// to disable.
rcl_duration_t min_forward;
/// A positive duration indicating the minimum magnitude of a jump backwards to be considered
/// exceeded, or zero to disable.
/// A negative duration indicating the minimum jump backwards to be considered exceeded, or zero
/// to disable.
rcl_duration_t min_backward;
} rcl_jump_threshold_t;

Expand Down
9 changes: 3 additions & 6 deletions rcl/src/rcl/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ _rcl_clock_call_callbacks(
if (
(is_clock_change && info->threshold.on_clock_change) ||
(time_jump->delta.nanoseconds < 0 &&
// Note: min_backward was stored as a negative duration
time_jump->delta.nanoseconds <= info->threshold.min_backward.nanoseconds) ||
(time_jump->delta.nanoseconds > 0 &&
time_jump->delta.nanoseconds >= info->threshold.min_forward.nanoseconds))
Expand Down Expand Up @@ -404,11 +403,11 @@ rcl_clock_add_jump_callback(
return RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(callback, RCL_RET_INVALID_ARGUMENT, clock->allocator);
if (threshold.min_forward.nanoseconds < 0) {
RCL_SET_ERROR_MSG("forward jump theshold must be positive", clock->allocator);
RCL_SET_ERROR_MSG("forward jump theshold must be positive or zero", clock->allocator);
return RCL_RET_INVALID_ARGUMENT;
}
if (threshold.min_backward.nanoseconds < 0) {
RCL_SET_ERROR_MSG("backward jump theshold must be positive", clock->allocator);
if (threshold.min_backward.nanoseconds > 0) {
RCL_SET_ERROR_MSG("backward jump theshold must be negative or zero", clock->allocator);
return RCL_RET_INVALID_ARGUMENT;
}

Expand All @@ -432,8 +431,6 @@ rcl_clock_add_jump_callback(
clock->jump_callbacks = callbacks;
clock->jump_callbacks[clock->num_jump_callbacks].callback = callback;
clock->jump_callbacks[clock->num_jump_callbacks].threshold = threshold;
// store backwards jump threshold with a negative value for convenience
clock->jump_callbacks[clock->num_jump_callbacks].threshold.min_backward.nanoseconds *= -1;
clock->jump_callbacks[clock->num_jump_callbacks].user_data = user_data;
++(clock->num_jump_callbacks);
return RCL_RET_OK;
Expand Down
2 changes: 1 addition & 1 deletion rcl/test/rcl/test_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ TEST(CLASSNAME(rcl_time, RMW_IMPLEMENTATION), rcl_time_backward_jump_callbacks)
rcl_jump_threshold_t threshold;
threshold.on_clock_change = false;
threshold.min_forward.nanoseconds = 0;
threshold.min_backward.nanoseconds = 1;
threshold.min_backward.nanoseconds = -1;
ASSERT_EQ(RCL_RET_OK,
rcl_clock_add_jump_callback(ros_clock, threshold, clock_callback, &time_jump)) <<
rcl_get_error_string_safe();
Expand Down

0 comments on commit 7da5d95

Please sign in to comment.