Skip to content

Commit a60ed9f

Browse files
ROS Parameter for service call timeout for ros_control controllers (backport #3419) (#3432)
* ROS Parameter for service call timeout for ros_control controllers (#3419) (cherry picked from commit 64e934f) Co-authored-by: Ashwin Sajith Nambiar <[email protected]>
1 parent 85dd2cf commit a60ed9f

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

moveit_plugins/moveit_ros_control_interface/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ In your MoveIt launch file (e.g. `ROBOT_moveit_config/launch/ROBOT_moveit_contro
2222
<param name="moveit_controller_manager" value="moveit_ros_control_interface::Ros2ControlManager" />
2323
```
2424

25-
And make sure to set the `ros_control_namespace` parameter to the namespace (without the /controller_manager/ part) of the ros_control-based node you like to interface.
26-
If you are using the `moveit_setup_assistent` you can add it to `ROBOT_moveit_config/config/moveit_controllers.yaml`, e.g.:
25+
Make sure to set the `ros_control_namespace` parameter to the namespace (without the /controller_manager/ part) of the ros_control-based node you like to interface.
26+
Also, the timeout in seconds for the service call to the controller can be changed from the default value, by setting the `controller_service_call_timeout` parameter.
27+
If you are using `moveit_setup_assistant`, you can add it to `ROBOT_moveit_config/config/moveit_controllers.yaml`, e.g.:
2728
```
2829
ros_control_namespace: /ROS_CONTROL_NODE
30+
controller_service_call_timeout: 5.0
2931
controller_list:
3032
- name: /ROS_CONTROL_NODE/position_trajectory_controller
3133
action_ns: follow_joint_trajectory

moveit_plugins/moveit_ros_control_interface/src/controller_manager_plugin.cpp

+21-6
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656

5757
static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit.plugins.ros_control_interface");
5858
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;
6159

6260
namespace moveit_ros_control_interface
6361
{
62+
static constexpr double DEFAULT_SERVICE_CALL_TIMEOUT = 3.0;
63+
6464
/**
6565
* \brief Get joint name from resource name reported by ros2_control, since claimed_interfaces return by ros2_control
6666
* will have the interface name as suffix joint_name/INTERFACE_TYPE
@@ -124,6 +124,7 @@ MOVEIT_CLASS_FORWARD(Ros2ControlManager); // Defines Ros2ControlManagerPtr, Con
124124
class Ros2ControlManager : public moveit_controller_manager::MoveItControllerManager
125125
{
126126
std::string ns_;
127+
std::chrono::duration<double> service_call_timeout_;
127128
pluginlib::ClassLoader<ControllerHandleAllocator> loader_;
128129
typedef std::map<std::string, controller_manager_msgs::msg::ControllerState> ControllersMap;
129130

@@ -181,10 +182,10 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan
181182

182183
auto request = std::make_shared<controller_manager_msgs::srv::ListControllers::Request>();
183184
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)
185186
{
186187
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()
188189
<< " seconds");
189190
return;
190191
}
@@ -307,6 +308,20 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan
307308
}
308309
}
309310

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+
310325
list_controllers_service_ = node_->create_client<controller_manager_msgs::srv::ListControllers>(
311326
getAbsName("controller_manager/list_controllers"));
312327
switch_controller_service_ = node_->create_client<controller_manager_msgs::srv::SwitchController>(
@@ -523,10 +538,10 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan
523538
if (!request->activate_controllers.empty() || !request->deactivate_controllers.empty())
524539
{ // something to switch?
525540
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)
527542
{
528543
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()
530545
<< " seconds");
531546
return false;
532547
}

0 commit comments

Comments
 (0)