Skip to content

Commit 97213da

Browse files
committed
Move waitForProgramRunning to robot initialization
1 parent e8e7642 commit 97213da

11 files changed

+56
-35
lines changed

examples/force_mode_example.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ int main(int argc, char* argv[])
8686
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
8787
"external_control.urp");
8888

89+
if (!g_my_robot->isHealthy())
90+
{
91+
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
92+
return 1;
93+
}
8994
if (!g_my_robot->ur_driver_->checkCalibration(CALIBRATION_CHECKSUM))
9095
{
9196
URCL_LOG_ERROR("Calibration checksum does not match actual robot.");
@@ -95,12 +100,6 @@ int main(int argc, char* argv[])
95100
"for details.");
96101
}
97102

98-
// Make sure that external control script is running
99-
if (!g_my_robot->waitForProgramRunning())
100-
{
101-
URCL_LOG_ERROR("External Control script not running.");
102-
return 1;
103-
}
104103
// End of initialization -- We've started the external control program, which means we have to
105104
// write keepalive signals from now on. Otherwise the connection will be dropped.
106105

examples/freedrive_example.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ int main(int argc, char* argv[])
8585
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
8686
"external_control.urp");
8787

88-
if (!g_my_robot->waitForProgramRunning())
88+
if (!g_my_robot->isHealthy())
8989
{
90-
URCL_LOG_ERROR("External Control script not running.");
90+
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
9191
return 1;
9292
}
9393

examples/full_driver.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ int main(int argc, char* argv[])
6262
bool headless_mode = true;
6363
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
6464
"external_control.urp");
65-
// Make sure that external control script is running
66-
if (!g_my_robot->waitForProgramRunning())
65+
if (!g_my_robot->isHealthy())
6766
{
68-
URCL_LOG_ERROR("External Control script not running.");
67+
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
6968
return 1;
7069
}
7170
// --------------- INITIALIZATION END -------------------

examples/instruction_executor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ int main(int argc, char* argv[])
6969
"[https://github.com/UniversalRobots/Universal_Robots_ROS_Driver#extract-calibration-information] "
7070
"for details.");
7171
}
72-
if (!g_my_robot->waitForProgramRunning(1000))
72+
if (!g_my_robot->isHealthy())
7373
{
74-
std::cout << "Program did not start running. Is the robot in remote control?" << std::endl;
74+
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
7575
return 1;
7676
}
7777

examples/spline_example.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ int main(int argc, char* argv[])
125125
bool headless_mode = true;
126126
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
127127
"external_control.urp");
128-
// Make sure that external control script is running
129-
if (!g_my_robot->waitForProgramRunning())
128+
if (!g_my_robot->isHealthy())
130129
{
131-
URCL_LOG_ERROR("External Control script not running.");
130+
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
132131
return 1;
133132
}
134133

examples/tool_contact_example.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ int main(int argc, char* argv[])
8080
bool headless_mode = true;
8181
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
8282
"external_control.urp");
83-
if (!g_my_robot->waitForProgramRunning(1000))
83+
if (!g_my_robot->isHealthy())
8484
{
85-
std::cout << "Program did not start running. Is the robot in remote control?" << std::endl;
85+
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
8686
return 1;
8787
}
8888
g_my_robot->ur_driver_->registerToolContactResultCallback(&handleToolContactResult);

examples/trajectory_point_interface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ int main(int argc, char* argv[])
6666
bool headless_mode = true;
6767
g_my_robot = std::make_unique<urcl::ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
6868
"external_control.urp");
69-
if (!g_my_robot->waitForProgramRunning(1000))
69+
if (!g_my_robot->isHealthy())
7070
{
71-
URCL_LOG_ERROR("Program did not start running. Is the robot in remote control?");
71+
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
7272
return 1;
7373
}
7474
// --------------- INITIALIZATION END -------------------

include/ur_client_library/example_robot_wrapper.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ExampleRobotWrapper
8383
*
8484
* The robot will be power-cycled once and end up switched on, breaks released.
8585
*/
86-
void initializeRobotWithDashboard();
86+
bool initializeRobotWithDashboard();
8787

