15 #ifndef RCLCPP__NODE_IMPL_HPP_ 16 #define RCLCPP__NODE_IMPL_HPP_ 36 #include "rcl_interfaces/msg/intra_process_message.hpp" 48 #ifndef RCLCPP__NODE_HPP_ 61 if (sub_namespace !=
"" && name.
front() !=
'/' && name.
front() !=
'~') {
62 name_with_sub_namespace = sub_namespace +
"/" + name;
64 return name_with_sub_namespace;
67 template<
typename MessageT,
typename AllocatorT,
typename PublisherT>
74 return rclcpp::create_publisher<MessageT, AllocatorT, PublisherT>(
81 template<
typename MessageT,
typename AllocatorT,
typename PublisherT>
85 size_t qos_history_depth,
90 return this->create_publisher<MessageT, AllocatorT, PublisherT>(
94 template<
typename MessageT,
typename AllocatorT,
typename PublisherT>
106 return this->create_publisher<MessageT, AllocatorT, PublisherT>(topic_name, qos, pub_options);
113 typename SubscriptionT>
118 CallbackT && callback,
124 return rclcpp::create_subscription<MessageT>(
128 std::forward<CallbackT>(callback),
137 typename SubscriptionT>
141 CallbackT && callback,
143 rclcpp::callback_group::CallbackGroup::SharedPtr group,
144 bool ignore_local_publications,
158 return this->create_subscription<MessageT, CallbackT, Alloc, SubscriptionT>(
159 topic_name, qos, std::forward<CallbackT>(callback), sub_options, msg_mem_strat);
166 typename SubscriptionT>
170 CallbackT && callback,
171 size_t qos_history_depth,
172 rclcpp::callback_group::CallbackGroup::SharedPtr group,
173 bool ignore_local_publications,
184 return this->create_subscription<MessageT, CallbackT, Alloc, SubscriptionT>(
187 std::forward<CallbackT>(callback),
192 template<
typename DurationRepT,
typename DurationT,
typename CallbackT>
197 rclcpp::callback_group::CallbackGroup::SharedPtr group)
200 std::chrono::duration_cast<std::chrono::nanoseconds>(period),
202 this->node_base_->get_context());
203 node_timers_->add_timer(timer, group);
207 template<
typename ServiceT>
212 rclcpp::callback_group::CallbackGroup::SharedPtr group)
215 options.
qos = qos_profile;
227 node_services_->add_client(cli_base_ptr, group);
231 template<
typename ServiceT,
typename CallbackT>
235 CallbackT && callback,
237 rclcpp::callback_group::CallbackGroup::SharedPtr group)
239 return rclcpp::create_service<ServiceT, CallbackT>(
243 std::forward<CallbackT>(callback),
248 template<
typename ParameterT>
252 const ParameterT & default_value,
253 const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor)
262 template<
typename ParameterT>
269 std::string normalized_namespace = namespace_.
empty() ?
"" : (namespace_ +
".");
272 [
this, &normalized_namespace](
auto element) {
273 return this->
declare_parameter(normalized_namespace + element.first, element.second);
279 template<
typename ParameterT>
289 std::string normalized_namespace = namespace_.
empty() ?
"" : (namespace_ +
".");
292 [
this, &normalized_namespace](
auto element) {
293 return static_cast<ParameterT
>(
295 normalized_namespace + element.first,
296 element.second.first,
297 element.second.second)
304 template<
typename ParameterT>
308 const ParameterT & value)
321 template<
typename ParameterT>
329 for (
const auto & val : values) {
330 std::string parameter_name = name +
"." + val.first;
342 template<
typename ParameterT>
352 parameter =
static_cast<ParameterT
>(parameter_variant.
get_value<ParameterT>());
358 template<
typename ParameterT>
362 ParameterT & parameter,
363 const ParameterT & alternative_value)
const 368 if (!got_parameter) {
369 parameter = alternative_value;
371 return got_parameter;
377 template<
typename ParameterT>
384 bool result = node_parameters_->get_parameters_by_prefix(prefix, params);
386 for (
const auto & param : params) {
387 values[param.first] =
static_cast<ParameterT
>(param.second.get_value<ParameterT>());
394 template<
typename ParameterT>
399 const ParameterT & alternative_value)
404 if (!got_parameter) {
408 value = alternative_value;
412 template<
typename CallbackT>
416 this->node_parameters_->register_param_change_callback(std::forward<CallbackT>(callback));
421 #endif // RCLCPP__NODE_IMPL_HPP_ void register_param_change_callback(CallbackT &&callback)
Register the callback for parameter changes.
Definition: node_impl.hpp:414
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)
rcl_interfaces::msg::SetParametersResult set_parameter(const rclcpp::Parameter ¶meter)
Set a single parameter.
Definition: parameter_value.hpp:34
bool get_parameter_or(const std::string &name, ParameterT ¶meter, const ParameterT &alternative_value) const
Get the parameter value, or the "alternative_value" if not set, and assign it to "parameter".
Definition: node_impl.hpp:360
Encapsulation of Quality of Service settings.
Definition: qos.hpp:55
Structure to store an arbitrary parameter with templated get/set methods.
Definition: parameter.hpp:51
Definition: timer.hpp:202
bool has_parameter(const std::string &name) const
Return true if a given parameter is declared.
const std::string & get_sub_namespace() const
Return the sub-namespace, if this is a sub-node, otherwise an empty string.
rmw_qos_profile_t & get_rmw_qos_profile()
Return the rmw qos profile.
This header provides the get_node_topics_interface() template function.
Definition: allocator_common.hpp:24
Use to initialize the QoS with the keep_last history setting and the given depth. ...
Definition: qos.hpp:49
static QoSInitialization from_rmw(const rmw_qos_profile_t &rmw_qos)
Create a QoSInitialization from an existing rmw_qos_profile_t, using its history and depth...
Definition: service.hpp:88
RCLCPP_LOCAL std::string extend_name_with_sub_namespace(const std::string &name, const std::string &sub_namespace)
Definition: node_impl.hpp:58
std::vector< ParameterT > declare_parameters(const std::string &namespace_, const std::map< std::string, ParameterT > ¶meters)
Declare and initialize several parameters with the same namespace and type.
Definition: node_impl.hpp:264
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:396
decltype(auto) get_value() const
Get value of parameter using rclcpp::ParameterType as template argument.
Definition: parameter.hpp:109
std::shared_ptr< Allocator > allocator
Optional custom allocator.
Definition: subscription_options.hpp:49
std::shared_ptr< Allocator > allocator
Optional custom allocator.
Definition: publisher_options.hpp:50
std::vector< rcl_interfaces::msg::SetParametersResult > set_parameters(const std::vector< rclcpp::Parameter > ¶meters)
Set one or more parameters, one at a time.
rcl_interfaces::msg::ParameterDescriptor describe_parameter(const std::string &name) const
Return the parameter descriptor for the given parameter name.
void set_parameters_if_not_set(const std::string &name, const std::map< std::string, ParameterT > &values)
Set a map of parameters with the same prefix.
Definition: node_impl.hpp:323
rcl_client_options_t rcl_client_get_default_options(void)
T dynamic_pointer_cast(T... args)
#define RCLCPP_LOCAL
Definition: visibility_control.hpp:51
std::shared_ptr< PublisherT > create_publisher(const std::string &topic_name, const rclcpp::QoS &qos, const PublisherOptionsWithAllocator< AllocatorT > &options=PublisherOptionsWithAllocator< AllocatorT >())
Create and return a Publisher.
Definition: node_impl.hpp:69
Structure containing optional configuration for Publishers.
Definition: publisher_options.hpp:47
Structure containing optional configuration for Subscriptions.
Definition: subscription_options.hpp:46
void set_parameter_if_not_set(const std::string &name, const ParameterT &value)
Set one parameter, unless that parameter has already been set.
Definition: node_impl.hpp:306
rclcpp::WallTimer< CallbackT >::SharedPtr create_wall_timer(std::chrono::duration< DurationRepT, DurationT > period, CallbackT callback, rclcpp::callback_group::CallbackGroup::SharedPtr group=nullptr)
Create a timer.
Definition: node_impl.hpp:194
const rclcpp::ParameterValue & declare_parameter(const std::string &name, const rclcpp::ParameterValue &default_value=rclcpp::ParameterValue(), const rcl_interfaces::msg::ParameterDescriptor ¶meter_descriptor=rcl_interfaces::msg::ParameterDescriptor())
Declare and initialize a parameter, return the effective value.
T back_inserter(T... args)
rclcpp::callback_group::CallbackGroup::SharedPtr callback_group
The callback group for this subscription. NULL to use the default callback group. ...
Definition: subscription_options.hpp:39
constexpr std::enable_if< type==ParameterType::PARAMETER_BOOL, const bool & >::type get() const
Definition: parameter_value.hpp:148
Store the type and value of a parameter.
Definition: parameter_value.hpp:71
std::shared_ptr< SubscriptionT > create_subscription(const std::string &topic_name, const rclcpp::QoS &qos, CallbackT &&callback, const SubscriptionOptionsWithAllocator< AllocatorT > &options=SubscriptionOptionsWithAllocator< AllocatorT >(), typename rclcpp::message_memory_strategy::MessageMemoryStrategy< typename rclcpp::subscription_traits::has_message_type< CallbackT >::type, AllocatorT >::SharedPtr msg_mem_strat=nullptr)
Create and return a Subscription.
Definition: node_impl.hpp:115
rclcpp::Parameter get_parameter(const std::string &name) const
Return the parameter by the given name.
std::vector< rclcpp::Parameter > get_parameters(const std::vector< std::string > &names) const
Return the parameters by the given parameter names.
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:233
bool ignore_local_publications
True to ignore local publications.
Definition: subscription_options.hpp:37