mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
timer_handler.hpp
1#ifndef MRS_TIMER_HPP
2#define MRS_TIMER_HPP
3
4#ifndef MRS_TIMER_H
5#include <mrs_lib/timer_handler.h>
6#endif
7
8#include <mutex>
9
10namespace mrs_lib
11{
12
13// | ----------------------- ThreadTimer ---------------------- |
14
15/* class ThreadTimer::Impl //{ */
16
18public:
19 Impl(const rclcpp::Node::SharedPtr& node, const std::function<void()>& callback, const rclcpp::Rate& rate, const bool oneshot);
20
21 ~Impl();
22
23 void start();
24 void stop();
25 void setPeriod(const rclcpp::Duration& duration);
26 void setCallback(const std::function<void()>& callback);
27
28 friend class ThreadTimer;
29
30 // to keep rule of five since we have a custom destructor
31 Impl(const Impl&) = delete;
32 Impl(Impl&&) = delete;
33 Impl& operator=(const Impl&) = delete;
34 Impl& operator=(Impl&&) = delete;
35
36private:
37 std::thread thread_;
38 std::function<void()> callback_;
39
40 rclcpp::Node::SharedPtr node_;
41
42 bool oneshot_;
43
44 bool breakableSleep(const rclcpp::Time& until);
45 void threadFcn();
46
47 std::mutex mutex_wakeup_;
48 std::condition_variable wakeup_cond_;
49 std::recursive_mutex mutex_state_;
50 bool running_;
51 std::chrono::nanoseconds delay_dur_;
52 bool ending_;
53 rclcpp::Time next_expected_;
54};
55
56//}
57
58} // namespace mrs_lib
59
60#endif // MRS_TIMER_HPP
Custom thread-based Timers with the same interface as mrs_lib::ROSTimer.
Definition timer_handler.h:167
Definition timer_handler.hpp:17
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition attitude_converter.h:24