8888
/**
8989
* @brief Starts RTDE communication with the robot.
@@ -157,6 +157,8 @@ class ExampleRobotWrapper
157157
*/
158158
bool startRobotProgram(const std::string& program_file_name);
159159

160+
bool isHealthy() const;
161+
160162
std::shared_ptr<urcl::DashboardClient> dashboard_client_; /*!< Dashboard client to interact with the robot */
161163
std::shared_ptr<urcl::UrDriver> ur_driver_; /*!< UR driver to interact with the robot */
162164

@@ -168,6 +170,8 @@ class ExampleRobotWrapper
168170
std::mutex read_package_mutex_;
169171
std::unique_ptr<rtde_interface::DataPackage> data_pkg_;
170172

173+
bool robot_initialized_ = false;
174+
171175
bool program_running_;
172176
std::condition_variable program_running_cv_;
173177
std::condition_variable program_not_running_cv_;

src/example_robot_wrapper.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ ExampleRobotWrapper::ExampleRobotWrapper(const std::string& robot_ip, const std:
5757
{
5858
startRobotProgram(autostart_program);
5959
}
60+
61+
if (headless_mode | !std::empty(autostart_program))
62+
{
63+
if (!waitForProgramRunning(500))
64+
{
65+
URCL_LOG_ERROR("Program did not start running. Is the robot in remote control?");
66+
}
67+
}
6068
}
6169

6270
ExampleRobotWrapper::~ExampleRobotWrapper()
@@ -66,34 +74,41 @@ ExampleRobotWrapper::~ExampleRobotWrapper()
6674
stopConsumingRTDEData();
6775
}
6876
}
69-
void ExampleRobotWrapper::initializeRobotWithDashboard()
77+
78+
bool ExampleRobotWrapper::initializeRobotWithDashboard()
7079
{
7180
// // Stop program, if there is one running
7281
if (!dashboard_client_->commandStop())
7382
{
7483
URCL_LOG_ERROR("Could not send stop program command");
84+
return false;
7585
}
7686

7787
// Power it off
7888
if (!dashboard_client_->commandPowerOff())
7989
{
8090
URCL_LOG_ERROR("Could not send Power off command");
91+
return false;
8192
}
8293

8394
// Power it on
8495
if (!dashboard_client_->commandPowerOn())
8596
{
8697
URCL_LOG_ERROR("Could not send Power on command");
98+
return false;
8799
}
88100

89101
// Release the brakes
90102
if (!dashboard_client_->commandBrakeRelease())
91103
{
92104
URCL_LOG_ERROR("Could not send BrakeRelease command");
105+
return false;
93106
}
94107

95108
// Now the robot is ready to receive a program
96109
URCL_LOG_INFO("Robot ready to start a program");
110+
robot_initialized_ = true;
111+
return true;
97112
}
98113

99114
void ExampleRobotWrapper::handleRobotProgramState(bool program_running)
@@ -210,4 +225,19 @@ bool ExampleRobotWrapper::resendRobotProgram()
210225
return startRobotProgram(autostart_program_);
211226
}
212227

228+
bool ExampleRobotWrapper::isHealthy() const
229+
{
230+
if (!robot_initialized_)
231+
{
232+
URCL_LOG_ERROR("Robot is not initialized");
233+
return false;
234+
}
235+
if (!program_running_)
236+
{
237+
URCL_LOG_ERROR("Robot program is not running");
238+
return false;
239+
}
240+
return true;
241+
}
242+
213243
} // namespace urcl

tests/test_spline_interpolation.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,7 @@ class SplineInterpolationTest : public ::testing::Test
133133
g_my_robot->dashboard_client_->commandCloseSafetyPopup();
134134
ASSERT_TRUE(g_my_robot->dashboard_client_->commandUnlockProtectiveStop());
135135
}
136-
// Make sure script is running on the robot
137-
if (!g_my_robot->waitForProgramRunning())
138-
{
139-
g_my_robot->resendRobotProgram();
140-
ASSERT_TRUE(g_my_robot->waitForProgramRunning());
141-
}
136+
ASSERT_TRUE(g_my_robot->isHealthy());
142137
}
143138

144139
void sendIdle()

0 commit comments

Comments
 (0)