Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ipm with rclcpp serialized messages #1931

Open
wants to merge 32 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
636e076
added rclcpp::SerializedMessage support to IPM
May 12, 2022
33cb9dc
* publish std::unique_ptr<rclcpp::SerializedMessage> support with ipm
May 12, 2022
1f1f28f
updated publisher/subcription factories
May 12, 2022
18c9259
updated tests
May 12, 2022
2a28f60
updated tests
May 13, 2022
bb09e50
added ipm for generic_subscription
May 13, 2022
4a34d97
renamed to SplitSubscriptionsIndices and changed datatype to unsigned
May 17, 2022
c8fd558
updated comments
May 17, 2022
4cbc678
using const modifier
May 17, 2022
9b5fd63
Update rclcpp/include/rclcpp/experimental/subscription_intra_process_…
DensoADAS Jun 20, 2022
9e16b43
Update rclcpp/include/rclcpp/experimental/subscription_intra_process_…
DensoADAS Jun 20, 2022
de29d0e
renamed to Indices
Jun 20, 2022
795a281
fixed comment
Jun 20, 2022
ea9245e
added comment block
Jun 20, 2022
f45d12b
added failure case at top
Jun 20, 2022
b4236b3
enabled qos override
Jun 20, 2022
7880677
fix double return
Jun 22, 2022
158ab2c
removed specialization of GenericSubscription
Jun 22, 2022
098b6dd
splitted deserialization and message forwarding
Jun 23, 2022
048c458
using instead of typedef
Jun 23, 2022
667d8d2
fixed intra process publish of serialized message
Jul 7, 2022
c9b148b
throwing error when subscription callback uses rclcpp::SerializedMess…
Jul 7, 2022
c2501cf
updated test to ipm issue
Jul 7, 2022
e98c158
added additional methods for create_generic_subscription
Jul 7, 2022
245c868
fixed duplicated messages for ipm and serialized messages
Aug 1, 2022
3978f2a
added unit test for generic publisher/subscriber with intraprocess co…
Aug 3, 2022
16fc15f
fixes due to rebase
May 8, 2023
280e7be
updated to rolling
May 22, 2023
9d37234
updated SubscriptionTopicStatistics to current master
Nov 6, 2023
2115b26
added test_intra_process_subscriber to test serialized communication …
Dec 11, 2023
4f6e466
extended test for shared callback to cover more use cases
Dec 11, 2023
a8e279c
added test for SubscriptionIntraProcess with unique subscriber
Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rclcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ set(${PROJECT_NAME}_SRCS
src/rclcpp/experimental/timers_manager.cpp
src/rclcpp/future_return_code.cpp
src/rclcpp/generic_publisher.cpp
src/rclcpp/generic_subscription.cpp
src/rclcpp/graph_listener.cpp
src/rclcpp/guard_condition.cpp
src/rclcpp/init_options.cpp
Expand Down
54 changes: 46 additions & 8 deletions rclcpp/include/rclcpp/create_generic_subscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace rclcpp
*
* \param topics_interface NodeTopicsInterface pointer used in parts of the setup.
* \param topic_name Topic name
* \param topic_type Topic type
* \param type_support_handle Topic type support
* \param qos %QoS settings
* \param callback Callback for new messages of serialized form
* \param options %Publisher options.
Expand All @@ -51,18 +51,18 @@ template<
std::shared_ptr<GenericSubscription> create_generic_subscription(
rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr topics_interface,
const std::string & topic_name,
const std::string & topic_type,
const rosidl_message_type_support_t & type_support_handle,
const rclcpp::QoS & qos,
CallbackT && callback,
const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT> & options = (
rclcpp::SubscriptionOptionsWithAllocator<AllocatorT>()
)
)
{
auto ts_lib = rclcpp::get_typesupport_library(
topic_type, "rosidl_typesupport_cpp");

auto allocator = options.get_allocator();
typename GenericSubscription::MessageMemoryStrategyType::SharedPtr msg_mem_strat = (
GenericSubscription::MessageMemoryStrategyType::create_default()
);

using rclcpp::AnySubscriptionCallback;
AnySubscriptionCallback<rclcpp::SerializedMessage, AllocatorT>
Expand All @@ -71,18 +71,56 @@ std::shared_ptr<GenericSubscription> create_generic_subscription(

auto subscription = std::make_shared<GenericSubscription>(
topics_interface->get_node_base_interface(),
std::move(ts_lib),
type_support_handle,
topic_name,
topic_type,
qos,
any_subscription_callback,
options);
options,
msg_mem_strat);

topics_interface->add_subscription(subscription, options.callback_group);

return subscription;
}

/// Create and return a GenericSubscription.
/**
* The returned pointer will never be empty, but this function can throw various exceptions, for
* instance when the message's package can not be found on the AMENT_PREFIX_PATH.
*
* \param topics_interface NodeTopicsInterface pointer used in parts of the setup.
* \param topic_name Topic name
* \param topic_type Topic type
* \param qos %QoS settings
* \param callback Callback for new messages of serialized form
* \param options %Publisher options.
* Not all publisher options are currently respected, the only relevant options for this
* publisher are `event_callbacks`, `use_default_callbacks`, and `%callback_group`.
*/
template<
typename CallbackT,
typename AllocatorT = std::allocator<void>>
std::shared_ptr<GenericSubscription> create_generic_subscription(
rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr topics_interface,
const std::string & topic_name,
const std::string & topic_type,
const rclcpp::QoS & qos,
CallbackT && callback,
const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT> & options = (
rclcpp::SubscriptionOptionsWithAllocator<AllocatorT>()
)
)
{
auto ts_lib = rclcpp::get_typesupport_library(
topic_type, "rosidl_typesupport_cpp");

return create_generic_subscription<CallbackT, AllocatorT>(
topics_interface, topic_name,
*rclcpp::get_typesupport_handle(topic_type, "rosidl_typesupport_cpp", *ts_lib),
qos, std::forward<CallbackT>(callback), options
);
}

} // namespace rclcpp

