Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions examples/force_mode_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ int main(int argc, char* argv[])
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
"external_control.urp");

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

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

Expand Down
4 changes: 2 additions & 2 deletions examples/freedrive_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ int main(int argc, char* argv[])
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
"external_control.urp");

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

Expand Down
5 changes: 2 additions & 3 deletions examples/full_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ int main(int argc, char* argv[])
bool headless_mode = true;
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
"external_control.urp");
// Make sure that external control script is running
if (!g_my_robot->waitForProgramRunning())
if (!g_my_robot->isHealthy())
{
URCL_LOG_ERROR("External Control script not running.");
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
return 1;
}
// --------------- INITIALIZATION END -------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/instruction_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ int main(int argc, char* argv[])
"[https://github.com/UniversalRobots/Universal_Robots_ROS_Driver#extract-calibration-information] "
"for details.");
}
if (!g_my_robot->waitForProgramRunning(1000))
if (!g_my_robot->isHealthy())
{
std::cout << "Program did not start running. Is the robot in remote control?" << std::endl;
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
return 1;
}

Expand Down
5 changes: 2 additions & 3 deletions examples/spline_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ int main(int argc, char* argv[])
bool headless_mode = true;
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
"external_control.urp");
// Make sure that external control script is running
if (!g_my_robot->waitForProgramRunning())
if (!g_my_robot->isHealthy())
{
URCL_LOG_ERROR("External Control script not running.");
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
return 1;
}

Expand Down
4 changes: 2 additions & 2 deletions examples/tool_contact_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ int main(int argc, char* argv[])
bool headless_mode = true;
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
"external_control.urp");
if (!g_my_robot->waitForProgramRunning(1000))
if (!g_my_robot->isHealthy())
{
std::cout << "Program did not start running. Is the robot in remote control?" << std::endl;
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
return 1;
}
g_my_robot->ur_driver_->registerToolContactResultCallback(&handleToolContactResult);
Expand Down
4 changes: 2 additions & 2 deletions examples/trajectory_point_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ int main(int argc, char* argv[])
bool headless_mode = true;
g_my_robot = std::make_unique<urcl::ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
"external_control.urp");
if (!g_my_robot->waitForProgramRunning(1000))
if (!g_my_robot->isHealthy())
{
URCL_LOG_ERROR("Program did not start running. Is the robot in remote control?");
URCL_LOG_ERROR("Something in the robot initialization went wrong. Exiting. Please check the output above.");
return 1;
}
// --------------- INITIALIZATION END -------------------
Expand Down
6 changes: 5 additions & 1 deletion include/ur_client_library/example_robot_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ExampleRobotWrapper
*
* The robot will be power-cycled once and end up switched on, breaks released.
*/
void initializeRobotWithDashboard();
bool initializeRobotWithDashboard();

/**
* @brief Starts RTDE communication with the robot.
Expand Down Expand Up @@ -157,6 +157,8 @@ class ExampleRobotWrapper
*/
bool startRobotProgram(const std::string& program_file_name);

bool isHealthy() const;

std::shared_ptr<urcl::DashboardClient> dashboard_client_; /*!< Dashboard client to interact with the robot */
std::shared_ptr<urcl::UrDriver> ur_driver_; /*!< UR driver to interact with the robot */

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

bool robot_initialized_ = false;

bool program_running_;
std::condition_variable program_running_cv_;
std::condition_variable program_not_running_cv_;
Expand Down
32 changes: 31 additions & 1 deletion src/example_robot_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
{
startRobotProgram(autostart_program);
}

if (headless_mode | !std::empty(autostart_program))
{
if (!waitForProgramRunning(500))
{
URCL_LOG_ERROR("Program did not start running. Is the robot in remote control?");
}
}
}

ExampleRobotWrapper::~ExampleRobotWrapper()
Expand All @@ -66,34 +74,41 @@
stopConsumingRTDEData();
}
}
void ExampleRobotWrapper::initializeRobotWithDashboard()

