Skip to content

Commit 5128775

Browse files
ashwinsnambiaranhle5
authored andcommitted
ROS Parameter for service call timeout for ros_control controllers (moveit#3419)
1 parent ac681f5 commit 5128775

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

moveit_plugins/moveit_ros_control_interface/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ In your MoveIt launch file (e.g. `ROBOT_moveit_config/launch/ROBOT_moveit_contro
2323
```
2424

2525
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.
2627
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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@
5757
#include <moveit/utils/logger.hpp>
5858

5959
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;
6260

6361
namespace moveit_ros_control_interface
6462
{
63+
static constexpr double DEFAULT_SERVICE_CALL_TIMEOUT = 3.0;
64+
6565
namespace
6666
{
6767
rclcpp::Logger getLogger()
@@ -133,6 +133,7 @@ MOVEIT_CLASS_FORWARD(Ros2ControlManager); // Defines Ros2ControlManagerPtr, Con
133133
class Ros2ControlManager : public moveit_controller_manager::MoveItControllerManager
134134
{
135135
std::string ns_;
136+
std::chrono::duration<double> service_call_timeout_;
136137
pluginlib::ClassLoader<ControllerHandleAllocator> loader_;
137138
typedef std::map<std::string, controller_manager_msgs::msg::ControllerState> ControllersMap;
138139

@@ -192,11 +193,11 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan
192193

193194
auto request = std::make_shared<controller_manager_msgs::srv::ListControllers::Request>();
194195
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)
196197
{
197198
RCLCPP_WARN_STREAM(getLogger(), "Failed to read controllers from "
198199
<< list_controllers_service_->get_service_name() << " within "
199-
<< SERVICE_CALL_TIMEOUT << " seconds");
200+
<< service_call_timeout_.count() << " seconds");
200201
return;
201202
}
202203

@@ -318,6 +319,20 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan
318319
}
319320
}
320321

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+
321336
list_controllers_service_ = node_->create_client<controller_manager_msgs::srv::ListControllers>(
322337
getAbsName("controller_manager/list_controllers"));
323338
switch_controller_service_ = node_->create_client<controller_manager_msgs::srv::SwitchController>(
@@ -552,11 +567,11 @@ class Ros2ControlManager : public moveit_controller_manager::MoveItControllerMan
552567
if (!request->activate_controllers.empty() || !request->deactivate_controllers.empty())
553568
{ // something to switch?
554569
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)
556571
{
557572
RCLCPP_ERROR_STREAM(getLogger(), "Couldn't switch controllers at "
558573
<< switch_controller_service_->get_service_name() << " within "
559-
<< SERVICE_CALL_TIMEOUT << " seconds");
574+
<< service_call_timeout_.count() << " seconds");
560575
return false;
561576
}
562577
discover(true);

0 commit comments

Comments
 (0)