rclcpp
master
C++ ROS Client Library API
|
Go to the documentation of this file.
15 #ifndef RCLCPP__CREATE_TIMER_HPP_
16 #define RCLCPP__CREATE_TIMER_HPP_
34 template<
typename CallbackT>
35 typename rclcpp::TimerBase::SharedPtr
39 rclcpp::Clock::SharedPtr clock,
41 CallbackT && callback,
42 rclcpp::CallbackGroup::SharedPtr group =
nullptr)
47 std::forward<CallbackT>(callback),
48 node_base->get_context());
50 node_timers->add_timer(timer, group);
55 template<
typename NodeT,
typename CallbackT>
56 typename rclcpp::TimerBase::SharedPtr
59 rclcpp::Clock::SharedPtr clock,
61 CallbackT && callback,
62 rclcpp::CallbackGroup::SharedPtr group =
nullptr)
69 std::forward<CallbackT>(callback),
88 template<
typename DurationRepT,
typename DurationT,
typename CallbackT>
93 rclcpp::CallbackGroup::SharedPtr group,
97 if (node_base ==
nullptr) {
101 if (node_timers ==
nullptr) {
111 constexpr
auto maximum_safe_cast_ns =
121 constexpr
auto ns_max_as_double =
122 std::chrono::duration_cast<std::chrono::duration<double, std::chrono::nanoseconds::period>>(
123 maximum_safe_cast_ns);
124 if (period > ns_max_as_double) {
126 "timer period must be less than std::chrono::nanoseconds::max()"};
129 const auto period_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(period);
132 "Casting timer period to nanoseconds resulted in integer overflow."};
143 #endif // RCLCPP__CREATE_TIMER_HPP_
rclcpp::WallTimer< CallbackT >::SharedPtr create_wall_timer(std::chrono::duration< DurationRepT, DurationT > period, CallbackT callback, rclcpp::CallbackGroup::SharedPtr group, node_interfaces::NodeBaseInterface *node_base, node_interfaces::NodeTimersInterface *node_timers)
Convenience method to create a timer with node resources.
Definition: create_timer.hpp:90
virtual rclcpp::Context::SharedPtr get_context()=0
Return the context of the node.
std::shared_ptr< rclcpp::node_interfaces::NodeBaseInterface > get_node_base_interface(NodeType &&node)
Get the NodeBaseInterface as a shared pointer from a pointer to a "Node like" object.
Definition: get_node_base_interface.hpp:72
DurationT to_chrono() const
Convert Duration into a std::chrono::Duration.
Definition: duration.hpp:146
virtual void add_timer(rclcpp::TimerBase::SharedPtr timer, rclcpp::CallbackGroup::SharedPtr callback_group)=0
Add a timer to the node.
Generic timer. Periodically executes a user-specified callback.
Definition: timer.hpp:159
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
Pure virtual interface class for the NodeTimers part of the Node API.
Definition: node_timers_interface.hpp:29
Definition: duration.hpp:26
rclcpp::TimerBase::SharedPtr create_timer(std::shared_ptr< node_interfaces::NodeBaseInterface > node_base, std::shared_ptr< node_interfaces::NodeTimersInterface > node_timers, rclcpp::Clock::SharedPtr clock, rclcpp::Duration period, CallbackT &&callback, rclcpp::CallbackGroup::SharedPtr group=nullptr)
Definition: create_timer.hpp:36
Definition: timer.hpp:259
std::shared_ptr< rclcpp::node_interfaces::NodeTimersInterface > get_node_timers_interface(NodeType &&node)
Get the NodeTimersInterface as a shared pointer from a pointer to a "Node like" object.
Definition: get_node_timers_interface.hpp:72