3232#include < iostream>
3333#include " ur_client_library/exceptions.h"
3434#include " ur_client_library/log.h"
35+ #include " ur_client_library/ur/version_information.h"
3536
3637namespace urcl
3738{
@@ -40,24 +41,31 @@ ExampleRobotWrapper::ExampleRobotWrapper(const std::string& robot_ip, const std:
4041 const std::string& autostart_program, const std::string& script_file)
4142 : headless_mode_(headless_mode), autostart_program_(autostart_program)
4243{
43- dashboard_client_ = std::make_shared<DashboardClient >(robot_ip);
44+ primary_client_ = std::make_shared<urcl::primary_interface::PrimaryClient >(robot_ip, notifier_ );
4445
45- // Connect the robot Dashboard
46- if (!dashboard_client_->connect ())
46+ primary_client_->start ();
47+
48+ auto robot_version = primary_client_->getRobotVersion ();
49+ if (*robot_version < VersionInformation::fromString (" 10.0.0" ))
4750 {
48- URCL_LOG_ERROR (" Could not connect to dashboard" );
49- }
51+ dashboard_client_ = std::make_shared<DashboardClient>(robot_ip);
52+ // Connect the robot Dashboard
53+ if (!dashboard_client_->connect ())
54+ {
55+ URCL_LOG_ERROR (" Could not connect to dashboard" );
56+ }
5057
51- // In CI we the dashboard client times out for no obvious reason. Hence we increase the timeout
52- // here.
53- timeval tv;
54- tv.tv_sec = 10 ;
55- tv.tv_usec = 0 ;
56- dashboard_client_->setReceiveTimeout (tv);
58+ // In CI we the dashboard client times out for no obvious reason. Hence we increase the timeout
59+ // here.
60+ timeval tv;
61+ tv.tv_sec = 10 ;
62+ tv.tv_usec = 0 ;
63+ dashboard_client_->setReceiveTimeout (tv);
64+ }
5765
58- if (!initializeRobotWithDashboard ())
66+ if (!initializeRobotWithPrimaryClient ())
5967 {
60- throw UrException (" Could not initialize robot with dashboard " );
68+ throw UrException (" Could not initialize robot with primary client " );
6169 }
6270
6371 UrDriverConfiguration driver_config;
@@ -75,7 +83,7 @@ ExampleRobotWrapper::ExampleRobotWrapper(const std::string& robot_ip, const std:
7583 startRobotProgram (autostart_program);
7684 }
7785
78- if (headless_mode | !std::empty (autostart_program))
86+ if (headless_mode || !std::empty (autostart_program))
7987 {
8088 if (!waitForProgramRunning (500 ))
8189 {
@@ -94,20 +102,27 @@ ExampleRobotWrapper::~ExampleRobotWrapper()
94102
95103bool ExampleRobotWrapper::clearProtectiveStop ()
96104{
97- std::string safety_status;
98- dashboard_client_->commandSafetyStatus (safety_status);
99- bool is_protective_stopped = safety_status.find (" PROTECTIVE_STOP" ) != std::string::npos;
100- if (is_protective_stopped)
105+ if (primary_client_->isRobotProtectiveStopped ())
101106 {
102107 URCL_LOG_INFO (" Robot is in protective stop, trying to release it" );
103- dashboard_client_->commandClosePopup ();
104- dashboard_client_->commandCloseSafetyPopup ();
105- if (!dashboard_client_->commandUnlockProtectiveStop ())
108+ if (dashboard_client_ != nullptr )
109+ {
110+ dashboard_client_->commandClosePopup ();
111+ }
112+ try
113+ {
114+ primary_client_->commandUnlockProtectiveStop ();
115+ }
116+ catch (const TimeoutException&)
106117 {
107118 std::this_thread::sleep_for (std::chrono::seconds (5 ));
108- if (!dashboard_client_-> commandUnlockProtectiveStop ())
119+ try
109120 {
110- URCL_LOG_ERROR (" Could not unlock protective stop" );
121+ primary_client_->commandUnlockProtectiveStop ();
122+ }
123+ catch (const TimeoutException&)
124+ {
125+ URCL_LOG_ERROR (" Robot did not unlock the protective stop within the given timeout" );
111126 return false ;
112127 }
113128 }
@@ -157,6 +172,36 @@ bool ExampleRobotWrapper::initializeRobotWithDashboard()
157172 return true ;
158173}
159174
175+ bool ExampleRobotWrapper::initializeRobotWithPrimaryClient ()
176+ {
177+ try
178+ {
179+ waitFor ([&]() { return primary_client_->getRobotModeData () != nullptr ; }, std::chrono::seconds (5 ));
180+ clearProtectiveStop ();
181+ }
182+ catch (const std::exception& exc)
183+ {
184+ URCL_LOG_ERROR (" Could not clear protective stop (%s)" , exc.what ());
185+ return false ;
186+ }
187+
188+ try
189+ {
190+ primary_client_->commandStop ();
191+ primary_client_->commandBrakeRelease ();
192+ }
193+ catch (const TimeoutException& exc)
194+ {
195+ URCL_LOG_ERROR (exc.what ());
196+ return false ;
197+ }
198+
199+ // Now the robot is ready to receive a program
200+ URCL_LOG_INFO (" Robot ready to start a program" );
201+ robot_initialized_ = true ;
202+ return true ;
203+ }
204+
160205void ExampleRobotWrapper::handleRobotProgramState (bool program_running)
161206{
162207 // Print the text in green so we see it better
@@ -254,13 +299,17 @@ bool ExampleRobotWrapper::waitForProgramNotRunning(int milliseconds)
254299
255300bool ExampleRobotWrapper::startRobotProgram (const std::string& program_file_name)
256301{
257- if (! dashboard_client_-> commandLoadProgram (program_file_name) )
302+ if (dashboard_client_ != nullptr )
258303 {
259- URCL_LOG_ERROR (" Could not load program '%s'" , program_file_name.c_str ());
260- return false ;
261- }
304+ if (!dashboard_client_->commandLoadProgram (program_file_name))
305+ {
306+ URCL_LOG_ERROR (" Could not load program '%s'" , program_file_name.c_str ());
307+ return false ;
308+ }
262309
263- return dashboard_client_->commandPlay ();
310+ return dashboard_client_->commandPlay ();
311+ }
312+ return false ;
264313}
265314bool ExampleRobotWrapper::resendRobotProgram ()
266315{
0 commit comments