-
Notifications
You must be signed in to change notification settings - Fork 316
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
Update services examples #317
base: rolling
Are you sure you want to change the base?
Conversation
Signed-off-by: Alfi Maulana <[email protected]>
Signed-off-by: Alfi Maulana <[email protected]>
Signed-off-by: Alfi Maulana <[email protected]>
Signed-off-by: Alfi Maulana <[email protected]>
Signed-off-by: Alfi Maulana <[email protected]>
f6173ae
to
9d79427
Compare
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.
Thank you for improving and extending the ROS 2 examples. I deem this to be important work!
I found an issue in case that the client node is canceled/stopped (e.g., by ctrl+c) while waiting for the service.
@@ -0,0 +1,67 @@ | |||
// Copyright 2016 Open Source Robotics Foundation, Inc. |
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.
You may want to update the copyright information, at least with the year 2021.
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.
// Copyright 2016 Open Source Robotics Foundation, Inc. | |
// Copyright 2024 Open Source Robotics Foundation, Inc. |
Happy new year 🆕 can be applied to other new files.
client_ = this->create_client<AddTwoInts>("add_two_ints"); | ||
while (!client_->wait_for_service(1s)) { | ||
if (!rclcpp::ok()) { | ||
RCLCPP_ERROR(this->get_logger(), "client interrupted while waiting for service to appear."); |
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 prevent an infinite loop, add return
(which is valid in a ctor) to leave the loop, cf. the return 1;
in not_composable.cpp
. However, note that the spin(node)
in the main function must not be called if rclcpp::ok()
is already false since this will cause an the given context is not valid
error. Probably it is better to move the waiting for the service into a one-shot timer as in the examples_rclcpp_minimal_action_client
example.
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 think @threeal tries to keep the current behavior here, i am okay with current behavior for this example so that user does not need to issue service 1st.
client_ = this->create_client<AddTwoInts>("add_two_ints"); | ||
while (!client_->wait_for_service(1s)) { | ||
if (!rclcpp::ok()) { | ||
RCLCPP_ERROR(this->get_logger(), "client interrupted while waiting for service to appear."); |
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.
See my above comment about leaving the loop by a return
.
|
||
int main(int argc, char * argv[]) | ||
{ | ||
rclcpp::init(argc, argv); | ||
auto node = rclcpp::Node::make_shared("minimal_client"); | ||
auto client = node->create_client<AddTwoInts>("add_two_ints"); | ||
while (!client->wait_for_service(std::chrono::seconds(1))) { | ||
while (!client->wait_for_service(1s)) { | ||
if (!rclcpp::ok()) { | ||
RCLCPP_ERROR(node->get_logger(), "client interrupted while waiting for service to appear."); |
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.
RCLCPP_ERROR(node->get_logger(), "client interrupted while waiting for service to appear."); | |
RCLCPP_ERROR(rclcpp::get_logger("rclcpp"), "client interrupted while waiting for service to appear."); |
With the node's logger, the publisher for rosout will occasionally raise a publisher's context is invalid
exception on this line.
client_ = this->create_client<AddTwoInts>("add_two_ints"); | ||
while (!client_->wait_for_service(1s)) { | ||
if (!rclcpp::ok()) { | ||
RCLCPP_ERROR(this->get_logger(), "client interrupted while waiting for service to appear."); |
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.
Once the return
issue is solved, it is probably also necessary to change the logger to rclcpp::get_logger("rclcpp")
as in not_composable.cpp
.
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.
Why? this log is not obviously for rclcpp
? so getting logger from this
(Node) is fine? (saying current code looks fine.)
client_ = this->create_client<AddTwoInts>("add_two_ints"); | ||
while (!client_->wait_for_service(1s)) { | ||
if (!rclcpp::ok()) { | ||
RCLCPP_ERROR(this->get_logger(), "client interrupted while waiting for service to appear."); |
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.
Once the return
issue is solved, it is probably also necessary to change the logger to rclcpp::get_logger("rclcpp")
as in not_composable.cpp
.
@threeal this's been 3 years. still working on this? if you are, could you please rebase this? |
I'm sorry, i almost forgot i have this PR, i'll try to work on this when i have time. |
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.
@threeal a couple of comments. thank you for the contribution.
@@ -0,0 +1,67 @@ | |||
// Copyright 2016 Open Source Robotics Foundation, Inc. |
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.
// Copyright 2016 Open Source Robotics Foundation, Inc. | |
// Copyright 2024 Open Source Robotics Foundation, Inc. |
Happy new year 🆕 can be applied to other new files.
client_ = this->create_client<AddTwoInts>("add_two_ints"); | ||
while (!client_->wait_for_service(1s)) { | ||
if (!rclcpp::ok()) { | ||
RCLCPP_ERROR(this->get_logger(), "client interrupted while waiting for service to appear."); |
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 think @threeal tries to keep the current behavior here, i am okay with current behavior for this example so that user does not need to issue service 1st.
client_ = this->create_client<AddTwoInts>("add_two_ints"); | ||
while (!client_->wait_for_service(1s)) { | ||
if (!rclcpp::ok()) { | ||
RCLCPP_ERROR(this->get_logger(), "client interrupted while waiting for service to appear."); |
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.
Why? this log is not obviously for rclcpp
? so getting logger from this
(Node) is fine? (saying current code looks fine.)
Separate rclcpp's minimal client and minimal service examples each into lambda, member function, and not composable.