Skip to content

Commit 7c22f49

Browse files
committed
Add ROS param to control reverse interface robot receive timeout
Useful when the connection to the robot does not support real-time control
1 parent 0d8db31 commit 7c22f49

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

ur_robot_driver/include/ur_robot_driver/hardware_interface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include <scaled_joint_trajectory_controller/scaled_joint_command_interface.h>
6565

6666
#include <ur_client_library/ur/ur_driver.h>
67+
#include <ur_client_library/ur/robot_receive_timeout.h>
6768
#include <ur_robot_driver/dashboard_client_ros.h>
6869

6970
#include <ur_dashboard_msgs/RobotMode.h>
@@ -352,6 +353,7 @@ class HardwareInterface : public hardware_interface::RobotHW
352353

353354
std::string robot_ip_;
354355
std::string tf_prefix_;
356+
urcl::RobotReceiveTimeout robot_receive_timeout_ = urcl::RobotReceiveTimeout::millisec(20);
355357
};
356358

357359
} // namespace ur_driver

ur_robot_driver/launch/ur_common.launch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<arg name="headless_mode" default="false" doc="Automatically send URScript to robot to execute. On e-Series this does require the robot to be in 'remote-control' mode. With this, the URCap is not needed on the robot."/>
2626
<arg name="ur_hardware_interface_node_required" default="true" doc="Shut down ros environment if ur_hardware_interface-node dies."/>
2727
<arg name="use_spline_interpolation" default="true" doc="True if splines should be used as interpolation on the robot controller when forwarding trajectory, if false movej or movel commands are used"/>
28+
<arg name="robot_receive_timeout" default="0.02" doc="Timeout for robot receive operations in seconds"/>
2829

2930
<!-- robot model -->
3031
<include file="$(arg robot_description_file)">
@@ -59,5 +60,6 @@
5960
<arg name="tool_tcp_port" value="$(arg tool_tcp_port)"/>
6061
<arg name="ur_hardware_interface_node_required" value="$(arg ur_hardware_interface_node_required)"/>
6162
<arg name="use_spline_interpolation" value="$(arg use_spline_interpolation)"/>
63+
<arg name="robot_receive_timeout" value="$(arg robot_receive_timeout)"/>
6264
</include>
6365
</launch>

ur_robot_driver/launch/ur_control.launch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<arg name="servoj_lookahead_time" default="0.03" doc="Specify lookahead time for servoing to position in joint space. A longer lookahead time can smooth the trajectory."/>
3535
<arg name="ur_hardware_interface_node_required" default="true" doc="Shut down ros environment if ur_hardware_interface-node dies."/>
3636
<arg name="use_spline_interpolation" default="true" doc="True if splines should be used as interpolation on the robot controller when forwarding trajectory, if false movej or movel commands are used"/>
37+
<arg name="robot_receive_timeout" default="0.02" doc="Timeout for robot receive operations in seconds"/>
3738

3839
<!-- Load hardware interface -->
3940
<node name="ur_hardware_interface" pkg="ur_robot_driver" type="ur_robot_driver_node" output="screen" launch-prefix="$(arg launch_prefix)" required="$(arg ur_hardware_interface_node_required)">
@@ -60,6 +61,7 @@
6061
<param name="servoj_gain" value="$(arg servoj_gain)"/>
6162
<param name="servoj_lookahead_time" value="$(arg servoj_lookahead_time)"/>
6263
<param name="use_spline_interpolation" value="$(arg use_spline_interpolation)"/>
64+
<param name="robot_receive_timeout" value="$(arg robot_receive_timeout)"/>
6365
</node>
6466

