rclcpp
master
C++ ROS Client Library API
|
Go to the documentation of this file.
15 #ifndef RCLCPP__CREATE_SUBSCRIPTION_HPP_
16 #define RCLCPP__CREATE_SUBSCRIPTION_HPP_
71 typename CallbackMessageT =
84 CallbackT && callback,
88 typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = (
89 MessageMemoryStrategyT::create_default()
97 subscription_topic_stats =
nullptr;
101 *node_topics->get_node_base_interface()))
105 "topic_stats_options.publish_period must be greater than 0, specified value of " +
106 std::to_string(options.topic_stats_options.publish_period.count()) +
111 create_publisher<statistics_msgs::msg::MetricsMessage>(
113 options.topic_stats_options.publish_topic,
118 >(node_topics->get_node_base_interface()->get_name(), publisher);
120 auto sub_call_back = [subscription_topic_stats]() {
121 subscription_topic_stats->publish_message();
124 auto node_timer_interface = node_topics->get_node_timers_interface();
127 std::chrono::duration_cast<std::chrono::nanoseconds>(
128 options.topic_stats_options.publish_period),
130 options.callback_group,
131 node_topics->get_node_base_interface(),
135 subscription_topic_stats->set_publisher_timer(timer);
138 auto factory = rclcpp::create_subscription_factory<MessageT>(
139 std::forward<CallbackT>(callback),
142 subscription_topic_stats
145 auto sub = node_topics->create_subscription(topic_name, factory, qos);
146 node_topics->add_subscription(sub, options.callback_group);
148 return std::dynamic_pointer_cast<SubscriptionT>(sub);
153 #endif // RCLCPP__CREATE_SUBSCRIPTION_HPP_
Definition: subscription_topic_statistics.hpp:55
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
Structure containing optional configuration for Subscriptions.
Definition: subscription_options.hpp:79
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
Subscription implementation, templated on the type of message this subscription receives.
Definition: subscription.hpp:69
Encapsulation of Quality of Service settings.
Definition: qos.hpp:59
std::shared_ptr< rclcpp::node_interfaces::NodeTopicsInterface > get_node_topics_interface(NodeType &&node)
Get the NodeTopicsInterface as a shared pointer from a pointer to a "Node like" object.
Definition: get_node_topics_interface.hpp:72
bool resolve_enable_topic_statistics(const OptionsT &options, const NodeBaseT &node_base)
Return whether or not topic statistics is enabled, resolving "NodeDefault" if needed.
Definition: resolve_enable_topic_statistics.hpp:30
Default allocation strategy for messages received by subscriptions.
Definition: message_memory_strategy.hpp:41
std::shared_ptr< SubscriptionT > create_subscription(NodeT &&node, const std::string &topic_name, const rclcpp::QoS &qos, CallbackT &&callback, const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &options=(rclcpp::SubscriptionOptionsWithAllocator< AllocatorT >()), typename MessageMemoryStrategyT::SharedPtr msg_mem_strat=(MessageMemoryStrategyT::create_default()))
Create and return a subscription of the given MessageT type.
Definition: create_subscription.hpp:80