Skip to content

Commit 517ad19

Browse files
committed
Make non blocking read timeout configurable
1 parent 8cc03bb commit 517ad19

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

ur_robot_driver/doc/hardware_interface_parameters.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ non_blocking_read (default: "true")
3030
If set to false, the ROS control cycle will wait for the robot to send a status update. Tests have
3131
shown that better real-time performance is achievable when setting this to ``true``. Required to be
3232
set to ``true`` when combining with other hardware components.
33+
When set to ``false``, the hardware interface will be stopped if it fails to read an RTDE package from the robot.
34+
when set to ``true``, the hardware interface will be stopped if it fails to read an RTDE package within the configured timeout (see non_blocking_read_timeout).
35+
36+
non_blocking_read_timeout (default: 0.04 (seconds))
37+
---------------------------------------------------
38+
Timeout value to be used when non_blocking_read is ``true``.
39+
If the value is 0 (or less) the timeout will be disabled.
40+
Note: for values <0.010 the driver might fail on startup, especially if used with URSim.
3341

3442
output_recipe_filename (Required)
3543
---------------------------------

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
204204
tf2::Quaternion tcp_rotation_quat_;
205205
Quaternion tcp_rotation_buffer;
206206

207-
rclcpp::Duration time_since_successful_read = rclcpp::Duration(0, 0);
208-
rclcpp::Duration max_time_between_reads = rclcpp::Duration(0, 4000000); // 4 ms
207+
rclcpp::Duration time_since_successful_read_ = rclcpp::Duration(0, 0);
208+
rclcpp::Duration non_blocking_read_timeout_ = rclcpp::Duration(0, 0);
209209

210210
bool packet_read_;
211211

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,9 @@ URPositionHardwareInterface::on_configure(const rclcpp_lifecycle::State& previou
630630
non_blocking_read_ = (info_.hardware_parameters["non_blocking_read"] == "true") ||
631631
(info_.hardware_parameters["non_blocking_read"] == "True");
632632

633+
non_blocking_read_timeout_ = rclcpp::Duration::from_seconds(stod(info_.hardware_parameters["non_blocking_read_"
634+
"timeout"]));
635+
633636
// Specify gain for servoing to position in joint space.
634637
// A higher gain can sharpen the trajectory.
635638
const int servoj_gain = stoi(info_.hardware_parameters["servoj_gain"]);
@@ -877,8 +880,6 @@ hardware_interface::return_type URPositionHardwareInterface::read(const rclcpp::
877880
if (!rtde_comm_has_been_started_) {
878881
ur_driver_->startRTDECommunication();
879882
rtde_comm_has_been_started_ = true;
880-
// Without this the driver will error out immediately, regardless of non_blocking_read_ (because of timeout)
881-
return hardware_interface::return_type::OK;
882883
}
883884
std::unique_ptr<rtde::DataPackage> data_pkg = ur_driver_->getDataPackage();
884885

@@ -968,21 +969,22 @@ hardware_interface::return_type URPositionHardwareInterface::read(const rclcpp::
968969
hw_moprim_states_[0] = static_cast<uint8_t>(current_moprim_execution_status_.load());
969970
hw_moprim_states_[1] = static_cast<double>(ready_for_new_moprim_);
970971

971-
time_since_successful_read = rclcpp::Duration(0, 0);
972+
time_since_successful_read_ = rclcpp::Duration(0, 0);
972973

973974
return hardware_interface::return_type::OK;
974975
}
975976

976977
if (non_blocking_read_) {
977-
time_since_successful_read += period;
978-
if (time_since_successful_read > max_time_between_reads) {
978+
time_since_successful_read_ += period;
979+
if (non_blocking_read_timeout_ > rclcpp::Duration(0, 0) &&
980+
time_since_successful_read_ > non_blocking_read_timeout_) {
979981
std::stringstream ss;
980-
ss << "It has been too long since the last successful reading of the hardware. \nTime since last successful "
981-
"read: "
982-
<< time_since_successful_read.seconds() * 1000
983-
<< " milliseconds \nThe maximum allowed time is: " << max_time_between_reads.seconds() * 1000
984-
<< " milliseconds";
982+
ss << "Non blocking read timeout exceeded. \n"
983+
<< "Time since last successful read of the hardware: " << time_since_successful_read_.seconds() * 1000
984+
<< " milliseconds \n"
985+
<< "The non blocking read time out is: " << non_blocking_read_timeout_.seconds() * 1000 << " milliseconds";
985986
RCLCPP_ERROR(rclcpp::get_logger("URPositionHardwareInterface"), ss.str().c_str());
987+
// For very small values of non_blocking_read_timeout_ (< 10 ms) this might error on startup
986988
return hardware_interface::return_type::ERROR;
987989
}
988990
return hardware_interface::return_type::OK;

ur_robot_driver/urdf/ur.ros2_control.xacro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
script_command_port:=50004
2626
trajectory_port:=50003
2727
non_blocking_read:=true
28+
non_blocking_read_timeout:=0.04
2829
robot_receive_timeout:=0.04
2930
rw_rate:=0
3031
">
@@ -60,6 +61,7 @@
6061
<param name="trajectory_port">${trajectory_port}</param>
6162
<param name="tf_prefix">${tf_prefix}</param>
6263
<param name="non_blocking_read">${non_blocking_read}</param>
64+
<param name="non_blocking_read_timeout">${non_blocking_read_timeout}</param>
6365
<param name="servoj_gain">2000</param>
6466
<param name="servoj_lookahead_time">0.03</param>
6567
<param name="use_tool_communication">${use_tool_communication}</param>

0 commit comments

Comments
 (0)