Skip to content

Commit 5058ac4

Browse files
Adds full nonblocking readout support (Multiarm part 4) - v2 (#673) (#703)
Adds full nonblocking readout support --------- Co-authored-by: Lennart Nachtigall <[email protected]> (cherry picked from commit 87363e4) Co-authored-by: Lennart Nachtigall <[email protected]>
1 parent d0e620f commit 5058ac4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
221221

222222
std::unique_ptr<urcl::UrDriver> ur_driver_;
223223
std::shared_ptr<std::thread> async_thread_;
224+
225+
bool rtde_comm_has_been_started_ = false;
224226
};
225227
} // namespace ur_robot_driver
226228

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ URPositionHardwareInterface::on_activate(const rclcpp_lifecycle::State& previous
413413
RCLCPP_INFO(rclcpp::get_logger("URPositionHardwareInterface"), "Initializing driver...");
414414
registerUrclLogHandler();
415415
try {
416+
rtde_comm_has_been_started_ = false;
416417
ur_driver_ = std::make_unique<urcl::UrDriver>(
417418
robot_ip, script_filename, output_recipe_filename, input_recipe_filename,
418419
std::bind(&URPositionHardwareInterface::handleRobotProgramState, this, std::placeholders::_1), headless_mode,
@@ -444,8 +445,6 @@ URPositionHardwareInterface::on_activate(const rclcpp_lifecycle::State& previous
444445
"README.md] for details.");
445446
}
446447

447-
ur_driver_->startRTDECommunication();
448-
449448
async_thread_ = std::make_shared<std::thread>(&URPositionHardwareInterface::asyncThread, this);
450449

451450
RCLCPP_INFO(rclcpp::get_logger("URPositionHardwareInterface"), "System successfully started!");
@@ -507,6 +506,12 @@ void URPositionHardwareInterface::asyncThread()
507506
hardware_interface::return_type URPositionHardwareInterface::read(const rclcpp::Time& time,
508507
const rclcpp::Duration& period)
509508
{
509+
// We want to start the rtde comm the latest point possible due to the delay times arising from setting up the
510+
// communication with multiple arms
511+
if (!rtde_comm_has_been_started_) {
512+
ur_driver_->startRTDECommunication();
513+
rtde_comm_has_been_started_ = true;
514+
}
510515
std::unique_ptr<rtde::DataPackage> data_pkg = ur_driver_->getDataPackage();
511516

512517
if (data_pkg) {
@@ -587,8 +592,8 @@ hardware_interface::return_type URPositionHardwareInterface::read(const rclcpp::
587592

588593
return hardware_interface::return_type::OK;
589594
}
590-
591-
RCLCPP_ERROR(rclcpp::get_logger("URPositionHardwareInterface"), "Unable to read from hardware...");
595+
if (!non_blocking_read_)
596+
RCLCPP_ERROR(rclcpp::get_logger("URPositionHardwareInterface"), "Unable to read from hardware...");
592597
// TODO(anyone): could not read from the driver --> return ERROR --> on error will be called
593598
return hardware_interface::return_type::OK;
594599
}
@@ -641,6 +646,9 @@ void URPositionHardwareInterface::initAsyncIO()
641646

642647
void URPositionHardwareInterface::checkAsyncIO()
643648
{
649+
if (!rtde_comm_has_been_started_) {
650+
return;
651+
}
644652
for (size_t i = 0; i < 18; ++i) {
645653
if (!std::isnan(standard_dig_out_bits_cmd_[i]) && ur_driver_ != nullptr) {
646654
if (i <= 7) {

0 commit comments

Comments
 (0)