Conversation
Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
f6173ae to
9d79427
Compare
ralph-lange
left a comment
There was a problem hiding this comment.
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.
You may want to update the copyright information, at least with the year 2021.
There was a problem hiding this comment.
| // 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.
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.
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.
See my above comment about leaving the loop by a return.
| 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.
| 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.
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.
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.
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. |
fujitatomoya
left a comment
There was a problem hiding this comment.
@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.
| // 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.
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.
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.