6567
<!-- Starts socat to bridge the robot's tool communication interface to a local tty device -->

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ bool HardwareInterface::init(ros::NodeHandle& root_nh, ros::NodeHandle& robot_hw
158158
// not used with combined_robot_hw can suppress important errors and affect real-time performance.
159159
robot_hw_nh.param("non_blocking_read", non_blocking_read_, false);
160160

161+
// Timeout for robot receive operations in seconds
162+
double timeout_seconds;
163+
robot_hw_nh.param("robot_receive_timeout", timeout_seconds, 0.02);
164+
robot_receive_timeout_ = urcl::RobotReceiveTimeout::sec(timeout_seconds);
165+
161166
// Specify gain for servoing to position in joint space.
162167
// A higher gain can sharpen the trajectory.
163168
int servoj_gain = robot_hw_nh.param("servoj_gain", 2000);
@@ -693,11 +698,11 @@ void HardwareInterface::write(const ros::Time& time, const ros::Duration& period
693698
{
694699
if (position_controller_running_)
695700
{
696-
ur_driver_->writeJointCommand(joint_position_command_, urcl::comm::ControlMode::MODE_SERVOJ);
701+
ur_driver_->writeJointCommand(joint_position_command_, urcl::comm::ControlMode::MODE_SERVOJ, robot_receive_timeout_);
697702
}
698703
else if (velocity_controller_running_)
699704
{
700-
ur_driver_->writeJointCommand(joint_velocity_command_, urcl::comm::ControlMode::MODE_SPEEDJ);
705+
ur_driver_->writeJointCommand(joint_velocity_command_, urcl::comm::ControlMode::MODE_SPEEDJ, robot_receive_timeout_);
701706
}
702707
else if (joint_forward_controller_running_)
703708
{
@@ -715,7 +720,7 @@ void HardwareInterface::write(const ros::Time& time, const ros::Duration& period
715720
cartesian_velocity_command_[3] = twist_command_.angular.x;
716721
cartesian_velocity_command_[4] = twist_command_.angular.y;
717722
cartesian_velocity_command_[5] = twist_command_.angular.z;
718-
ur_driver_->writeJointCommand(cartesian_velocity_command_, urcl::comm::ControlMode::MODE_SPEEDL);
723+
ur_driver_->writeJointCommand(cartesian_velocity_command_, urcl::comm::ControlMode::MODE_SPEEDL, robot_receive_timeout_);
719724
}
720725
else if (pose_controller_running_)
721726
{
@@ -729,11 +734,11 @@ void HardwareInterface::write(const ros::Time& time, const ros::Duration& period
729734
cartesian_pose_command_[4] = rot.GetRot().y();
730735
cartesian_pose_command_[5] = rot.GetRot().z();
731736

732-
ur_driver_->writeJointCommand(cartesian_pose_command_, urcl::comm::ControlMode::MODE_POSE);
737+
ur_driver_->writeJointCommand(cartesian_pose_command_, urcl::comm::ControlMode::MODE_POSE, robot_receive_timeout_);
733738
}
734739
else
735740
{
736-
ur_driver_->writeKeepalive();
741+
ur_driver_->writeKeepalive(robot_receive_timeout_);
737742
}
738743
packet_read_ = false;
739744
}
@@ -1292,7 +1297,7 @@ void HardwareInterface::startJointInterpolation(const hardware_interface::JointT
12921297
{
12931298
size_t point_number = trajectory.trajectory.points.size();
12941299
ROS_DEBUG("Starting joint-based trajectory forward");
1295-
ur_driver_->writeTrajectoryControlMessage(urcl::control::TrajectoryControlMessage::TRAJECTORY_START, point_number);
1300+
ur_driver_->writeTrajectoryControlMessage(urcl::control::TrajectoryControlMessage::TRAJECTORY_START, point_number, robot_receive_timeout_);
12961301
double last_time = 0.0;
12971302
for (size_t i = 0; i < point_number; i++)
12981303
{
@@ -1354,7 +1359,7 @@ void HardwareInterface::startCartesianInterpolation(const hardware_interface::Ca
13541359
{
13551360
size_t point_number = trajectory.trajectory.points.size();
13561361
ROS_DEBUG("Starting cartesian trajectory forward");
1357-
ur_driver_->writeTrajectoryControlMessage(urcl::control::TrajectoryControlMessage::TRAJECTORY_START, point_number);
1362+
ur_driver_->writeTrajectoryControlMessage(urcl::control::TrajectoryControlMessage::TRAJECTORY_START, point_number, robot_receive_timeout_);
13581363
double last_time = 0.0;
13591364
for (size_t i = 0; i < point_number; i++)
13601365
{

0 commit comments

Comments
 (0)