-
Notifications
You must be signed in to change notification settings - Fork 665
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
feat(tier4_autoware_utils, obstacle_cruise): change to read topic by polling #6702
Changes from 8 commits
5758493
8d24fbc
4c569d9
bcdf07c
8659816
8fa1e84
6cbc75f
293191e
3c7bdef
fe39cc6
d38ec7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef TIER4_AUTOWARE_UTILS__ROS__POLLING_SUBSCRIBER_HPP_ | ||
#define TIER4_AUTOWARE_UTILS__ROS__POLLING_SUBSCRIBER_HPP_ | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
|
||
namespace tier4_autoware_utils | ||
{ | ||
|
||
template <typename T> | ||
class InterProcessPollingSubscriber | ||
{ | ||
private: | ||
typename rclcpp::Subscription<T>::SharedPtr subscriber; | ||
std::optional<T> data; | ||
|
||
public: | ||
explicit InterProcessPollingSubscriber(rclcpp::Node * node, const std::string & topic_name) | ||
{ | ||
auto noexec_callback_group = | ||
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive, false); | ||
auto noexec_subscription_options = rclcpp::SubscriptionOptions(); | ||
noexec_subscription_options.callback_group = noexec_callback_group; | ||
|
||
subscriber = node->create_subscription<T>( | ||
topic_name, rclcpp::QoS{1}, [node](const typename T::ConstSharedPtr msg) { assert(false); }, | ||
yuki-takagi-66 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
noexec_subscription_options); | ||
}; | ||
bool updateLatestData() | ||
{ | ||
rclcpp::MessageInfo message_info; | ||
T tmp; | ||
// The queue size (QoS) must be 1 to get the last message data. | ||
if (subscriber->take(tmp, message_info)) { | ||
data = tmp; | ||
} | ||
return data.has_value(); | ||
}; | ||
const std::optional<T> & getData() const { return data; }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to add & here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, if we do not check whether the optional is not nullopt or not on the node side, it may be better to return T instead of std::optional. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
While I'm not familiar with the |
||
}; | ||
|
||
} // namespace tier4_autoware_utils | ||
|
||
#endif // TIER4_AUTOWARE_UTILS__ROS__POLLING_SUBSCRIBER_HPP_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuki-takagi-66
I am wondering if another wrapper class is created for a different use.
InterProcessPollingSubscriber
is wrapper class that wraps a subscriber whose queue size is 1.On the other hand, if another developer wants to use a subscriber whose queue size is multiple, does he have to create another class.
This comment may seem that I disagree with using use the wrapper function, but I don't disagree.
I want to align understanding because it will be used commonly.