@@ -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()
507506hardware_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
642647void 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