@@ -53,9 +53,10 @@ static const std::string SCRIPT_COMMAND_PORT_REPLACE("{{SCRIPT_COMMAND_SERVER_PO
5353urcl::UrDriver::UrDriver (const std::string& robot_ip, const std::string& script_file,
5454 const std::string& output_recipe_file, const std::string& input_recipe_file,
5555 std::function<void (bool )> handle_program_state, bool headless_mode,
56- std::unique_ptr<ToolCommSetup> tool_comm_setup, const uint32_t reverse_port,
57- const uint32_t script_sender_port, int servoj_gain, double servoj_lookahead_time,
58- bool non_blocking_read, const std::string& reverse_ip, const uint32_t trajectory_port,
56+ std::unique_ptr<ToolCommSetup> tool_comm_setup, const std::string& calibration_checksum,
57+ const bool & simulated, const uint32_t reverse_port, const uint32_t script_sender_port,
58+ int servoj_gain, double servoj_lookahead_time, bool non_blocking_read,
59+ const std::string& reverse_ip, const uint32_t trajectory_port,
5960 const uint32_t script_command_port)
6061 : servoj_time_(0.008 )
6162 , servoj_gain_(servoj_gain)
@@ -66,12 +67,9 @@ urcl::UrDriver::UrDriver(const std::string& robot_ip, const std::string& script_
6667 URCL_LOG_DEBUG (" Initializing urdriver" );
6768 URCL_LOG_DEBUG (" Initializing RTDE client" );
6869 rtde_client_.reset (new rtde_interface::RTDEClient (robot_ip_, notifier_, output_recipe_file, input_recipe_file));
69-
70- primary_stream_.reset (
71- new comm::URStream<primary_interface::PrimaryPackage>(robot_ip_, urcl::primary_interface::UR_PRIMARY_PORT));
72- secondary_stream_.reset (
73- new comm::URStream<primary_interface::PrimaryPackage>(robot_ip_, urcl::primary_interface::UR_SECONDARY_PORT));
74- secondary_stream_->connect ();
70+ URCL_LOG_DEBUG (" Initializing Primary client" );
71+ primary_client_.reset (new primary_interface::PrimaryClient (robot_ip, calibration_checksum));
72+ primary_client_->setSimulated (simulated);
7573
7674 non_blocking_read_ = non_blocking_read;
7775 get_packet_timeout_ = non_blocking_read_ ? 0 : 100 ;
@@ -179,31 +177,14 @@ urcl::UrDriver::UrDriver(const std::string& robot_ip, const std::string& script_
179177urcl::UrDriver::UrDriver (const std::string& robot_ip, const std::string& script_file,
180178 const std::string& output_recipe_file, const std::string& input_recipe_file,
181179 std::function<void (bool )> handle_program_state, bool headless_mode,
182- std::unique_ptr<ToolCommSetup> tool_comm_setup, const std::string& calibration_checksum ,
183- const uint32_t reverse_port, const uint32_t script_sender_port, int servoj_gain,
184- double servoj_lookahead_time, bool non_blocking_read, const std::string& reverse_ip,
185- const uint32_t trajectory_port, const uint32_t script_command_port)
180+ std::unique_ptr<ToolCommSetup> tool_comm_setup, const uint32_t reverse_port ,
181+ const uint32_t script_sender_port, int servoj_gain, double servoj_lookahead_time ,
182+ bool non_blocking_read, const std::string& reverse_ip, const uint32_t trajectory_port ,
183+ const uint32_t script_command_port)
186184 : UrDriver(robot_ip, script_file, output_recipe_file, input_recipe_file, handle_program_state, headless_mode,
187- std::move (tool_comm_setup), reverse_port, script_sender_port, servoj_gain, servoj_lookahead_time ,
188- non_blocking_read, reverse_ip, trajectory_port)
185+ std::move (tool_comm_setup), "", false, reverse_port, script_sender_port, servoj_gain,
186+ servoj_lookahead_time, non_blocking_read, reverse_ip, trajectory_port, script_command_port )
189187{
190- URCL_LOG_WARN (" DEPRECATION NOTICE: Passing the calibration_checksum to the UrDriver's constructor has been "
191- " deprecated. Instead, use the checkCalibration(calibration_checksum) function separately. This "
192- " notice is for application developers using this library. If you are only using an application using "
193- " this library, you can ignore this message." );
194- if (checkCalibration (calibration_checksum))
195- {
196- URCL_LOG_INFO (" Calibration checked successfully." );
197- }
198- else
199- {
200- URCL_LOG_ERROR (" The calibration parameters of the connected robot don't match the ones from the given kinematics "
201- " config file. Please be aware that this can lead to critical inaccuracies of tcp positions. Use "
202- " the ur_calibration tool to extract the correct calibration from the robot and pass that into the "
203- " description. See "
204- " [https://github.com/UniversalRobots/Universal_Robots_ROS_Driver#extract-calibration-information] "
205- " for details." );
206- }
207188}
208189
209190std::unique_ptr<rtde_interface::DataPackage> urcl::UrDriver::getDataPackage ()
@@ -339,27 +320,7 @@ std::string UrDriver::readScriptFile(const std::string& filename)
339320
340321bool UrDriver::checkCalibration (const std::string& checksum)
341322{
342- if (primary_stream_ == nullptr )
343- {
344- throw std::runtime_error (" checkCalibration() called without a primary interface connection being established." );
345- }
346- primary_interface::PrimaryParser parser;
347- comm::URProducer<primary_interface::PrimaryPackage> prod (*primary_stream_, parser);
348- prod.setupProducer ();
349-
350- CalibrationChecker consumer (checksum);
351-
352- comm::INotifier notifier;
353-
354- comm::Pipeline<primary_interface::PrimaryPackage> pipeline (prod, &consumer, " Pipeline" , notifier);
355- pipeline.run ();
356-
357- while (!consumer.isChecked ())
358- {
359- std::this_thread::sleep_for (std::chrono::seconds (1 ));
360- }
361- URCL_LOG_DEBUG (" Got calibration information from robot." );
362- return consumer.checkSuccessful ();
323+ return primary_client_->getCalibrationChecker ()->checkCalibration (checksum);
363324}
364325
365326rtde_interface::RTDEWriter& UrDriver::getRTDEWriter ()
@@ -369,29 +330,7 @@ rtde_interface::RTDEWriter& UrDriver::getRTDEWriter()
369330
370331bool UrDriver::sendScript (const std::string& program)
371332{
372- if (secondary_stream_ == nullptr )
373- {
374- throw std::runtime_error (" Sending script to robot requested while there is no primary interface established. "
375- " This "
376- " should not happen." );
377- }
378-
379- // urscripts (snippets) must end with a newline, or otherwise the controller's runtime will
380- // not execute them. To avoid problems, we always just append a newline here, even if
381- // there may already be one.
382- auto program_with_newline = program + ' \n ' ;
383-
384- size_t len = program_with_newline.size ();
385- const uint8_t * data = reinterpret_cast <const uint8_t *>(program_with_newline.c_str ());
386- size_t written;
387-
388- if (secondary_stream_->write (data, len, written))
389- {
390- URCL_LOG_DEBUG (" Sent program to robot:\n %s" , program_with_newline.c_str ());
391- return true ;
392- }
393- URCL_LOG_ERROR (" Could not send program to robot" );
394- return false ;
333+ return primary_client_->sendScript (program);
395334}
396335
397336bool UrDriver::sendRobotProgram ()
0 commit comments