mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
timeout_manager.h
Go to the documentation of this file.
1// clang: MatousFormat
2
8#ifndef TIMEOUT_MANAGER_H
9#define TIMEOUT_MANAGER_H
10
11#include <rclcpp/rclcpp.hpp>
12
13#include <mrs_lib/timer_handler.h>
14
15#if USE_ROS_TIMER == 1
17#else
19#endif
20
21namespace mrs_lib
22{
24 {
25 public:
26 // | ---------------------- public types ---------------------- |
27 using timeout_id_t = size_t;
28 using callback_t = std::function<void(const rclcpp::Time&)>;
29
30 public:
31 // | --------------------- public methods --------------------- |
32
33 TimeoutManager(const std::shared_ptr<rclcpp::Node>& node, const rclcpp::Rate& update_rate);
34
35 timeout_id_t registerNew(const rclcpp::Duration& timeout, const callback_t& callback, const rclcpp::Time& last_reset, const bool oneshot = false,
36 const bool autostart = true);
37
38 void reset(const timeout_id_t id, const rclcpp::Time& time);
39
40 void pause(const timeout_id_t id);
41
42 void start(const timeout_id_t id, const rclcpp::Time& time);
43
44 void pauseAll();
45
46 void startAll();
47
48 void change(const timeout_id_t id, const rclcpp::Duration& timeout, const callback_t& callback, const rclcpp::Time& last_reset, const bool oneshot = false,
49 const bool autostart = true);
50
51 rclcpp::Time lastReset(const timeout_id_t id);
52
53 bool started(const timeout_id_t id);
54
55 /* implementation details //{ */
56
57 private:
58 // | ---------------------- private types --------------------- |
59 struct timeout_info_t
60 {
61 bool oneshot;
62 bool started;
63 callback_t callback;
64 rclcpp::Duration timeout;
65 rclcpp::Time last_reset;
66 rclcpp::Time last_callback;
67 };
68
69 private:
70 // | --------------------- private methods -------------------- |
71 void main_timer_callback();
72
73 private:
74 // | ------------------------- members ------------------------ |
75 std::recursive_mutex m_mtx;
76 timeout_id_t m_last_id;
77 std::vector<timeout_info_t> m_timeouts;
78
79 std::shared_ptr<rclcpp::Node> node_;
80
81 rclcpp::CallbackGroup::SharedPtr cb_grp_;
82
83 std::shared_ptr<TimerType> m_main_timer;
84
85 //}
86 };
87
88} // namespace mrs_lib
89
90#endif // TIMEOUT_MANAGER_H
rclcpp::Timer wrapper. The interface is the same as with rclcpp::Timer, except for the initialization...
Definition timer_handler.h:94
Custom thread-based Timers with the same interface as mrs_lib::ROSTimer.
Definition timer_handler.h:167
Definition timeout_manager.h:24
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition attitude_converter.h:24