ros2_control - iron
Loading...
Searching...
No Matches
realtime_clock.hpp
1// Copyright (c) 2013, hiDOF, Inc.
2//
3// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8//
9// * Redistributions in binary form must reproduce the above copyright
10// notice, this list of conditions and the following disclaimer in the
11// documentation and/or other materials provided with the distribution.
12//
13// * Neither the name of the hiDOF, Inc. nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27// POSSIBILITY OF SUCH DAMAGE.
28
29/*
30 * Author: Wim Meeussen
31 */
32
33#ifndef REALTIME_TOOLS__REALTIME_CLOCK_HPP_
34#define REALTIME_TOOLS__REALTIME_CLOCK_HPP_
35
36#include <mutex>
37#include <thread>
38
39#include "rclcpp/clock.hpp"
40#include "rclcpp/duration.hpp"
41#include "rclcpp/logger.hpp"
42#include "rclcpp/time.hpp"
43
44namespace realtime_tools
45{
46class [[deprecated("Use rclcpp::Clock or std::chrono::steady_clock instead")]] RealtimeClock
47{
48public:
53
57 explicit RealtimeClock(rclcpp::Clock::SharedPtr clock);
58
62 RealtimeClock(rclcpp::Clock::SharedPtr clock, rclcpp::Logger logger);
63
65
70 [[deprecated]] rclcpp::Time getSystemTime(const rclcpp::Time & realtime_time = rclcpp::Time());
71
77 rclcpp::Time now(const rclcpp::Time & realtime_time = rclcpp::Time());
78
79private:
80 void loop();
81
82 rclcpp::Clock::SharedPtr clock_;
83 rclcpp::Logger logger_;
84 unsigned int lock_misses_ = 0;
85 rclcpp::Time system_time_;
86 rclcpp::Duration clock_offset_{0, 0u};
87
88 rclcpp::Time last_realtime_time_;
89 bool running_ = false;
90 bool initialized_ = false;
91 std::mutex mutex_;
92 std::thread thread_;
93}; // class
94
95} // namespace realtime_tools
96#endif // REALTIME_TOOLS__REALTIME_CLOCK_HPP_
Definition realtime_clock.hpp:47
rclcpp::Time getSystemTime(const rclcpp::Time &realtime_time=rclcpp::Time())
A pthread mutex wrapper that provides a mutex with the priority inheritance protocol and a priority c...
Definition async_function_handler.hpp:38