Skip to content
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

ParameterClient request is not finished although executor is canceled. #1022

Open
DongheeYe opened this issue Mar 11, 2020 · 0 comments
Open
Assignees

Comments

@DongheeYe
Copy link
Contributor

Bug report

Required Info:

  • Operating System:
    • Ubuntu 18.04
  • Installation type:
    • from source
  • Version or commit hash:
    • dashing, master
  • DDS implementation:
    • Fast-RTPS
  • Client library (if applicable):
    • rclcpp

Steps to reproduce issue

Parameter Server code

#include <chrono>
#include <iostream>
#include <memory>
#include <vector>

#include <rclcpp/rclcpp.hpp>

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);

  rclcpp::executors::SingleThreadedExecutor executor;
  auto node = std::make_shared<rclcpp::Node>("param_test_server_node");
  auto test_param = "test_param";

  rcl_interfaces::msg::ParameterDescriptor descriptor;
  descriptor.read_only = false;
  node->declare_parameter(test_param, rclcpp::ParameterValue(10), descriptor);

  executor.add_node(node);

  node->set_on_parameters_set_callback([&](const std::vector<rclcpp::Parameter> & parameters) {
        rcl_interfaces::msg::SetParametersResult result;
        std::cout << "set_parameter callback is called" << std::endl;
        result.successful = true;
        for (const auto & parameter : parameters) {
          if (parameter.get_name() == test_param)
          {
            std::cout << test_param << " " << parameter.value_to_string() << std::endl;
          }
        }
        std::this_thread::sleep_for(std::chrono::seconds(100));   // To reproduce the issue
        return result;
      });

  executor.spin();

  rclcpp::shutdown();

  return 0;
}

Parameter Client code

#include <chrono>
#include <iostream>
#include <memory>
#include <vector>

#include <rclcpp/rclcpp.hpp>

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);

  auto remote_node = "/param_test_server_node";
  auto test_param = "test_param";

  auto exec = std::make_shared<rclcpp::executors::SingleThreadedExecutor>() ;
  auto node = std::make_shared<rclcpp::Node>("param_test_client");

  std::this_thread::sleep_for(std::chrono::seconds(1));

  auto parameters_client =
      std::make_shared<rclcpp::SyncParametersClient>(exec, node, remote_node);

  while (!parameters_client->wait_for_service(std::chrono::seconds(1))) {
    if (!rclcpp::ok()) {
      RCLCPP_ERROR(node->get_logger(), "interrupted, exit!");
      rclcpp::shutdown();
      return 0;
    }
    RCLCPP_INFO(node->get_logger(), "wait for service");
  }

  auto timer_callback = [&]() -> void {
      RCLCPP_INFO(node->get_logger(), "Timer expired");
      exec->cancel();
    };
  auto timer = node->create_wall_timer(std::chrono::seconds(5), timer_callback);

  std::vector<rclcpp::Parameter> set_params;
  set_params.emplace_back(test_param, 50);
  auto results = parameters_client->set_parameters(set_params);
  for (auto &result : results)
    RCLCPP_INFO(node->get_logger(), "result: %d", result.successful);
  RCLCPP_INFO(node->get_logger(), "done");
  timer->cancel();

  rclcpp::shutdown();

  return 0;
}

Expected behavior

Although set_parameters is not finished successfully, if executor is canceled then set_parameters must be finished.

set_parameter callback is called
test_param 50
[INFO] [1583914754.708738050] [param_test_client]: Timer expired
[INFO] [1583914754.709483787] [param_test_client]: done

Actual behavior

set_parameters does not finished although executor is cancled.

set_parameter callback is called
test_param 50
[INFO] [1583914837.349401253] [param_test_client]: Timer expired
[INFO] [1583914842.349311295] [param_test_client]: Timer expired
DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this issue Aug 5, 2022
style: fix diff

style: remove additional spaces

style: typo

fix: added missing input parameter

refactor: make variable private

refactor: fix linting error

fix: Add missing initialization

style: linter

refactor: invert logic

Signed-off-by: Kaju Bubanja <bubanja.kaju@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants