Skip to content

Commit 1a9399d

Browse files
author
Felix Exner (fexner)
authored
Replace keepalive count (#1002)
* Use robot_receive_timeout instead of keepalive_count * Add migration note containing the keepalive_count to robot_receive_timeout migration
1 parent 1098617 commit 1a9399d

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ur_robot_driver
2+
^^^^^^^^^^^^^^^
3+
4+
keep_alive_count -> robot_receive_timeout
5+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
7+
Doing real-time control with a robot requires the control pc to conform to certain timing
8+
constraints. For this ``keep_alive_count`` was used to estimate the tolerance that was given to the
9+
ROS controller in terms of multiples of 20 ms. Now the timeout is directly configured using the
10+
``robot_receive_timeout`` parameter of the hardware interface.

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
// UR stuff
5555
#include "ur_client_library/ur/ur_driver.h"
56+
#include "ur_client_library/ur/robot_receive_timeout.h"
5657
#include "ur_robot_driver/dashboard_client_ros.hpp"
5758
#include "ur_dashboard_msgs/msg/robot_mode.hpp"
5859

@@ -225,6 +226,8 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
225226
std::shared_ptr<std::thread> async_thread_;
226227

227228
std::atomic_bool rtde_comm_has_been_started_ = false;
229+
230+
urcl::RobotReceiveTimeout receive_timeout_ = urcl::RobotReceiveTimeout::millisec(20);
228231
};
229232
} // namespace ur_robot_driver
230233

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,6 @@ URPositionHardwareInterface::on_configure(const rclcpp_lifecycle::State& previou
414414
tool_comm_setup->setTxIdleChars(tx_idle_chars);
415415
}
416416

417-
// Amount of allowed timed out reads before the reverse interface will be dropped
418-
const int keep_alive_count = std::stoi(info_.hardware_parameters["keep_alive_count"]);
419-
420417
// Obtain the tf_prefix which is needed for the logging handler so that log messages from different arms are
421418
// distiguishable in the log
422419
const std::string tf_prefix = info_.hardware_parameters.at("tf_prefix");
@@ -429,7 +426,6 @@ URPositionHardwareInterface::on_configure(const rclcpp_lifecycle::State& previou
429426
std::bind(&URPositionHardwareInterface::handleRobotProgramState, this, std::placeholders::_1), headless_mode,
430427
std::move(tool_comm_setup), (uint32_t)reverse_port, (uint32_t)script_sender_port, servoj_gain,
431428
servoj_lookahead_time, non_blocking_read_, reverse_ip, trajectory_port, script_command_port);
432-
ur_driver_->setKeepaliveCount(keep_alive_count);
433429
} catch (urcl::ToolCommNotAvailable& e) {
434430
RCLCPP_FATAL_STREAM(rclcpp::get_logger("URPositionHardwareInterface"), "See parameter use_tool_communication");
435431

@@ -438,6 +434,9 @@ URPositionHardwareInterface::on_configure(const rclcpp_lifecycle::State& previou
438434
RCLCPP_FATAL_STREAM(rclcpp::get_logger("URPositionHardwareInterface"), e.what());
439435
return hardware_interface::CallbackReturn::ERROR;
440436
}
437+
// Timeout before the reverse interface will be dropped by the robot
438+
receive_timeout_ = urcl::RobotReceiveTimeout::sec(std::stof(info_.hardware_parameters["robot_receive_timeout"]));
439+
441440
RCLCPP_INFO(rclcpp::get_logger("URPositionHardwareInterface"), "Calibration checksum: '%s'.",
442441
calibration_checksum.c_str());
443442
// check calibration
@@ -627,10 +626,10 @@ hardware_interface::return_type URPositionHardwareInterface::write(const rclcpp:
627626
runtime_state_ == static_cast<uint32_t>(rtde::RUNTIME_STATE::PAUSING)) &&
628627
robot_program_running_ && (!non_blocking_read_ || packet_read_)) {
629628
if (position_controller_running_) {
630-
ur_driver_->writeJointCommand(urcl_position_commands_, urcl::comm::ControlMode::MODE_SERVOJ);
629+
ur_driver_->writeJointCommand(urcl_position_commands_, urcl::comm::ControlMode::MODE_SERVOJ, receive_timeout_);
631630

632631
} else if (velocity_controller_running_) {
633-
ur_driver_->writeJointCommand(urcl_velocity_commands_, urcl::comm::ControlMode::MODE_SPEEDJ);
632+
ur_driver_->writeJointCommand(urcl_velocity_commands_, urcl::comm::ControlMode::MODE_SPEEDJ, receive_timeout_);
634633

635634
} else {
636635
ur_driver_->writeKeepalive();

ur_robot_driver/urdf/ur.ros2_control.xacro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
script_command_port:=50004
2626
trajectory_port:=50003
2727
non_blocking_read:=true
28-
keep_alive_count:=2
28+
robot_receive_timeout:=0.04
2929
">
3030

3131
<xacro:property name="config_kinematics_parameters" value="${xacro.load_yaml(kinematics_parameters_file)}"/>
@@ -69,7 +69,7 @@
6969
<param name="tool_tx_idle_chars">${tool_tx_idle_chars}</param>
7070
<param name="tool_device_name">${tool_device_name}</param>
7171
<param name="tool_tcp_port">${tool_tcp_port}</param>
72-
<param name="keep_alive_count">${keep_alive_count}</param>
72+
<param name="robot_receive_timeout">${robot_receive_timeout}</param>
7373
</xacro:unless>
7474
</hardware>
7575

0 commit comments

Comments
 (0)