15 #ifndef RCLCPP__NODE_IMPL_HPP_ 16 #define RCLCPP__NODE_IMPL_HPP_ 36 #include "rcl_interfaces/msg/intra_process_message.hpp" 46 #ifndef RCLCPP__NODE_HPP_ 55 template<
typename MessageT,
typename Alloc,
typename PublisherT>
56 std::shared_ptr<PublisherT>
58 const std::string & topic_name,
size_t qos_history_depth,
59 std::shared_ptr<Alloc> allocator)
62 allocator = std::make_shared<Alloc>();
65 qos.
depth = qos_history_depth;
66 return this->create_publisher<MessageT, Alloc, PublisherT>(topic_name, qos, allocator);
69 template<
typename MessageT,
typename Alloc,
typename PublisherT>
70 std::shared_ptr<PublisherT>
73 std::shared_ptr<Alloc> allocator)
76 allocator = std::make_shared<Alloc>();
78 return rclcpp::create_publisher<MessageT, Alloc, PublisherT>(
79 this->node_topics_.get(),
82 use_intra_process_comms_,
86 template<
typename MessageT,
typename CallbackT,
typename Alloc,
typename SubscriptionT>
87 std::shared_ptr<SubscriptionT>
89 const std::string & topic_name,
90 CallbackT && callback,
92 rclcpp::callback_group::CallbackGroup::SharedPtr group,
93 bool ignore_local_publications,
96 std::shared_ptr<Alloc> allocator)
99 allocator = std::make_shared<Alloc>();
102 if (!msg_mem_strat) {
104 msg_mem_strat = MessageMemoryStrategy<MessageT, Alloc>::create_default();
107 return rclcpp::create_subscription<MessageT, CallbackT, Alloc, SubscriptionT>(
108 this->node_topics_.get(),
110 std::forward<CallbackT>(callback),
113 ignore_local_publications,
114 use_intra_process_comms_,
119 template<
typename MessageT,
typename CallbackT,
typename Alloc,
typename SubscriptionT>
120 std::shared_ptr<SubscriptionT>
122 const std::string & topic_name,
123 size_t qos_history_depth,
124 CallbackT && callback,
125 rclcpp::callback_group::CallbackGroup::SharedPtr group,
126 bool ignore_local_publications,
129 std::shared_ptr<Alloc> allocator)
132 qos.
depth = qos_history_depth;
133 return this->create_subscription<MessageT, CallbackT, Alloc, SubscriptionT>(
135 std::forward<CallbackT>(callback),
138 ignore_local_publications,
143 template<
typename DurationT,
typename CallbackT>
146 std::chrono::duration<int64_t, DurationT> period,
148 rclcpp::callback_group::CallbackGroup::SharedPtr group)
151 std::chrono::duration_cast<std::chrono::nanoseconds>(period),
152 std::move(callback));
153 node_timers_->add_timer(timer, group);
157 template<
typename ServiceT>
160 const std::string & service_name,
162 rclcpp::callback_group::CallbackGroup::SharedPtr group)
165 options.
qos = qos_profile;
170 auto cli = Client<ServiceT>::make_shared(
176 auto cli_base_ptr = std::dynamic_pointer_cast<ClientBase>(cli);
177 node_services_->add_client(cli_base_ptr, group);
181 template<
typename ServiceT,
typename CallbackT>
184 const std::string & service_name,
185 CallbackT && callback,
187 rclcpp::callback_group::CallbackGroup::SharedPtr group)
190 any_service_callback.
set(std::forward<CallbackT>(callback));
193 service_options.
qos = qos_profile;
196 node_base_->get_shared_rcl_node_handle(),
197 service_name, any_service_callback, service_options);
199 node_services_->add_service(serv_base_ptr, group);
203 template<
typename CallbackT>
207 this->node_parameters_->register_param_change_callback(std::forward<CallbackT>(callback));
210 template<
typename ParameterT>
213 const std::string & name,
214 const ParameterT & value)
224 template<
typename ParameterT>
231 value = parameter_variant.
get_value<ParameterT>();
237 template<
typename ParameterT>
240 const std::string & name,
242 const ParameterT & alternative_value)
const 245 if (!got_parameter) {
246 value = alternative_value;
248 return got_parameter;
254 #endif // RCLCPP__NODE_IMPL_HPP_ void set_parameter_if_not_set(const std::string &name, const ParameterT &value)
Definition: node_impl.hpp:212
rclcpp::timer::WallTimer< CallbackT >::SharedPtr create_wall_timer(std::chrono::duration< int64_t, DurationT > period, CallbackT callback, rclcpp::callback_group::CallbackGroup::SharedPtr group=nullptr)
Create a timer.
Definition: node_impl.hpp:145
std::vector< rcl_interfaces::msg::SetParametersResult > set_parameters(const std::vector< rclcpp::parameter::ParameterVariant > ¶meters)
Default allocation strategy for messages received by subscriptions.
Definition: message_memory_strategy.hpp:33
Definition: service.hpp:89
std::shared_ptr< PublisherT > create_publisher(const std::string &topic_name, size_t qos_history_depth, std::shared_ptr< Alloc > allocator=nullptr)
Create and return a Publisher.
Definition: node_impl.hpp:57
rclcpp::client::Client< ServiceT >::SharedPtr create_client(const std::string &service_name, const rmw_qos_profile_t &qos_profile=rmw_qos_profile_services_default, rclcpp::callback_group::CallbackGroup::SharedPtr group=nullptr)
Definition: allocator_common.hpp:24
rclcpp::parameter::ParameterVariant get_parameter(const std::string &name) const
Definition: service.hpp:41
bool get_parameter_or(const std::string &name, ParameterT &value, const ParameterT &alternative_value) const
Get the parameter value, or the "alternative value" if not set, and assign it to "value".
Definition: node_impl.hpp:239
void set(CallbackT callback)
Definition: any_service_callback.hpp:66
rcl_client_options_t rcl_client_get_default_options(void)
std::enable_if< type==ParameterType::PARAMETER_INTEGER, int64_t >::type get_value() const
Definition: parameter.hpp:87
rclcpp::service::Service< ServiceT >::SharedPtr create_service(const std::string &service_name, CallbackT &&callback, const rmw_qos_profile_t &qos_profile=rmw_qos_profile_services_default, rclcpp::callback_group::CallbackGroup::SharedPtr group=nullptr)
Definition: node_impl.hpp:183
Definition: client.hpp:53
Generic timer templated on the clock type. Periodically executes a user-specified callback...
Definition: timer.hpp:107
Definition: parameter.hpp:45
rcl_service_options_t rcl_service_get_default_options(void)
Definition: client.hpp:113
void register_param_change_callback(CallbackT &&callback)
Register the callback for parameter changes.
Definition: node_impl.hpp:205
std::shared_ptr< SubscriptionT > create_subscription(const std::string &topic_name, CallbackT &&callback, const rmw_qos_profile_t &qos_profile=rmw_qos_profile_default, rclcpp::callback_group::CallbackGroup::SharedPtr group=nullptr, bool ignore_local_publications=false, typename rclcpp::message_memory_strategy::MessageMemoryStrategy< MessageT, Alloc >::SharedPtr msg_mem_strat=nullptr, std::shared_ptr< Alloc > allocator=nullptr)
Create and return a Subscription.
Definition: node_impl.hpp:88
Definition: any_service_callback.hpp:34