bool ExampleRobotWrapper::initializeRobotWithDashboard()
{
// // Stop program, if there is one running
if (!dashboard_client_->commandStop())
{
URCL_LOG_ERROR("Could not send stop program command");
return false;

Check warning on line 84 in src/example_robot_wrapper.cpp

View check run for this annotation

Codecov / codecov/patch

src/example_robot_wrapper.cpp#L84

Added line #L84 was not covered by tests
}

// Power it off
if (!dashboard_client_->commandPowerOff())
{
URCL_LOG_ERROR("Could not send Power off command");
return false;

Check warning on line 91 in src/example_robot_wrapper.cpp

View check run for this annotation

Codecov / codecov/patch

src/example_robot_wrapper.cpp#L91

Added line #L91 was not covered by tests
}

// Power it on
if (!dashboard_client_->commandPowerOn())
{
URCL_LOG_ERROR("Could not send Power on command");
return false;

Check warning on line 98 in src/example_robot_wrapper.cpp

View check run for this annotation

Codecov / codecov/patch

src/example_robot_wrapper.cpp#L98

Added line #L98 was not covered by tests
}

// Release the brakes
if (!dashboard_client_->commandBrakeRelease())
{
URCL_LOG_ERROR("Could not send BrakeRelease command");
return false;

Check warning on line 105 in src/example_robot_wrapper.cpp

View check run for this annotation

Codecov / codecov/patch

src/example_robot_wrapper.cpp#L105

Added line #L105 was not covered by tests
}

// Now the robot is ready to receive a program
URCL_LOG_INFO("Robot ready to start a program");
robot_initialized_ = true;
return true;
}

void ExampleRobotWrapper::handleRobotProgramState(bool program_running)
Expand Down Expand Up @@ -210,4 +225,19 @@
return startRobotProgram(autostart_program_);
}

bool ExampleRobotWrapper::isHealthy() const
{
if (!robot_initialized_)
{
URCL_LOG_ERROR("Robot is not initialized");
return false;

Check warning on line 233 in src/example_robot_wrapper.cpp

View check run for this annotation

Codecov / codecov/patch

src/example_robot_wrapper.cpp#L232-L233

Added lines #L232 - L233 were not covered by tests
}
if (!program_running_)
{
URCL_LOG_ERROR("Robot program is not running");
return false;

Check warning on line 238 in src/example_robot_wrapper.cpp

View check run for this annotation

Codecov / codecov/patch

src/example_robot_wrapper.cpp#L237-L238

Added lines #L237 - L238 were not covered by tests
}
return true;
}

} // namespace urcl
7 changes: 1 addition & 6 deletions tests/test_spline_interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,7 @@ class SplineInterpolationTest : public ::testing::Test
g_my_robot->dashboard_client_->commandCloseSafetyPopup();
ASSERT_TRUE(g_my_robot->dashboard_client_->commandUnlockProtectiveStop());
}
// Make sure script is running on the robot
if (!g_my_robot->waitForProgramRunning())
{
g_my_robot->resendRobotProgram();
ASSERT_TRUE(g_my_robot->waitForProgramRunning());
}
ASSERT_TRUE(g_my_robot->isHealthy());
}

void sendIdle()
Expand Down
9 changes: 2 additions & 7 deletions tests/test_ur_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ class UrDriverTest : public ::testing::Test

void SetUp()
{
// Make sure script is running on the robot
if (!g_my_robot->waitForProgramRunning())
{
g_my_robot->resendRobotProgram();
ASSERT_TRUE(g_my_robot->waitForProgramRunning());
}
ASSERT_TRUE(g_my_robot->isHealthy());
}
};

Expand Down Expand Up @@ -295,4 +290,4 @@ int main(int argc, char* argv[])
}

return RUN_ALL_TESTS();
}
}
Loading