|
57 | 57 | #include <moveit/utils/logger.hpp> |
58 | 58 |
|
59 | 59 | static const rclcpp::Duration CONTROLLER_INFORMATION_VALIDITY_AGE = rclcpp::Duration::from_seconds(1.0); |
60 | | -// TODO: Create a ROS parameter allowing to customize this default timeout |
61 | | -static constexpr double SERVICE_CALL_TIMEOUT = 3.0; |
62 | 60 |
|
63 | 61 | namespace moveit_ros_control_interface |
64 | 62 | { |
| 63 | +static constexpr double DEFAULT_SERVICE_CALL_TIMEOUT = 3.0; |
| 64 | + |
65 | 65 | namespace |
66 | 66 | { |
67 | 67 | rclcpp::Logger getLogger() |
@@ -133,6 +133,7 @@ MOVEIT_CLASS_FORWARD(Ros2ControlManager); // Defines Ros2ControlManagerPtr, Con |
133 | 133 | class Ros2ControlManager : public moveit_controller_manager::MoveItControllerManager |
134 | 134 | { |
135 | 135 | std::string ns_; |
| 136 | + std::chrono::duration<double> service_call_timeout_; |
136 | 137 | pluginlib::ClassLoader<ControllerHandleAllocator> loader_; |
137 | 138 | typedef std::map<std::string, controller_manager_msgs::msg::ControllerState> ControllersMap; |
138 | 139 |
|
@@ -192,11 +193,11 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan |
192 | 193 |
|
193 | 194 | auto request = std::make_shared<controller_manager_msgs::srv::ListControllers::Request>(); |
194 | 195 | auto result_future = list_controllers_service_->async_send_request(request); |
195 | | - if (result_future.wait_for(std::chrono::duration<double>(SERVICE_CALL_TIMEOUT)) == std::future_status::timeout) |
| 196 | + if (result_future.wait_for(service_call_timeout_) == std::future_status::timeout) |
196 | 197 | { |
197 | 198 | RCLCPP_WARN_STREAM(getLogger(), "Failed to read controllers from " |
198 | 199 | << list_controllers_service_->get_service_name() << " within " |
199 | | - << SERVICE_CALL_TIMEOUT << " seconds"); |
| 200 | + << service_call_timeout_.count() << " seconds"); |
200 | 201 | return; |
201 | 202 | } |
202 | 203 |
|
@@ -318,6 +319,20 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan |
318 | 319 | } |
319 | 320 | } |
320 | 321 |
|
| 322 | + double timeout_seconds; |
| 323 | + if (!node_->has_parameter("controller_service_call_timeout")) |
| 324 | + { |
| 325 | + timeout_seconds = |
| 326 | + node_->declare_parameter<double>("controller_service_call_timeout", DEFAULT_SERVICE_CALL_TIMEOUT); |
| 327 | + } |
| 328 | + else |
| 329 | + { |
| 330 | + node_->get_parameter("controller_service_call_timeout", timeout_seconds); |
| 331 | + } |
| 332 | + service_call_timeout_ = std::chrono::duration<double>(timeout_seconds); |
| 333 | + |
| 334 | + RCLCPP_INFO_STREAM(getLogger(), "Using service call timeout " << service_call_timeout_.count() << " seconds"); |
| 335 | + |
321 | 336 | list_controllers_service_ = node_->create_client<controller_manager_msgs::srv::ListControllers>( |
322 | 337 | getAbsName("controller_manager/list_controllers")); |
323 | 338 | switch_controller_service_ = node_->create_client<controller_manager_msgs::srv::SwitchController>( |
@@ -552,11 +567,11 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan |
552 | 567 | if (!request->activate_controllers.empty() || !request->deactivate_controllers.empty()) |
553 | 568 | { // something to switch? |
554 | 569 | auto result_future = switch_controller_service_->async_send_request(request); |
555 | | - if (result_future.wait_for(std::chrono::duration<double>(SERVICE_CALL_TIMEOUT)) == std::future_status::timeout) |
| 570 | + if (result_future.wait_for(service_call_timeout_) == std::future_status::timeout) |
556 | 571 | { |
557 | 572 | RCLCPP_ERROR_STREAM(getLogger(), "Couldn't switch controllers at " |
558 | 573 | << switch_controller_service_->get_service_name() << " within " |
559 | | - << SERVICE_CALL_TIMEOUT << " seconds"); |
| 574 | + << service_call_timeout_.count() << " seconds"); |
560 | 575 | return false; |
561 | 576 | } |
562 | 577 | discover(true); |
|
0 commit comments