ROS 2 rclcpp + rcl - rolling  rolling-a919a6e5
ROS 2 C++ Client Library with ROS Client Library
clock.cpp
1 // Copyright 2017 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "rclcpp/clock.hpp"
16 
17 #include <condition_variable>
18 #include <memory>
19 #include <thread>
20 
21 #include "rclcpp/exceptions.hpp"
22 #include "rclcpp/utilities.hpp"
23 
24 #include "rcpputils/scope_exit.hpp"
25 #include "rcutils/logging_macros.h"
26 
27 namespace rclcpp
28 {
29 
31 {
32 public:
33  explicit Impl(rcl_clock_type_t clock_type)
34  : allocator_{rcl_get_default_allocator()}
35  {
36  rcl_ret_t ret = rcl_clock_init(clock_type, &rcl_clock_, &allocator_);
37  if (ret != RCL_RET_OK) {
38  exceptions::throw_from_rcl_error(ret, "failed to initialize rcl clock");
39  }
40  }
41 
42  ~Impl()
43  {
44  rcl_ret_t ret = rcl_clock_fini(&rcl_clock_);
45  if (ret != RCL_RET_OK) {
46  RCUTILS_LOG_ERROR("Failed to fini rcl clock.");
47  }
48  }
49 
50  rcl_clock_t rcl_clock_;
51  rcl_allocator_t allocator_;
52  bool stop_sleeping_ = false;
53  bool shutdown_ = false;
54  std::condition_variable cv_;
55  std::mutex wait_mutex_;
56  std::mutex clock_mutex_;
57 };
58 
59 JumpHandler::JumpHandler(
60  pre_callback_t pre_callback,
61  post_callback_t post_callback,
62  const rcl_jump_threshold_t & threshold)
63 : pre_callback(pre_callback),
64  post_callback(post_callback),
65  notice_threshold(threshold)
66 {}
67 
69 : impl_(new Clock::Impl(clock_type)) {}
70 
71 Clock::~Clock() {}
72 
73 Time
74 Clock::now() const
75 {
76  Time now(0, 0, impl_->rcl_clock_.type);
77 
78  auto ret = rcl_clock_get_now(&impl_->rcl_clock_, &now.rcl_time_.nanoseconds);
79  if (ret != RCL_RET_OK) {
80  exceptions::throw_from_rcl_error(ret, "could not get current time stamp");
81  }
82 
83  return now;
84 }
85 
86 bool
88  Time until,
89  Context::SharedPtr context)
90 {
91  if (!context || !context->is_valid()) {
92  throw std::runtime_error("context cannot be slept with because it's invalid");
93  }
94  const auto this_clock_type = get_clock_type();
95  if (until.get_clock_type() != this_clock_type) {
96  throw std::runtime_error("until's clock type does not match this clock's type");
97  }
98  bool time_source_changed = false;
99 
100  // Wake this thread if the context is shutdown
101  rclcpp::OnShutdownCallbackHandle shutdown_cb_handle = context->add_on_shutdown_callback(
102  [this]() {
103  {
104  std::unique_lock lock(impl_->wait_mutex_);
105  impl_->shutdown_ = true;
106  }
107  impl_->cv_.notify_one();
108  });
109  // No longer need the shutdown callback when this function exits
110  auto callback_remover = rcpputils::scope_exit(
111  [context, &shutdown_cb_handle]() {
112  context->remove_on_shutdown_callback(shutdown_cb_handle);
113  });
114 
115  if (this_clock_type == RCL_STEADY_TIME) {
116  // Synchronize because RCL steady clock epoch might differ from chrono::steady_clock epoch
117  const Time rcl_entry = now();
118  const std::chrono::steady_clock::time_point chrono_entry = std::chrono::steady_clock::now();
119  const Duration delta_t = until - rcl_entry;
120  const std::chrono::steady_clock::time_point chrono_until =
121  chrono_entry + std::chrono::nanoseconds(delta_t.nanoseconds());
122 
123  // loop over spurious wakeups but notice shutdown or stop of sleep
124  std::unique_lock lock(impl_->wait_mutex_);
125  while (now() < until && !impl_->stop_sleeping_ && !impl_->shutdown_ && context->is_valid()) {
126  impl_->cv_.wait_until(lock, chrono_until);
127  }
128  impl_->stop_sleeping_ = false;
129  } else if (this_clock_type == RCL_SYSTEM_TIME) {
130  auto system_time = std::chrono::system_clock::time_point(
131  // Cast because system clock resolution is too big for nanoseconds on some systems
132  std::chrono::duration_cast<std::chrono::system_clock::duration>(
133  std::chrono::nanoseconds(until.nanoseconds())));
134 
135  // loop over spurious wakeups but notice shutdown or stop of sleep
136  std::unique_lock lock(impl_->wait_mutex_);
137  while (now() < until && !impl_->stop_sleeping_ && !impl_->shutdown_ && context->is_valid()) {
138  impl_->cv_.wait_until(lock, system_time);
139  }
140  impl_->stop_sleeping_ = false;
141  } else if (this_clock_type == RCL_ROS_TIME) {
142  // Install jump handler for any amount of time change, for two purposes:
143  // - if ROS time is active, check if time reached on each new clock sample
144  // - Trigger via on_clock_change to detect if time source changes, to invalidate sleep
145  rcl_jump_threshold_t threshold;
146  threshold.on_clock_change = true;
147  // 0 is disable, so -1 and 1 are smallest possible time changes
148  threshold.min_backward.nanoseconds = -1;
149  threshold.min_forward.nanoseconds = 1;
150  auto clock_handler = create_jump_callback(
151  nullptr,
152  [this, &time_source_changed](const rcl_time_jump_t & jump) {
153  if (jump.clock_change != RCL_ROS_TIME_NO_CHANGE) {
154  std::lock_guard<std::mutex> lk(impl_->wait_mutex_);
155  time_source_changed = true;
156  }
157  impl_->cv_.notify_one();
158  },
159  threshold);
160 
161  if (!ros_time_is_active()) {
162  auto system_time = std::chrono::system_clock::time_point(
163  // Cast because system clock resolution is too big for nanoseconds on some systems
164  std::chrono::duration_cast<std::chrono::system_clock::duration>(
165  std::chrono::nanoseconds(until.nanoseconds())));
166 
167  // loop over spurious wakeups but notice shutdown, stop of sleep or time source change
168  std::unique_lock lock(impl_->wait_mutex_);
169  while (now() < until && !impl_->stop_sleeping_ && !impl_->shutdown_ && context->is_valid() &&
170  !time_source_changed)
171  {
172  impl_->cv_.wait_until(lock, system_time);
173  }
174  impl_->stop_sleeping_ = false;
175  } else {
176  // RCL_ROS_TIME with ros_time_is_active.
177  // Just wait without "until" because installed
178  // jump callbacks wake the cv on every new sample.
179  std::unique_lock lock(impl_->wait_mutex_);
180  while (now() < until && !impl_->stop_sleeping_ && !impl_->shutdown_ && context->is_valid() &&
181  !time_source_changed)
182  {
183  impl_->cv_.wait(lock);
184  }
185  impl_->stop_sleeping_ = false;
186  }
187  }
188 
189  if (!context->is_valid() || time_source_changed) {
190  return false;
191  }
192 
193  return now() >= until;
194 }
195 
196 bool
197 Clock::sleep_for(Duration rel_time, Context::SharedPtr context)
198 {
199  return sleep_until(now() + rel_time, context);
200 }
201 
202 bool
204 {
206  throw std::runtime_error("clock is not rcl_clock_valid");
207  }
209 }
210 
211 bool
212 Clock::wait_until_started(Context::SharedPtr context)
213 {
214  if (!context || !context->is_valid()) {
215  throw std::runtime_error("context cannot be slept with because it's invalid");
216  }
218  throw std::runtime_error("clock cannot be waited on as it is not rcl_clock_valid");
219  }
220 
221  if (started()) {
222  return true;
223  } else {
224  // Wait until the first non-zero time
225  return sleep_until(rclcpp::Time(0, 1, get_clock_type()), context);
226  }
227 }
228 
229 bool
231  const Duration & timeout,
232  Context::SharedPtr context,
233  const Duration & wait_tick_ns)
234 {
235  if (!context || !context->is_valid()) {
236  throw std::runtime_error("context cannot be slept with because it's invalid");
237  }
239  throw std::runtime_error("clock cannot be waited on as it is not rcl_clock_valid");
240  }
241 
242  Clock timeout_clock = Clock(RCL_STEADY_TIME);
243  Time start = timeout_clock.now();
244 
245  // Check if the clock has started every wait_tick_ns nanoseconds
246  // Context check checks for rclcpp::shutdown()
247  while (!started() && context->is_valid()) {
248  if (timeout < wait_tick_ns) {
249  timeout_clock.sleep_for(timeout);
250  } else {
251  Duration time_left = start + timeout - timeout_clock.now();
252  if (time_left > wait_tick_ns) {
253  timeout_clock.sleep_for(Duration(wait_tick_ns));
254  } else {
255  timeout_clock.sleep_for(time_left);
256  }
257  }
258 
259  if (timeout_clock.now() - start > timeout) {
260  return started();
261  }
262  }
263  return started();
264 }
265 
266 
267 bool
269 {
270  if (!rcl_clock_valid(&impl_->rcl_clock_)) {
271  RCUTILS_LOG_ERROR("ROS time not valid!");
272  return false;
273  }
274 
275  bool is_enabled = false;
276  auto ret = rcl_is_enabled_ros_time_override(&impl_->rcl_clock_, &is_enabled);
277  if (ret != RCL_RET_OK) {
278  exceptions::throw_from_rcl_error(
279  ret, "Failed to check ros_time_override_status");
280  }
281  return is_enabled;
282 }
283 
284 rcl_clock_t *
286 {
287  return &impl_->rcl_clock_;
288 }
289 
291 Clock::get_clock_type() const noexcept
292 {
293  return impl_->rcl_clock_.type;
294 }
295 
296 std::mutex &
298 {
299  return impl_->clock_mutex_;
300 }
301 
302 void
303 Clock::on_time_jump(
304  const rcl_time_jump_t * time_jump,
305  bool before_jump,
306  void * user_data)
307 {
308  const auto * handler = static_cast<JumpHandler *>(user_data);
309  if (nullptr == handler) {
310  return;
311  }
312  if (before_jump && handler->pre_callback) {
313  handler->pre_callback();
314  } else if (!before_jump && handler->post_callback) {
315  handler->post_callback(*time_jump);
316  }
317 }
318 
319 JumpHandler::SharedPtr
321  JumpHandler::pre_callback_t pre_callback,
322  JumpHandler::post_callback_t post_callback,
323  const rcl_jump_threshold_t & threshold)
324 {
325  // Allocate a new jump handler
326  JumpHandler::UniquePtr handler(new JumpHandler(pre_callback, post_callback, threshold));
327  if (nullptr == handler) {
328  throw std::bad_alloc{};
329  }
330 
331  {
332  std::lock_guard<std::mutex> clock_guard(impl_->clock_mutex_);
333  // Try to add the jump callback to the clock
335  &impl_->rcl_clock_, threshold, Clock::on_time_jump,
336  handler.get());
337  if (RCL_RET_OK != ret) {
338  exceptions::throw_from_rcl_error(ret, "Failed to add time jump callback");
339  }
340  }
341 
342  std::weak_ptr<Clock::Impl> weak_impl = impl_;
343  // *INDENT-OFF*
344  // create shared_ptr that removes the callback automatically when all copies are destructed
345  return JumpHandler::SharedPtr(handler.release(), [weak_impl](JumpHandler * handler) noexcept {
346  auto shared_impl = weak_impl.lock();
347  if (shared_impl) {
348  std::lock_guard<std::mutex> clock_guard(shared_impl->clock_mutex_);
349  rcl_ret_t ret = rcl_clock_remove_jump_callback(&shared_impl->rcl_clock_,
350  Clock::on_time_jump, handler);
351  if (RCL_RET_OK != ret) {
352  RCUTILS_LOG_ERROR("Failed to remove time jump callback");
353  }
354  }
355  delete handler;
356  });
357  // *INDENT-ON*
358 }
359 
361 {
362 private:
363  std::condition_variable cv_;
364 
365  rclcpp::Clock::SharedPtr clock_;
366  bool time_source_changed_ = false;
367  std::function<void(const rcl_time_jump_t &)> post_time_jump_callback;
368 
369  bool
370  wait_until_system_time(
371  std::unique_lock<std::mutex> & lock,
372  const rclcpp::Time & abs_time, const std::function<bool ()> & pred)
373  {
374  auto system_time = std::chrono::system_clock::time_point(
375  // Cast because system clock resolution is too big for nanoseconds on some systems
376  std::chrono::duration_cast<std::chrono::system_clock::duration>(
377  std::chrono::nanoseconds(abs_time.nanoseconds())));
378 
379  return cv_.wait_until(lock, system_time, pred);
380  }
381 
382  bool
383  wait_until_steady_time(
384  std::unique_lock<std::mutex> & lock,
385  const rclcpp::Time & abs_time, const std::function<bool ()> & pred)
386  {
387  // Synchronize because RCL steady clock epoch might differ from chrono::steady_clock epoch
388  const rclcpp::Time rcl_entry = clock_->now();
389  const std::chrono::steady_clock::time_point chrono_entry = std::chrono::steady_clock::now();
390  const rclcpp::Duration delta_t = abs_time - rcl_entry;
391  const std::chrono::steady_clock::time_point chrono_until =
392  chrono_entry + std::chrono::nanoseconds(delta_t.nanoseconds());
393 
394  return cv_.wait_until(lock, chrono_until, pred);
395  }
396 
397 
398  bool
399  wait_until_ros_time(
400  std::unique_lock<std::mutex> & lock,
401  const rclcpp::Time & abs_time, const std::function<bool ()> & pred)
402  {
403  // Install jump handler for any amount of time change, for two purposes:
404  // - if ROS time is active, check if time reached on each new clock sample
405  // - Trigger via on_clock_change to detect if time source changes, to invalidate sleep
406  rcl_jump_threshold_t threshold;
407  threshold.on_clock_change = true;
408  // 0 is disable, so -1 and 1 are smallest possible time changes
409  threshold.min_backward.nanoseconds = -1;
410  threshold.min_forward.nanoseconds = 1;
411 
412  time_source_changed_ = false;
413 
414  post_time_jump_callback = [this, &lock] (const rcl_time_jump_t & jump)
415  {
416  if (jump.clock_change != RCL_ROS_TIME_NO_CHANGE) {
417  std::lock_guard<std::mutex> lk(*lock.mutex());
418  time_source_changed_ = true;
419  }
420  cv_.notify_one();
421  };
422 
423  // Note this is a trade-off. Adding the callback for every call
424  // is expensive for high frequency calls. For low frequency waits
425  // its more overhead to have the callback being called all the time.
426  // As we expect the use case to be low frequency calls to wait_until
427  // with relative big pauses between the calls, we install it on demand.
428  auto clock_handler = clock_->create_jump_callback(
429  nullptr,
430  post_time_jump_callback,
431  threshold);
432 
433  if (!clock_->ros_time_is_active()) {
434  auto system_time = std::chrono::system_clock::time_point(
435  // Cast because system clock resolution is too big for nanoseconds on some systems
436  std::chrono::duration_cast<std::chrono::system_clock::duration>(
437  std::chrono::nanoseconds(abs_time.nanoseconds())));
438 
439  return cv_.wait_until(lock, system_time, [this, &pred] () {
440  return time_source_changed_ || pred();
441  });
442  }
443 
444  // RCL_ROS_TIME with ros_time_is_active.
445  // Just wait without "until" because installed
446  // jump callbacks wake the cv on every new sample.
447  cv_.wait(lock, [this, &pred, &abs_time] () {
448  return clock_->now() >= abs_time || time_source_changed_ || pred();
449  });
450 
451  return clock_->now() < abs_time;
452  }
453 
454 public:
455  explicit ClockWaiterImpl(const rclcpp::Clock::SharedPtr & clock)
456  :clock_(clock)
457  {
458  }
459 
460  bool
461  wait_until(
462  std::unique_lock<std::mutex> & lock,
463  const rclcpp::Time & abs_time, const std::function<bool ()> & pred)
464  {
465  switch(clock_->get_clock_type()) {
467  throw std::runtime_error("Error, wait on uninitialized clock called");
468  case RCL_ROS_TIME:
469  return wait_until_ros_time(lock, abs_time, pred);
470  break;
471  case RCL_STEADY_TIME:
472  return wait_until_steady_time(lock, abs_time, pred);
473  break;
474  case RCL_SYSTEM_TIME:
475  return wait_until_system_time(lock, abs_time, pred);
476  break;
477  }
478 
479  return false;
480  }
481 
482  void
483  notify_one()
484  {
485  cv_.notify_one();
486  }
487 };
488 
489 ClockWaiter::ClockWaiter(const rclcpp::Clock::SharedPtr & clock)
490 :impl_(std::make_unique<ClockWaiterImpl>(clock))
491 {
492 }
493 
494 ClockWaiter::~ClockWaiter() = default;
495 
496 bool
498  std::unique_lock<std::mutex> & lock,
499  const rclcpp::Time & abs_time, const std::function<bool ()> & pred)
500 {
501  return impl_->wait_until(lock, abs_time, pred);
502 }
503 
504 void
506 {
507  impl_->notify_one();
508 }
509 
511 {
512  std::mutex pred_mutex_;
513  bool shutdown_ = false;
514  rclcpp::Context::SharedPtr context_;
515  rclcpp::OnShutdownCallbackHandle shutdown_cb_handle_;
516  ClockWaiter::UniquePtr clock_;
517 
518 public:
519  Impl(const rclcpp::Clock::SharedPtr & clock, rclcpp::Context::SharedPtr context)
520  :context_(context),
521  clock_(std::make_unique<ClockWaiter>(clock))
522  {
523  if (!context_ || !context_->is_valid()) {
524  throw std::runtime_error("context cannot be slept with because it's invalid");
525  }
526  // Wake this thread if the context is shutdown
527  shutdown_cb_handle_ = context_->add_on_shutdown_callback(
528  [this]() {
529  {
530  std::unique_lock lock(pred_mutex_);
531  shutdown_ = true;
532  }
533  clock_->notify_one();
534  });
535  }
536 
537  ~Impl()
538  {
539  context_->remove_on_shutdown_callback(shutdown_cb_handle_);
540  }
541 
542  bool
543  wait_until(
544  std::unique_lock<std::mutex> & lock, rclcpp::Time until,
545  const std::function<bool ()> & pred)
546  {
547  if(lock.mutex() != &pred_mutex_) {
548  throw std::runtime_error(
549  "ClockConditionalVariable::wait_until: Internal error, given lock does not use"
550  " mutex returned by this->mutex()");
551  }
552 
553  clock_->wait_until(lock, until, [this, &pred] () -> bool {
554  return shutdown_ || pred();
555  });
556  return true;
557  }
558 
559  void
560  notify_one()
561  {
562  clock_->notify_one();
563  }
564 
565  std::mutex &
566  mutex()
567  {
568  return pred_mutex_;
569  }
570 };
571 
572 ClockConditionalVariable::ClockConditionalVariable(
573  const rclcpp::Clock::SharedPtr & clock,
574  rclcpp::Context::SharedPtr context)
575 :impl_(std::make_unique<Impl>(clock, context))
576 {
577 }
578 
579 ClockConditionalVariable::~ClockConditionalVariable() = default;
580 
581 void
583 {
584  impl_->notify_one();
585 }
586 
587 bool
589  std::unique_lock<std::mutex> & lock, rclcpp::Time until,
590  const std::function<bool ()> & pred)
591 {
592  return impl_->wait_until(lock, until, pred);
593 }
594 
595 std::mutex &
597 {
598  return impl_->mutex();
599 }
600 
601 } // namespace rclcpp
#define rcl_get_default_allocator
Return a properly initialized rcl_allocator_t with default values.
Definition: allocator.h:37
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:31
RCLCPP_PUBLIC void notify_one()
Definition: clock.cpp:582
RCLCPP_PUBLIC std::mutex & mutex()
Definition: clock.cpp:596
RCLCPP_PUBLIC bool wait_until(std::unique_lock< std::mutex > &lock, rclcpp::Time until, const std::function< bool()> &pred)
Definition: clock.cpp:588
RCLCPP_PUBLIC bool wait_until(std::unique_lock< std::mutex > &lock, const rclcpp::Time &abs_time, const std::function< bool()> &pred)
Definition: clock.cpp:497
RCLCPP_PUBLIC void notify_one()
Definition: clock.cpp:505
RCLCPP_PUBLIC rcl_clock_t * get_clock_handle() noexcept
Return the rcl_clock_t clock handle.
Definition: clock.cpp:285
RCLCPP_PUBLIC bool ros_time_is_active()
Definition: clock.cpp:268
RCLCPP_PUBLIC bool wait_until_started(Context::SharedPtr context=contexts::get_global_default_context())
Definition: clock.cpp:212
RCLCPP_PUBLIC Time now() const
Definition: clock.cpp:74
RCLCPP_PUBLIC bool started()
Definition: clock.cpp:203
RCLCPP_PUBLIC JumpHandler::SharedPtr create_jump_callback(JumpHandler::pre_callback_t pre_callback, JumpHandler::post_callback_t post_callback, const rcl_jump_threshold_t &threshold)
Add a callback to invoke if the jump threshold is exceeded.
Definition: clock.cpp:320
RCLCPP_PUBLIC Clock(rcl_clock_type_t clock_type=RCL_SYSTEM_TIME)
Default c'tor.
Definition: clock.cpp:68
RCLCPP_PUBLIC bool sleep_until(Time until, Context::SharedPtr context=contexts::get_global_default_context())
Definition: clock.cpp:87
RCLCPP_PUBLIC std::mutex & get_clock_mutex() noexcept
Get the clock's mutex.
Definition: clock.cpp:297
RCLCPP_PUBLIC bool sleep_for(Duration rel_time, Context::SharedPtr context=contexts::get_global_default_context())
Definition: clock.cpp:197
rcl_duration_value_t nanoseconds() const
Get duration in nanosecods.
Definition: duration.cpp:249
RCLCPP_PUBLIC rcl_time_point_value_t nanoseconds() const
Get the nanoseconds since epoch.
Definition: time.cpp:216
RCLCPP_PUBLIC rcl_clock_type_t get_clock_type() const
Get the clock type.
Definition: time.cpp:228
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Encapsulation of a time source.
Definition: time.h:138
rcl_duration_value_t nanoseconds
Duration in nanoseconds and its source.
Definition: time.h:77
Describe the prerequisites for calling a time jump callback.
Definition: time.h:114
rcl_duration_t min_forward
Definition: time.h:119
bool on_clock_change
True to call callback when the clock type changes.
Definition: time.h:116
rcl_duration_t min_backward
Definition: time.h:122
Struct to describe a jump in time.
Definition: time.h:95
rcl_clock_change_t clock_change
Indicate whether or not the source of time changed.
Definition: time.h:97
rcl_time_point_value_t nanoseconds
Nanoseconds of the point in time.
Definition: time.h:158
enum rcl_clock_type_e rcl_clock_type_t
Time source type, used to indicate the source of a time measurement.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_clock_get_now(rcl_clock_t *clock, rcl_time_point_value_t *time_point_value)
Fill the time point value with the current value of the associated clock.
Definition: time.c:263
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_clock_fini(rcl_clock_t *clock)
Finalize a clock.
Definition: time.c:132
@ RCL_ROS_TIME_NO_CHANGE
The source before and after the jump is ROS_TIME.
Definition: time.h:84
RCL_PUBLIC RCL_WARN_UNUSED bool rcl_clock_time_started(rcl_clock_t *clock)
Check if the clock has started.
Definition: time.c:76
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_clock_add_jump_callback(rcl_clock_t *clock, rcl_jump_threshold_t threshold, rcl_jump_callback_t callback, void *user_data)
Add a callback to be called when a time jump exceeds a threshold.
Definition: time.c:392
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_is_enabled_ros_time_override(rcl_clock_t *clock, bool *is_enabled)
Check if the RCL_ROS_TIME time source has the override enabled.
Definition: time.c:343
@ RCL_ROS_TIME
Use ROS time.
Definition: time.h:66
@ RCL_SYSTEM_TIME
Use system time.
Definition: time.h:68
@ RCL_CLOCK_UNINITIALIZED
Clock uninitialized.
Definition: time.h:64
@ RCL_STEADY_TIME
Use a steady clock time.
Definition: time.h:70
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_clock_init(rcl_clock_type_t clock_type, rcl_clock_t *clock, rcl_allocator_t *allocator)
Initialize a clock based on the passed type.
Definition: time.c:98
RCL_PUBLIC RCL_WARN_UNUSED bool rcl_clock_valid(rcl_clock_t *clock)
Check if the clock has valid values.
Definition: time.c:86
#define RCL_RET_OK
Success return code.
Definition: types.h:27
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:24