#endif // RCLCPP__CREATE_GENERIC_SUBSCRIPTION_HPP_
47 changes: 47 additions & 0 deletions rclcpp/include/rclcpp/create_publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,53 @@ namespace rclcpp

namespace detail
{
/// Create and return a publisher of the given MessageT type.
/**
* The NodeT type only needs to have a method called get_node_topics_interface()
* which returns a shared_ptr to a NodeTopicsInterface.
*/
template<
typename MessageT = SerializedMessage,
typename AllocatorT = std::allocator<void>,
typename PublisherT = rclcpp::Publisher<MessageT, AllocatorT>,
typename NodeT>
std::shared_ptr<PublisherT>
create_publisher(
NodeT & node,
const std::string & topic_name,
const rosidl_message_type_support_t & type_support,
const rclcpp::QoS & qos,
const rclcpp::PublisherOptionsWithAllocator<AllocatorT> & options = (
rclcpp::PublisherOptionsWithAllocator<AllocatorT>()
)
)
{
// Extract the NodeTopicsInterface from the NodeT.
using rclcpp::node_interfaces::get_node_topics_interface;
auto node_topics_interface = get_node_topics_interface(node);
auto node_parameters = node.get_node_parameters_interface();
const rclcpp::QoS & actual_qos = options.qos_overriding_options.get_policy_kinds().size() ?
rclcpp::detail::declare_qos_parameters(
options.qos_overriding_options, node_parameters,
node_topics_interface->resolve_topic_name(topic_name),
qos, rclcpp::detail::PublisherQosParametersTraits{}) :
qos;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to support the QoS overrides feature here too, via the parameters interface. Is there a reason this was omitted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, done

// Create the publisher.
auto pub = node_topics_interface->create_publisher(
topic_name,
rclcpp::create_publisher_factory<AllocatorT, PublisherT>(
options,
type_support),
actual_qos
);

// Add the publisher to the node topics interface.
node_topics_interface->add_publisher(pub, options.callback_group);

return std::dynamic_pointer_cast<PublisherT>(pub);
}

/// Create and return a publisher of the given MessageT type.
template<
typename MessageT,
Expand Down
Loading