Skip to content

Commit 5ab3f4f

Browse files
Felix ExnerVinDp
authored andcommitted
Use robot_receive_timeout instead of keepalive_count
1 parent 4255d83 commit 5ab3f4f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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::millisec(std::stoi(info_.hardware_parameters["keep_alive_count"]) * 20);
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();

0 commit comments

Comments
 (0)