12#ifndef NROS_RCLCPP_RCLCPP_HPP
13#define NROS_RCLCPP_RCLCPP_HPP
18#include "rclcpp/detail/nros_cpp_ffi.h"
20#include "rclcpp/detail/traits.hpp"
21#include "rclcpp/logging.hpp"
29#include "rclcpp/duration.hpp"
30#include "rclcpp/time.hpp"
31#include "rclcpp/clock.hpp"
33#include "rclcpp/options.hpp"
49#include "rclcpp/polling_action_server.hpp"
50#include "rclcpp/polling_action_client.hpp"
51#include "rclcpp/polling_client.hpp"
52#include "rclcpp/polling_service.hpp"
53#include "rclcpp/polling_subscription.hpp"
54#include "rclcpp/parameter.hpp"
60#include "rclcpp/node_parameters.hpp"
61#include "rclcpp/tick_ctx.hpp"
62#include "rclcpp_lifecycle/lifecycle_node.hpp"
63#include "rclcpp/rosout.hpp"
73#include "rclcpp/detail/component.hpp"
98 if (!::rclcpp::Node::global_initialized()) {
140 if (executor ==
nullptr) {
159 if (executor ==
nullptr) {
172 if (executor ==
nullptr)
return false;
180 if (executor ==
nullptr)
return false;
193 if (!::rclcpp::Node::global_initialized()) {
213 if (!::rclcpp::Node::global_initialized()) {
260#include <type_traits>
285 return s ==
nullptr ?
false
286 :
"--ros-args"[
i] ==
'\0' ?
s[
i] ==
'\0'
345 verb,
name !=
nullptr ?
name :
"",
static_cast<int>(code));
386 ::rclcpp::detail::apply_ros_args(
nullptr,
argc,
argv) != 0) {
394 ::rclcpp::detail::apply_ros_args(executor,
argc,
argv) != 0) {
418 return ::rclcpp::shutdown_in().ok();
435using ::rclcpp::spin_once;
486 const ::rclcpp::QoS&
qos) {
504#if defined(NROS_CPP_HAS_STD_STRING)
584 const ::rclcpp::QoS& qos) {
585 return this->create_publisher<M>(topic.c_str(), qos);
595 return this->create_publisher<M>(topic.c_str(),
::rclcpp::QoS(
static_cast<uint32_t
>(depth)));
640template <
typename M,
typename Cb>
644 return this->create_subscription<M>(topic.c_str(), qos, ::rclcpp::tr::forward_rvalue(cb));
651template <
typename M,
typename Cb>
653 ::size_t depth, Cb cb) {
654 return this->create_subscription<M>(topic.c_str(), depth, ::rclcpp::tr::forward_rvalue(cb));
696 const ::rclcpp::QoS& qos) {
698 return this->
template create_service<S>(name.c_str(), qos);
705template <
typename S,
typename F,
typename>
706inline typename Service<S>::SharedPtr Node::create_service(const ::std::string& name, F callback,
707 const ::rclcpp::QoS& qos) {
708 return this->
template create_service<S>(name.c_str(), callback, qos);
715template <
typename S,
typename F,
typename,
typename>
716inline typename Service<S>::SharedPtr Node::create_service(const ::std::string&, F,
717 const ::rclcpp::QoS&) {
718 static_assert(::rclcpp::detail::refuse<F>::value,
719 NROS_RCLCPP_REFUSE_SHARED_PTR_SERVICE_CALLBACK);
720 return typename Service<S>::SharedPtr();
728inline ::rclcpp::Owned<::rclcpp::PollClient<S>> Node::create_client(const ::std::string& name,
729 const ::rclcpp::QoS& qos) {
731 return this->
template create_client<S>(name.c_str(), qos);
738template <
typename S,
typename F,
typename>
739inline typename Client<S>::SharedPtr Node::create_client(const ::std::string& name, F callback,
740 const ::rclcpp::QoS& qos) {
741 return this->
template create_client<S>(name.c_str(), callback, qos);
748template <
typename S,
typename F,
typename,
typename>
749inline typename Client<S>::SharedPtr Node::create_client(const ::std::string&, F,
750 const ::rclcpp::QoS&) {
751 static_assert(::rclcpp::detail::refuse<F>::value,
752 NROS_RCLCPP_REFUSE_SHARED_PTR_SERVICE_CALLBACK);
753 return typename Client<S>::SharedPtr();
761#if defined(NROS_CPP_HAS_SHARED_PTR)
811template <
typename N, typename ::rclcpp::tr::enable_if<
812 ::rclcpp::tr::is_convertible<N*, ::rclcpp::Node*>::value,
int>::type = 0>
813inline ::rclcpp::Node&
as_node_ref(const ::std::shared_ptr<N>& n) {
855 if (!
node || !
node->initialized()) {
862 if (!
node || !
node->initialized()) {
885template <
typename Future>
888 if (!
node || !
node->initialized()) {
917#if defined(NROS_CPP_HAS_SHARED_PTR)
926template <
typename N, typename ::rclcpp::tr::enable_if<
927 ::rclcpp::tr::is_convertible<N*, Node*>::value,
int>::type = 0>
928inline void spin(const ::std::shared_ptr<N>& node) {
932template <
typename N, typename ::rclcpp::tr::enable_if<
933 ::rclcpp::tr::is_convertible<N*, Node*>::value,
int>::type = 0>
934inline void spin_some(const ::std::shared_ptr<N>& node) {
939 typename N,
typename Future,
940 typename ::rclcpp::tr::enable_if<::rclcpp::tr::is_convertible<N*, Node*>::value,
int>::type = 0>
942 const Future& future, int32_t timeout_ms = -1) {
958template <
typename M,
typename Cb>
970 ::size_t handle_id = 0;
971 const ::rclcpp::Result
r = ::rclcpp::detail::register_subscription_capturing<M>(
982template <
typename M,
typename Cb>
984 ::size_t depth,
Cb cb) {
986 ::rclcpp::tr::forward_rvalue(
cb));
991 const ::rclcpp::QoS&
qos) {
999 "create_service",
name);
1000 return ::rclcpp::Owned<::rclcpp::PollService<S>>(::rclcpp::tr::forward_rvalue(
s));
1003template <
typename S,
typename F,
typename>
1005 const ::rclcpp::QoS&
qos) {
1013 "create_service",
name);
1017template <
typename S,
typename F,
typename,
typename>
1019 static_assert(::rclcpp::detail::refuse<F>::value,
1024template <
typename S>
1026 const ::rclcpp::QoS&
qos) {
1034 "create_client",
name);
1035 return ::rclcpp::Owned<::rclcpp::PollClient<S>>(::rclcpp::tr::forward_rvalue(
c));
1038template <
typename S,
typename F,
typename>
1040 const ::rclcpp::QoS&
qos) {
1049 "create_client",
name);
1053template <
typename S,
typename F,
typename,
typename>
1055 static_assert(::rclcpp::detail::refuse<F>::value,
1083template <
typename Cb>
1092 const int64_t ns = period.nanoseconds();
1094 size_t handle_id = 0;
1116template <
typename Cb>
1118 return ::rclcpp::detail::register_timer_capturing(
1119 *
this,
RCL_STEADY_TIME, period, ::rclcpp::tr::forward_rvalue(
cb),
"create_wall_timer");
1122#ifdef NROS_CPP_HAS_STD_CHRONO
1123template <
typename Rep,
typename Period,
typename Cb>
1126 const auto ns = ::std::chrono::duration_cast<::std::chrono::nanoseconds>(period).count();
1128 ::rclcpp::tr::forward_rvalue(
cb));
1155template <
typename NodeT,
typename CallbackT>
1160 clock !=
nullptr ? clock->get_clock_type() :
n.get_clock()->get_clock_type();
1161 return ::rclcpp::detail::register_timer_capturing(
1162 n, type, period, ::rclcpp::tr::relay<CallbackT>(
callback),
"create_timer");
1165#ifdef NROS_CPP_HAS_STD_CHRONO
1171template <typename NodeT, typename Rep, typename Period, typename CallbackT>
1173 ::std::chrono::duration<Rep, Period> period,
1174 CallbackT&& callback) {
1175 const auto ns = ::std::chrono::duration_cast<::std::chrono::nanoseconds>(period).count();
1176 return create_timer(::rclcpp::tr::relay<NodeT>(node), clock,
1177 ::rclcpp::Duration::from_nanoseconds(
static_cast<int64_t
>(ns)),
1178 ::rclcpp::tr::relay<CallbackT>(callback));
1247 if (!::rclcpp::detail::node_param_get(
h,
name,
out).
ok()) {
1258 return ::rclcpp::detail::node_param_get(this->
ffi_handle(), name,
out).ok();
1282 return ::rclcpp::detail::node_param_set(this->
ffi_handle(), name, value);
1290 return ::rclcpp::detail::node_param_has(this->
ffi_handle(), name);
1302template <
typename T>
1312 (
void)::rclcpp::detail::node_param_apply_descriptor(
1317template <
typename T>
1319 if (::rclcpp::detail::node_param_get(this->
ffi_handle(), name,
out).
ok()) {
1327 return ::rclcpp::detail::node_param_undeclare(this->
ffi_handle(), name);
1332 if (!::rclcpp::detail::node_param_get_type(this->
ffi_handle(), name, code).
ok()) {
1340 if ((
names ==
nullptr ||
out ==
nullptr) && count != 0) {
1343 for (::size_t
i = 0;
i < count; ++
i) {
1373 if (type == ::rclcpp::param_type::INTEGER) {
1375 ::rclcpp::detail::node_param_get_range(this->
ffi_handle(), name, &
out.integer_from,
1376 &
out.integer_to, &
out.integer_step)
1378 }
else if (type == ::rclcpp::param_type::DOUBLE) {
1380 ::rclcpp::detail::node_param_get_range(this->
ffi_handle(), name, &
out.double_from,
1381 &
out.double_to, &
out.double_step)
1388 ::size_t
max_names, ::size_t& count)
const {
1394 return ::rclcpp::detail::node_params_set_atomically(this->
ffi_handle(), writes, count);
1400 return ::rclcpp::detail::node_param_add_on_set_callback(this->
ffi_handle(), callback, context,
1405 return ::rclcpp::detail::node_param_remove_on_set_callback(this->
ffi_handle(), handle);
1485 if (period_ns_ < 0) period_ns_ = 0;
1489#ifdef NROS_CPP_HAS_STD_CHRONO
1495 template <typename Rep, typename Period>
1496 explicit Rate(std::chrono::duration<Rep, Period> period)
1498 if (period_ns_ < 0) period_ns_ = 0;
1509 if (period_ns_ <= 0) {
1513 if (
now_ns >= next_tick_ns_) {
1527 next_tick_ns_ +=
static_cast<uint64_t>(period_ns_);
Definition client.hpp:129
::rclcpp::ClientHandle< S > SharedPtr
Definition client.hpp:141
size_t handle_id() const
Executor arena slot for the registration; SIZE_MAX until registered.
Definition client.hpp:322
const nros_cpp_node_t * ffi_handle() const
Definition node.hpp:1475
Result get_parameter_types(const char *const *names, ::size_t count, ParameterType *out) const
Definition rclcpp.hpp:1338
::rclcpp::Owned<::rclcpp::PollService< S > > create_service(const char *name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
bool get_parameter(const char *name, T &out) const
Definition rclcpp.hpp:1257
typename::rclcpp::Subscription< M >::SharedPtr create_subscription(const char *topic, const ::rclcpp::QoS &qos, Cb cb)
typename::rclcpp::Publisher< M >::SharedPtr create_publisher(const char *topic, const ::rclcpp::QoS &qos=::rclcpp::QoS::default_profile())
create_publisher<M>(topic, qos) — available on every target.
::rclcpp::TimerHandle create_wall_timer(::rclcpp::Duration period, Cb cb)
bool check_declared_param(const char *name, int passed_type)
Definition node.hpp:2425
Result describe_parameter(const char *name, ParameterDescriptor &out, char *text, ::size_t text_len) const
Definition rclcpp.hpp:1349
T declare_parameter(const char *name, T default_value=T())
rclcpp::Node::declare_parameter<T>(name, default).
Definition rclcpp.hpp:1234
bool get_parameter_or(const char *name, T &out, T fallback) const
Definition rclcpp.hpp:1318
ParameterType get_parameter_type(const char *name) const
Definition rclcpp.hpp:1330
bool ok() const
Definition node.hpp:819
bool has_parameter(const char *name) const
rclcpp::Node::has_parameter(name).
Definition rclcpp.hpp:1289
void * executor_handle() const
Definition node.hpp:1499
Result list_parameters(const char *prefix, char *out_names, ::size_t name_stride, ::size_t max_names, ::size_t &count) const
Definition rclcpp.hpp:1387
::rclcpp::Handle< Node > SharedPtr
Definition node.hpp:903
Result remove_on_set_parameters_callback(ParameterCallbackHandle handle)
rclcpp::Node::remove_on_set_parameters_callback(handle).
Definition rclcpp.hpp:1404
Result set_parameters_atomically(const ParameterWrite *writes, ::size_t count)
Definition rclcpp.hpp:1393
::rclcpp::Owned<::rclcpp::PollClient< S > > create_client(const char *name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
Result set_parameter(const char *name, T value)
Definition rclcpp.hpp:1281
Result undeclare_parameter(const char *name)
Definition rclcpp.hpp:1326
Result add_on_set_parameters_callback(OnSetParametersCallbackType callback, void *context, ParameterCallbackHandle &out_handle)
Definition rclcpp.hpp:1397
Definition executor.hpp:88
Definition executor.hpp:81
::rclcpp::Owned< Publisher< M > > SharedPtr
Definition publisher.hpp:164
Definition rclcpp.hpp:1473
bool sleep()
Definition rclcpp.hpp:1508
Rate(::rclcpp::Duration period)
Definition rclcpp.hpp:1484
Rate(double frequency_hz)
Definition rclcpp.hpp:1477
void reset()
rclcpp::Rate::reset() — anchor the next tick one period from now.
Definition rclcpp.hpp:1534
::rclcpp::Duration period() const
Definition rclcpp.hpp:1542
Definition result.hpp:216
static constexpr ResultOf success()
Named constructors.
Definition result.hpp:238
::rclcpp::ServiceHandle< S > SharedPtr
Definition service.hpp:130
nros_cpp_shutdown_callback_handle_t value() const
The raw FFI value, for passing to the C entry points directly.
Definition executor.hpp:67
::rclcpp::SubscriptionHandle< M > SharedPtr
Definition subscription.hpp:219
rclcpp::Future<T> — single-shot deferred result.
int nros_cpp_ret_t
Definition future.hpp:21
nros_cpp_ret_t nros_cpp_spin_once(void *handle, int32_t timeout_ms)
uint64_t nros_cpp_time_ns(void)
TimerHandle register_timer_capturing(::rclcpp::Node &node, rcl_clock_type_t clock_type, Duration period, Cb &&cb, const char *verb)
Definition rclcpp.hpp:1084
void abort_failed_create(const char *verb, const char *name, int32_t code)
Definition rclcpp.hpp:337
void require_created(::rclcpp::Result r, const char *verb, const char *name)
Definition rclcpp.hpp:352
constexpr bool is_ros_args_flag(char const *s, int i=0)
Definition rclcpp.hpp:284
inline ::rclcpp::Node & as_node_ref(const ::rclcpp::Node::SharedPtr &n)
Definition rclcpp.hpp:1137
constexpr bool argv_has_ros_args(int argc, char const *const *argv, int i=0)
Definition rclcpp.hpp:291
void spin(const Node::SharedPtr &node)
Definition rclcpp.hpp:854
inline ::rclcpp::TimerHandle create_timer(NodeT &&node, ::rclcpp::Clock *clock, ::rclcpp::Duration period, CallbackT &&callback)
Definition rclcpp.hpp:1156
void spin_some(const Node::SharedPtr &node)
Definition rclcpp.hpp:861
FutureReturnCode spin_until_future_complete(const Node::SharedPtr &node, const Future &future, int32_t timeout_ms=-1)
Definition rclcpp.hpp:886
Result init_in(const char *locator=nullptr, uint8_t domain_id=0)
Definition node.hpp:2785
ResultOf< void > Result
Definition result.hpp:246
Result spin_once(int32_t timeout_ms=10)
Definition rclcpp.hpp:97
FutureReturnCode
Definition rclcpp.hpp:447
@ TIMEOUT
The deadline passed with the future still pending.
@ INTERRUPTED
rclcpp::ok() went false (shutdown) before the future was ready.
void init()
rclcpp::init() — the zero-argument form. ADOPT.
Definition rclcpp.hpp:400
bool remove_on_shutdown_callback(OnShutdownCallbackHandle handle)
Definition rclcpp.hpp:178
bool ok()
Definition node.hpp:3031
Result spin_in()
Definition rclcpp.hpp:192
void * global_handle()
Definition node.hpp:2954
Result on_shutdown(ShutdownCallback callback, void *context=nullptr, OnShutdownCallbackHandle *out=nullptr)
Definition rclcpp.hpp:156
bool shutdown()
Definition rclcpp.hpp:417
bool remove_pre_shutdown_callback(PreShutdownCallbackHandle handle)
Definition rclcpp.hpp:170
void arm_monitors()
Definition rclcpp.hpp:113
Result pre_shutdown(ShutdownCallback callback, void *context=nullptr, PreShutdownCallbackHandle *out=nullptr)
Definition rclcpp.hpp:137
rclcpp::Node and global session helpers.
rclcpp::Publisher<M> — typed topic publisher.
rclcpp::QoS — full DDS-shaped QoS settings (Phase 108.B.7).
rclcpp::Client<S> — the arena-registered (callback-style) service client, and Client<S>::SharedPtr = ...
rclcpp::Result, rclcpp::ErrorCode, and the RCLCPP_TRY macro.
rclcpp::Service<S> — the arena-registered (callback-style) service server, and Service<S>::SharedPtr ...
rclcpp::Stream<T> — multi-shot message receiver.
rclcpp::Subscription<M> — the typed DISPATCH subscriber: the arena owns it and the executor calls you...