rclcpp
master
C++ ROS Client Library API
|
Go to the documentation of this file.
15 #ifndef RCLCPP__NODE_IMPL_HPP_
16 #define RCLCPP__NODE_IMPL_HPP_
34 #include "rcl/publisher.h"
35 #include "rcl/subscription.h"
50 #ifndef RCLCPP__NODE_HPP_
63 if (sub_namespace !=
"" && name.
front() !=
'/' && name.
front() !=
'~') {
64 name_with_sub_namespace = sub_namespace +
"/" + name;
66 return name_with_sub_namespace;
69 template<
typename MessageT,
typename AllocatorT,
typename PublisherT>
76 return rclcpp::create_publisher<MessageT, AllocatorT, PublisherT>(
87 typename CallbackMessageT,
88 typename SubscriptionT,
89 typename MessageMemoryStrategyT>
94 CallbackT && callback,
96 typename MessageMemoryStrategyT::SharedPtr msg_mem_strat)
98 return rclcpp::create_subscription<MessageT>(
102 std::forward<CallbackT>(callback),
107 template<
typename DurationRepT,
typename DurationT,
typename CallbackT>
112 rclcpp::CallbackGroup::SharedPtr group)
118 this->node_base_.get(),
119 this->node_timers_.get());
122 template<
typename ServiceT>
127 rclcpp::CallbackGroup::SharedPtr group)
129 return rclcpp::create_client<ServiceT>(
138 template<
typename ServiceT,
typename CallbackT>
142 CallbackT && callback,
144 rclcpp::CallbackGroup::SharedPtr group)
146 return rclcpp::create_service<ServiceT, CallbackT>(
150 std::forward<CallbackT>(callback),
155 template<
typename ParameterT>
159 const ParameterT & default_value,
160 const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor,
161 bool ignore_override)
167 parameter_descriptor,
175 template<
typename ParameterT>
180 bool ignore_overrides)
183 std::string normalized_namespace = namespace_.
empty() ?
"" : (namespace_ +
".");
186 [
this, &normalized_namespace, ignore_overrides](
auto element) {
187 return this->declare_parameter(
188 normalized_namespace + element.first,
190 rcl_interfaces::msg::ParameterDescriptor(),
197 template<
typename ParameterT>
205 bool ignore_overrides)
208 std::string normalized_namespace = namespace_.
empty() ?
"" : (namespace_ +
".");
211 [
this, &normalized_namespace, ignore_overrides](
auto element) {
212 return static_cast<ParameterT>(
213 this->declare_parameter(
214 normalized_namespace + element.first,
215 element.second.first,
216 element.second.second,
224 template<
typename ParameterT>
234 parameter =
static_cast<ParameterT
>(parameter_variant.
get_value<ParameterT>());
240 template<
typename ParameterT>
244 ParameterT & parameter,
245 const ParameterT & alternative_value)
const
250 if (!got_parameter) {
251 parameter = alternative_value;
253 return got_parameter;
259 template<
typename ParameterT>
266 bool result = node_parameters_->get_parameters_by_prefix(prefix, params);
268 for (
const auto & param : params) {
269 values[param.first] =
static_cast<ParameterT
>(param.second.get_value<ParameterT>());
278 #endif // RCLCPP__NODE_IMPL_HPP_
Store the type and value of a parameter.
Definition: parameter_value.hpp:71
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
#define RCLCPP_LOCAL
Definition: visibility_control.hpp:51
rclcpp::WallTimer< CallbackT >::SharedPtr create_wall_timer(std::chrono::duration< DurationRepT, DurationT > period, CallbackT callback, rclcpp::CallbackGroup::SharedPtr group=nullptr)
Create a timer.
Definition: node_impl.hpp:109
constexpr std::enable_if< type==ParameterType::PARAMETER_BOOL, const bool & >::type get() const
Definition: parameter_value.hpp:148
T back_inserter(T... args)
decltype(auto) get_value() const
Get value of parameter using rclcpp::ParameterType as template argument.
Definition: parameter.hpp:117
Definition: service.hpp:144
std::shared_ptr< SubscriptionT > create_subscription(const std::string &topic_name, const rclcpp::QoS &qos, CallbackT &&callback, const SubscriptionOptionsWithAllocator< AllocatorT > &options=SubscriptionOptionsWithAllocator< AllocatorT >(), typename MessageMemoryStrategyT::SharedPtr msg_mem_strat=(MessageMemoryStrategyT::create_default()))
Create and return a Subscription.
Definition: node_impl.hpp:91
rclcpp::Client< ServiceT >::SharedPtr create_client(const std::string &service_name, const rmw_qos_profile_t &qos_profile=rmw_qos_profile_services_default, rclcpp::CallbackGroup::SharedPtr group=nullptr)
Create and return a Client.
Structure containing optional configuration for Subscriptions.
Definition: subscription_options.hpp:79
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(), bool ignore_override=false)
Declare and initialize a parameter, return the effective value.
Indicate the parameter type does not match the expected type.
Definition: parameter_value.hpp:56
RCLCPP_LOCAL std::string extend_name_with_sub_namespace(const std::string &name, const std::string &sub_namespace)
Definition: node_impl.hpp:60
rclcpp::Parameter get_parameter(const std::string &name) const
Return the parameter by the given name.
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
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:71
Encapsulation of Quality of Service settings.
Definition: qos.hpp:59
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::CallbackGroup::SharedPtr group=nullptr)
Create and return a Service.
Definition: node_impl.hpp:140
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:242
std::vector< ParameterT > declare_parameters(const std::string &namespace_, const std::map< std::string, ParameterT > ¶meters, bool ignore_overrides=false)
Declare and initialize several parameters with the same namespace and type.
Definition: node_impl.hpp:177
Structure containing optional configuration for Publishers.
Definition: publisher_options.hpp:57
Definition: client.hpp:178
const std::string & get_sub_namespace() const
Return the sub-namespace, if this is a sub-node, otherwise an empty string.
Definition: timer.hpp:259
Structure to store an arbitrary parameter with templated get/set methods.
Definition: parameter.hpp:52
Thrown if requested parameter type is invalid.
Definition: exceptions.hpp:234