15 #ifndef RCLCPP__NODE_IMPL_HPP_ 16 #define RCLCPP__NODE_IMPL_HPP_ 36 #include "rcl_interfaces/msg/intra_process_message.hpp" 47 #ifndef RCLCPP__NODE_HPP_ 54 template<
typename MessageT,
typename Alloc,
typename PublisherT>
57 const std::string & topic_name,
size_t qos_history_depth,
61 allocator = std::make_shared<Alloc>();
64 qos.
depth = qos_history_depth;
65 return this->create_publisher<MessageT, Alloc, PublisherT>(topic_name, qos, allocator);
68 template<
typename MessageT,
typename Alloc,
typename PublisherT>
75 allocator = std::make_shared<Alloc>();
77 return rclcpp::create_publisher<MessageT, Alloc, PublisherT>(
78 this->node_topics_.get(),
81 use_intra_process_comms_,
89 typename SubscriptionT>
93 CallbackT && callback,
95 rclcpp::callback_group::CallbackGroup::SharedPtr group,
96 bool ignore_local_publications,
105 allocator = std::make_shared<Alloc>();
108 if (!msg_mem_strat) {
113 return rclcpp::create_subscription<MessageT, CallbackT, Alloc, CallbackMessageT, SubscriptionT>(
114 this->node_topics_.get(),
116 std::forward<CallbackT>(callback),
119 ignore_local_publications,
120 use_intra_process_comms_,
129 typename SubscriptionT>
133 CallbackT && callback,
134 size_t qos_history_depth,
135 rclcpp::callback_group::CallbackGroup::SharedPtr group,
136 bool ignore_local_publications,
143 qos.
depth = qos_history_depth;
144 return this->create_subscription<MessageT>(
146 std::forward<CallbackT>(callback),
149 ignore_local_publications,
154 template<
typename DurationT,
typename CallbackT>
159 rclcpp::callback_group::CallbackGroup::SharedPtr group)
162 std::chrono::duration_cast<std::chrono::nanoseconds>(period),
164 this->node_base_->get_context());
165 node_timers_->add_timer(timer, group);
169 template<
typename ServiceT>
174 rclcpp::callback_group::CallbackGroup::SharedPtr group)
177 options.
qos = qos_profile;
189 node_services_->add_client(cli_base_ptr, group);
193 template<
typename ServiceT,
typename CallbackT>
197 CallbackT && callback,
199 rclcpp::callback_group::CallbackGroup::SharedPtr group)
201 return rclcpp::create_service<ServiceT, CallbackT>(
202 node_base_, node_services_,
203 service_name, std::forward<CallbackT>(callback), qos_profile, group);
206 template<
typename CallbackT>
210 this->node_parameters_->register_param_change_callback(std::forward<CallbackT>(callback));
213 template<
typename ParameterT>
217 const ParameterT & value)
230 template<
typename MapValueT>
238 for (
const auto & val : values) {
249 template<
typename ParameterT>
256 value = parameter.
get_value<ParameterT>();
265 template<
typename MapValueT>
274 rcl_interfaces::msg::ListParametersResult result = node_parameters_->list_parameters(prefix, 0);
275 for (
const auto & param : result.names) {
276 values[param.substr(name_with_dot.
length())] =
277 node_parameters_->get_parameter(param).get_value<MapValueT>();
284 template<
typename ParameterT>
289 const ParameterT & alternative_value)
const 292 if (!got_parameter) {
293 value = alternative_value;
295 return got_parameter;
298 template<
typename ParameterT>
303 const ParameterT & alternative_value)
306 if (!got_parameter) {
310 value = alternative_value;
316 #endif // RCLCPP__NODE_IMPL_HPP_ void register_param_change_callback(CallbackT &&callback)
Register the callback for parameter changes.
Definition: node_impl.hpp:208
Definition: client.hpp:52
Default allocation strategy for messages received by subscriptions.
Definition: message_memory_strategy.hpp:40
rclcpp::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)
Structure to store an arbitrary parameter with templated get/set methods.
Definition: parameter.hpp:32
Definition: timer.hpp:192
rclcpp::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:156
Definition: allocator_common.hpp:24
Definition: service.hpp:88
Definition: client.hpp:119
void get_parameter_or_set(const std::string &name, ParameterT &value, const ParameterT &alternative_value)
Get the parameter value; if not set, set the "alternative value" and store it in the node...
Definition: node_impl.hpp:300
decltype(auto) get_value() const
Get value of parameter using rclcpp::ParameterType as template argument.
Definition: parameter.hpp:66
void set_parameters_if_not_set(const std::string &name, const std::map< std::string, MapValueT > &values)
Set a map of parameters with the same prefix.
Definition: node_impl.hpp:232
static SharedPtr create_default()
Default factory method.
Definition: message_memory_strategy.hpp:77
std::vector< rcl_interfaces::msg::SetParametersResult > set_parameters(const std::vector< rclcpp::Parameter > ¶meters)
rcl_client_options_t rcl_client_get_default_options(void)
T dynamic_pointer_cast(T... args)
void set_parameter_if_not_set(const std::string &name, const ParameterT &value)
Definition: node_impl.hpp:215
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:56
rclcpp::Parameter get_parameter(const std::string &name) const
std::vector< rclcpp::Parameter > get_parameters(const std::vector< std::string > &names) const
rclcpp::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:195
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< typename rclcpp::subscription_traits::has_message_type< CallbackT >::type, Alloc >::SharedPtr msg_mem_strat=nullptr, std::shared_ptr< Alloc > allocator=nullptr)
Create and return a Subscription.
Definition: node_impl.hpp:91
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:286