|
56 | 56 |
|
57 | 57 | static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.plugins.ros_control_interface");
|
58 | 58 | static const rclcpp::Duration CONTROLLER_INFORMATION_VALIDITY_AGE = rclcpp::Duration::from_seconds(1.0);
|
59 |
| -// TODO: Create a ROS parameter allowing to customize this default timeout |
60 |
| -static constexpr double SERVICE_CALL_TIMEOUT = 3.0; |
61 | 59 |
|
62 | 60 | namespace moveit_ros_control_interface
|
63 | 61 | {
|
| 62 | +static constexpr double DEFAULT_SERVICE_CALL_TIMEOUT = 3.0; |
| 63 | + |
64 | 64 | /**
|
65 | 65 | * \brief Get joint name from resource name reported by ros2_control, since claimed_interfaces return by ros2_control
|
66 | 66 | * will have the interface name as suffix joint_name/INTERFACE_TYPE
|
@@ -124,6 +124,7 @@ MOVEIT_CLASS_FORWARD(Ros2ControlManager); // Defines Ros2ControlManagerPtr, Con
|
124 | 124 | class Ros2ControlManager : public moveit_controller_manager::MoveItControllerManager
|
125 | 125 | {
|
126 | 126 | std::string ns_;
|
| 127 | + std::chrono::duration<double> service_call_timeout_; |
127 | 128 | pluginlib::ClassLoader<ControllerHandleAllocator> loader_;
|
128 | 129 | typedef std::map<std::string, controller_manager_msgs::msg::ControllerState> ControllersMap;
|
129 | 130 |
|
@@ -181,10 +182,10 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan
|
181 | 182 |
|
182 | 183 | auto request = std::make_shared<controller_manager_msgs::srv::ListControllers::Request>();
|
183 | 184 | auto result_future = list_controllers_service_->async_send_request(request);
|
184 |
| - if (result_future.wait_for(std::chrono::duration<double>(SERVICE_CALL_TIMEOUT)) == std::future_status::timeout) |
| 185 | + if (result_future.wait_for(service_call_timeout_) == std::future_status::timeout) |
185 | 186 | {
|
186 | 187 | RCLCPP_WARN_STREAM(LOGGER, "Failed to read controllers from " << list_controllers_service_->get_service_name()
|
187 |
| - << " within " << SERVICE_CALL_TIMEOUT |
| 188 | + << " within " << service_call_timeout_.count() |
188 | 189 | << " seconds");
|
189 | 190 | return;
|
190 | 191 | }
|
@@ -307,6 +308,20 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan
|
307 | 308 | }
|
308 | 309 | }
|
309 | 310 |
|
| 311 | + double timeout_seconds; |
| 312 | + if (!node_->has_parameter("controller_service_call_timeout")) |
| 313 | + { |
| 314 | + timeout_seconds = |
| 315 | + node_->declare_parameter<double>("controller_service_call_timeout", DEFAULT_SERVICE_CALL_TIMEOUT); |
| 316 | + } |
| 317 | + else |
| 318 | + { |
| 319 | + node_->get_parameter("controller_service_call_timeout", timeout_seconds); |
| 320 | + } |
| 321 | + service_call_timeout_ = std::chrono::duration<double>(timeout_seconds); |
| 322 | + |
| 323 | + RCLCPP_INFO_STREAM(LOGGER, "Using service call timeout " << service_call_timeout_.count() << " seconds"); |
| 324 | + |
310 | 325 | list_controllers_service_ = node_->create_client<controller_manager_msgs::srv::ListControllers>(
|
311 | 326 | getAbsName("controller_manager/list_controllers"));
|
312 | 327 | switch_controller_service_ = node_->create_client<controller_manager_msgs::srv::SwitchController>(
|
@@ -523,10 +538,10 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan
|
523 | 538 | if (!request->activate_controllers.empty() || !request->deactivate_controllers.empty())
|
524 | 539 | { // something to switch?
|
525 | 540 | auto result_future = switch_controller_service_->async_send_request(request);
|
526 |
| - if (result_future.wait_for(std::chrono::duration<double>(SERVICE_CALL_TIMEOUT)) == std::future_status::timeout) |
| 541 | + if (result_future.wait_for(service_call_timeout_) == std::future_status::timeout) |
527 | 542 | {
|
528 | 543 | RCLCPP_ERROR_STREAM(LOGGER, "Couldn't switch controllers at " << switch_controller_service_->get_service_name()
|
529 |
| - << " within " << SERVICE_CALL_TIMEOUT |
| 544 | + << " within " << service_call_timeout_.count() |
530 | 545 | << " seconds");
|
531 | 546 | return false;
|
532 | 547 | }
|
|
0 commit comments