@@ -72,9 +72,6 @@ void UrDriver::init(const UrDriverConfiguration& config)
7272
7373 primary_stream_.reset (
7474 new comm::URStream<primary_interface::PrimaryPackage>(robot_ip_, urcl::primary_interface::UR_PRIMARY_PORT));
75- secondary_stream_.reset (
76- new comm::URStream<primary_interface::PrimaryPackage>(robot_ip_, urcl::primary_interface::UR_SECONDARY_PORT));
77- secondary_stream_->connect (socket_connection_attempts_, socket_reconnection_timeout_);
7875
7976 primary_client_.reset (new urcl::primary_interface::PrimaryClient (robot_ip_, notifier_));
8077
@@ -151,6 +148,7 @@ void UrDriver::init(const UrDriverConfiguration& config)
151148 trajectory_interface_.reset (new control::TrajectoryPointInterface (config.trajectory_port ));
152149 script_command_interface_.reset (new control::ScriptCommandInterface (config.script_command_port ));
153150
151+ startPrimaryClientCommunication ();
154152 if (in_headless_mode_)
155153 {
156154 full_robot_program_ = " stop program\n " ;
@@ -591,44 +589,11 @@ rtde_interface::RTDEWriter& UrDriver::getRTDEWriter()
591589
592590bool UrDriver::sendScript (const std::string& program)
593591{
594- if (secondary_stream_ == nullptr )
592+ if (primary_client_ == nullptr )
595593 {
596- throw std::runtime_error (" Sending script to robot requested while there is no secondary interface established. "
597- " This should not happen." );
598- }
599-
600- // urscripts (snippets) must end with a newline, or otherwise the controller's runtime will
601- // not execute them. To avoid problems, we always just append a newline here, even if
602- // there may already be one.
603- auto program_with_newline = program + ' \n ' ;
604-
605- size_t len = program_with_newline.size ();
606- const uint8_t * data = reinterpret_cast <const uint8_t *>(program_with_newline.c_str ());
607- size_t written;
608-
609- const auto send_script_contents = [this , program_with_newline, data, len,
610- &written](const std::string&& description) -> bool {
611- if (secondary_stream_->write (data, len, written))
612- {
613- URCL_LOG_DEBUG (" Sent program to robot:\n %s" , program_with_newline.c_str ());
614- return true ;
615- }
616- const std::string error_message = " Could not send program to robot: " + description;
617- URCL_LOG_ERROR (error_message.c_str ());
618594 return false ;
619- };
620-
621- if (send_script_contents (" initial attempt" ))
622- {
623- return true ;
624595 }
625-
626- if (reconnectSecondaryStream ())
627- {
628- return send_script_contents (" after reconnecting secondary stream" );
629- }
630-
631- return false ;
596+ return primary_client_->sendScript (program);
632597}
633598
634599bool UrDriver::sendRobotProgram ()
@@ -644,19 +609,6 @@ bool UrDriver::sendRobotProgram()
644609 }
645610}
646611
647- bool UrDriver::reconnectSecondaryStream ()
648- {
649- URCL_LOG_DEBUG (" Closing secondary stream..." );
650- secondary_stream_->close ();
651- if (secondary_stream_->connect ())
652- {
653- URCL_LOG_DEBUG (" Secondary stream connected" );
654- return true ;
655- }
656- URCL_LOG_ERROR (" Failed to reconnect secondary stream!" );
657- return false ;
658- }
659-
660612std::vector<std::string> UrDriver::getRTDEOutputRecipe ()
661613{
662614 return rtde_client_->getOutputRecipe ();
@@ -718,4 +670,4 @@ std::deque<urcl::primary_interface::ErrorCode> UrDriver::getErrorCodes()
718670{
719671 return primary_client_->getErrorCodes ();
720672}
721- } // namespace urcl
673+ } // namespace urcl
0 commit comments