-
Notifications
You must be signed in to change notification settings - Fork 691
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
feat(tier4_autoware_utils, obstacle_cruise): change to read topic by polling #6702
Conversation
thank you very much for your change! Dedicated callback group is created for each of traj_sub_, objects_sub_, odom_sub_, and acc_sub_ in PR #6702. |
@ohsawa1204 Do you have any ideas to implement? |
rclcpp::MessageInfo message_info; | ||
T tmp; | ||
// "while" is required for the case of Queue size (QoS) is 2 or lager | ||
while (subscriber->take(tmp, message_info)) { |
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.
As Queue size is fixed to '1' above, I think that if (subscriber->take(tmp, message_info))
is less confusing.
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.
typename rclcpp::Subscription<T>::SharedPtr subscriber; | ||
|
||
public: | ||
explicit InterProcessPollingReceiver(rclcpp::Node * node, const std::string & topic_name) |
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.
explict is not required for the two arguments.
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.
Yes. we can remove explicit
.
But explicit makes sense even for multi arguments constructor.
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.
determined to maintain explicit by a book written by Bjarne Stroustrup
noexec_subscription_options); | ||
}; | ||
|
||
void takeLastData(std::optional<T> & data) |
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.
takeLatestData sounds less confusing
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.
In my knowledge, term "last" is preferred in this context.
For example, https://learn.microsoft.com/ja-jp/dotnet/api/system.collections.generic.queue-1?view=net-8.0
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.
For the user of this code, we determine to use the term "latest"
noexec_subscription_options); | ||
}; | ||
|
||
void takeLastData(std::optional<T> & data) |
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.
std::optional<T> takeLatestData()
sounds better. Any reason to add the argument as a reference?
class PollingInputTopics | ||
{ | ||
private: | ||
tier4_autoware_utils::InterProcessPollingReceiver<Odometry> ego_odom_sub_; | ||
tier4_autoware_utils::InterProcessPollingReceiver<PredictedObjects> objects_sub_; | ||
tier4_autoware_utils::InterProcessPollingReceiver<AccelWithCovarianceStamped> acc_sub_; | ||
|
||
public: | ||
PollingInputTopics(rclcpp::Node * node) | ||
: ego_odom_sub_(node, "~/input/odometry"), | ||
objects_sub_(node, "~/input/objects"), | ||
acc_sub_(node, "~/input/acceleration") | ||
{ | ||
} | ||
std::optional<Odometry> ego_odom_opt; | ||
std::optional<PredictedObjects> objects_opt; | ||
std::optional<AccelWithCovarianceStamped> ego_accel_opt; | ||
bool takeData() | ||
{ | ||
ego_odom_sub_.takeLastData(ego_odom_opt); | ||
objects_sub_.takeLastData(objects_opt); | ||
acc_sub_.takeLastData(ego_accel_opt); | ||
|
||
if (!ego_odom_opt.has_value() || !objects_opt.has_value() || !ego_accel_opt.has_value()) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
} polling_topics_{this}; |
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.
The motivation to create a class in tier4_autoware_utils is not to create member variables for the data of each topic on the node side.
We can call ego_odom_sub_.takeLastData
directly in the main callback of the node.
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.
@takayuki5168
I think we should discuss aside
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.
delete this class and change to declare subscriber class on the node class
{ | ||
|
||
template <typename T> | ||
class InterProcessPollingReceiver |
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.
InterProcessPollingReceiver
is hard to understand for me.
InterProcessSubscriber
sounds easy to understand.
@takam5f2 @ohsawa1204 What do you think?
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.
InterProcessPollingReceiver
is hard to understand for me.InterProcessSubscriber
sounds easy to understand.@takam5f2 @ohsawa1204 What do you think?
@takayuki5168
I agree!
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.
OK, I see.
However, InterProcess
denotes less meaning in this context, hence we need some additional modifier term.
How do you think?
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.
To recognize the difference to between the conventional call back subscriber, we use InterProcessPollingSubscriber
as the name of this class
@yuki-takagi-66 |
@ohsawa1204 About unnecessary call back group issue |
3cc8c87
to
0e2a259
Compare
Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
0e2a259
to
293191e
Compare
common/tier4_autoware_utils/include/tier4_autoware_utils/ros/polling_subscriber.hpp
Show resolved
Hide resolved
} | ||
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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to add & here?
While I'm not familiar with the reference
in C++
Maybe & is required to prevent copy.
https://learn.microsoft.com/ja-jp/cpp/cpp/reference-type-function-returns?view=msvc-170
{ | ||
|
||
template <typename T> | ||
class InterProcessPollingSubscriber |
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.
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.
Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6702 +/- ##
==========================================
- Coverage 14.94% 14.90% -0.04%
==========================================
Files 1943 1944 +1
Lines 133953 135017 +1064
Branches 39841 40517 +676
==========================================
+ Hits 20020 20130 +110
- Misses 91656 92483 +827
- Partials 22277 22404 +127
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Sentry. |
c0fcd75
into
autowarefoundation:main
…polling (autowarefoundation#6702) change to read topic by polling Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
…polling (autowarefoundation#6702) (#1224) change to read topic by polling Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
…polling (autowarefoundation#6702) change to read topic by polling Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
…polling (#6702) change to read topic by polling Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
Is there documentation / code comments for understanding the meaning / usage of the Polling Subscriber? |
…polling (autowarefoundation#6702) change to read topic by polling Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
Description
change to read topic by polling instead of best_effort callback
Related links
Tests performed
psim test and tier4 internal tests were performed
If we access to getData() without any call of updatelatestDate() following message will be shown
[component_container_mt-31] terminate called after throwing an instance of 'std::runtime_error'
[component_container_mt-31] what(): Bad_optional_access in class InterProcessPollingSubscriber
[component_container_mt-31] *** Aborted at 1712130709 (unix time) try "date -d @1712130709" if you are using GNU date ***
[component_container_mt-31] PC: @ 0x0 (unknown)
[component_container_mt-31] *** SIGABRT (@0x3e8002983f9) received by PID 2720761 (TID 0x7fe1de7ec640) from PID 2720761; stack trace: ***
[component_container_mt-31] @ 0x7fe1d84b6046 (unknown)
[component_container_mt-31] @ 0x7fe2136fb520 (unknown)
[component_container_mt-31] @ 0x7fe21374f9fc pthread_kill
[component_container_mt-31] @ 0x7fe2136fb476 raise
[component_container_mt-31] @ 0x7fe2136e17f3 abort
[component_container_mt-31] @ 0x7fe2139a3b9e (unknown)
[component_container_mt-31] @ 0x7fe2139af20c (unknown)
[component_container_mt-31] @ 0x7fe2139af277 std::terminate()
[component_container_mt-31] @ 0x7fe2139af4d8 __cxa_throw
[component_container_mt-31] @ 0x7fe20067cf8c _ZNK15motion_planning25ObstacleCruisePlannerNode18convertToObstaclesERKSt6vectorIN27autoware_auto_planning_msgs3msg16TrajectoryPoint_ISaIvEEESaIS6_EE.cold
[component_container_mt-31] @ 0x7fe2006ace54 motion_planning::ObstacleCruisePlannerNode::onTrajectory()
[component_container_mt-31] @ 0x7fe2006d7627 std::_Function_handler<>::_M_invoke()
[component_container_mt-31] @ 0x7fe2006d6462 ZNSt8__detail9__variant17__gen_vtable_implINS0_12_Multi_arrayIPFNS0_21__deduce_visit_resultIvEEOZN6rclcpp23AnySubscriptionCallbackIN27autoware_auto_planning_msgs3msg11Trajectory_ISaIvEEESA_E8dispatchESt10shared_ptrISB_ERKNS5_11MessageInfoEEUlOT_E_RSt7variantIJSt8functionIFvRKSB_EESN_IFvSP_SH_EESN_IFvRKNS5_17SerializedMessageEEESN_IFvSW_SH_EESN_IFvSt10unique_ptrISB_St14default_deleteISB_EEEESN_IFvS14_SH_EESN_IFvS11_ISU_S12_ISU_EEEESN_IFvS1A_SH_EESN_IFvSD_ISO_EEESN_IFvS1F_SH_EESN_IFvSD_ISV_EEESN_IFvS1K_SH_EESN_IFvRKS1F_EESN_IFvS1Q_SH_EESN_IFvRKS1K_EESN_IFvS1W_SH_EESN_IFvSE_EESN_IFvSE_SH_EESN_IFvSD_ISU_EEESN_IFvS25_SH_EEEEEJEEESt16integer_sequenceImJLm8EEEE14__visit_invokeESL_S2B
[component_container_mt-31] @ 0x7fe20075029a rclcpp::Subscription<>::handle_message()
[component_container_mt-31] @ 0x7fe213ccaba0 rclcpp::Executor::execute_subscription()
[component_container_mt-31] @ 0x7fe213ccc10e rclcpp::Executor::execute_any_executable()
[component_container_mt-31] @ 0x7fe213cd2432 rclcpp::executors::MultiThreadedExecutor::run()
[component_container_mt-31] @ 0x7fe2139dd253 (unknown)
[component_container_mt-31] @ 0x7fe21374dac3 (unknown)
[component_container_mt-31] @ 0x7fe2137dfa40 (unknown)
[component_container_mt-31] @ 0x0 (unknown)
Notes for reviewers
Interface changes
Effects on system behavior
Pre-review checklist for the PR author
The PR author must check the checkboxes below when creating the PR.
In-review checklist for the PR reviewers
The PR reviewers must check the checkboxes below before approval.
Post-review checklist for the PR author
The PR author must check the checkboxes below before merging.
After all checkboxes are checked, anyone who has write access can merge the PR.