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,28 @@ 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+ dashboard_client_->commandCloseSafetyPopup ();
112+ }
113+ try
114+ {
115+ primary_client_->commandUnlockProtectiveStop ();
116+ }
117+ catch (const TimeoutException&)
106118 {
107119 std::this_thread::sleep_for (std::chrono::seconds (5 ));
108- if (!dashboard_client_-> commandUnlockProtectiveStop ())
120+ try
109121 {
110- URCL_LOG_ERROR (" Could not unlock protective stop" );
122+ primary_client_->commandUnlockProtectiveStop ();
123+ }
124+ catch (const TimeoutException&)
125+ {
126+ URCL_LOG_ERROR (" Robot did not unlock the protective stop within the given timeout" );
111127 return false ;
112128 }
113129 }
@@ -157,6 +173,36 @@ bool ExampleRobotWrapper::initializeRobotWithDashboard()
157173 return true ;
158174}
159175
176+ bool ExampleRobotWrapper::initializeRobotWithPrimaryClient ()
177+ {
178+ try
179+ {
180+ waitFor ([&]() { return primary_client_->getRobotModeData () != nullptr ; }, std::chrono::seconds (5 ));
181+ clearProtectiveStop ();
182+ }
183+ catch (const std::exception& exc)
184+ {
185+ URCL_LOG_ERROR (" Could not clear protective stop (%s)" , exc.what ());
186+ return false ;
187+ }
188+
189+ try
190+ {
191+ primary_client_->commandStop ();
192+ primary_client_->commandBrakeRelease ();
193+ }
194+ catch (const TimeoutException& exc)
195+ {
196+ URCL_LOG_ERROR (exc.what ());
197+ return false ;
198+ }
199+
200+ // Now the robot is ready to receive a program
201+ URCL_LOG_INFO (" Robot ready to start a program" );
202+ robot_initialized_ = true ;
203+ return true ;
204+ }
205+
160206void ExampleRobotWrapper::handleRobotProgramState (bool program_running)
161207{
162208 // Print the text in green so we see it better
@@ -254,13 +300,20 @@ bool ExampleRobotWrapper::waitForProgramNotRunning(int milliseconds)
254300
255301bool ExampleRobotWrapper::startRobotProgram (const std::string& program_file_name)
256302{
257- if (! dashboard_client_-> commandLoadProgram (program_file_name) )
303+ if (dashboard_client_ != nullptr )
258304 {
259- URCL_LOG_ERROR (" Could not load program '%s'" , program_file_name.c_str ());
260- return false ;
261- }
305+ if (!dashboard_client_->commandLoadProgram (program_file_name))
306+ {
307+ URCL_LOG_ERROR (" Could not load program '%s'" , program_file_name.c_str ());
308+ return false ;
309+ }
262310
263- return dashboard_client_->commandPlay ();
311+ return dashboard_client_->commandPlay ();
312+ }
313+ URCL_LOG_ERROR (" Dashboard client is not initialized. If you are running a PolyScope X robot, the dashboard server is "
314+ " not available. Loading and running polyscope programs isn't possible. Please use the headless mode "
315+ " or the teach pendant instead." );
316+ return false ;
264317}
265318bool ExampleRobotWrapper::resendRobotProgram ()
266319{
0 commit comments