-
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
Merged
yuki-takagi-66
merged 11 commits into
autowarefoundation:main
from
tier4:feat/disable_recieve_callback
Apr 3, 2024
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5758493
prototype
yuki-takagi-66 8d24fbc
move to tier4/autoware_utils
yuki-takagi-66 4c569d9
remove unused change
yuki-takagi-66 bcdf07c
fix spell
yuki-takagi-66 8659816
change while to if
yuki-takagi-66 8fa1e84
reflect the review comments
yuki-takagi-66 6cbc75f
upadate
yuki-takagi-66 293191e
update
yuki-takagi-66 3c7bdef
change to return raw T instead of optional<T>
yuki-takagi-66 fe39cc6
add underbar
yuki-takagi-66 d38ec7f
add include
yuki-takagi-66 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
common/tier4_autoware_utils/include/tier4_autoware_utils/ros/polling_subscriber.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 T & getData() const | ||
{ | ||
if (!data.has_value()) { | ||
throw std::runtime_error("Bad_optional_access in class InterProcessPollingSubscriber"); | ||
} | ||
return data.value(); | ||
}; | ||
}; | ||
|
||
} // namespace tier4_autoware_utils | ||
|
||
#endif // TIER4_AUTOWARE_UTILS__ROS__POLLING_SUBSCRIBER_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.