Skip to content

Commit 236a669

Browse files
committed
Check for protective stop in ExampleRobotWrapper initialization
1 parent b43ef46 commit 236a669

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

include/ur_client_library/example_robot_wrapper.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ class ExampleRobotWrapper
157157
*/
158158
bool startRobotProgram(const std::string& program_file_name);
159159

160+
/**
161+
* @brief Clear protective stop on the robot.
162+
*
163+
* This will try to clear a protective stop on the robot. If the robot is not in protective stop
164+
* this call will do nothing.
165+
*/
166+
bool clearProtectiveStop();
167+
160168
bool isHealthy() const;
161169

162170
std::shared_ptr<urcl::DashboardClient> dashboard_client_; /*!< Dashboard client to interact with the robot */

src/example_robot_wrapper.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <ur_client_library/example_robot_wrapper.h>
3232
#include <iostream>
3333
#include "ur_client_library/exceptions.h"
34+
#include "ur_client_library/log.h"
3435

3536
namespace urcl
3637
{
@@ -80,9 +81,38 @@ ExampleRobotWrapper::~ExampleRobotWrapper()
8081
}
8182
}
8283

84+
bool ExampleRobotWrapper::clearProtectiveStop()
85+
{
86+
std::string safety_status;
87+
dashboard_client_->commandSafetyStatus(safety_status);
88+
bool is_protective_stopped = safety_status.find("PROTECTIVE_STOP") != std::string::npos;
89+
if (is_protective_stopped)
90+
{
91+
URCL_LOG_INFO("Robot is in protective stop, trying to release it");
92+
dashboard_client_->commandClosePopup();
93+
dashboard_client_->commandCloseSafetyPopup();
94+
if (!dashboard_client_->commandUnlockProtectiveStop())
95+
{
96+
std::this_thread::sleep_for(std::chrono::seconds(5));
97+
if (!dashboard_client_->commandUnlockProtectiveStop())
98+
{
99+
URCL_LOG_ERROR("Could not unlock protective stop");
100+
return false;
101+
}
102+
}
103+
}
104+
return true;
105+
}
106+
83107
bool ExampleRobotWrapper::initializeRobotWithDashboard()
84108
{
85-
// // Stop program, if there is one running
109+
if (!clearProtectiveStop())
110+
{
111+
URCL_LOG_ERROR("Could not clear protective stop");
112+
return false;
113+
}
114+
115+
// Stop program, if there is one running
86116
if (!dashboard_client_->commandStop())
87117
{
88118
URCL_LOG_ERROR("Could not send stop program command");

tests/test_instruction_executor.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,7 @@ class InstructionExecutorTest : public ::testing::Test
6262
void SetUp() override
6363
{
6464
executor_ = std::make_unique<InstructionExecutor>(g_my_robot->ur_driver_);
65-
std::string safety_status;
66-
g_my_robot->dashboard_client_->commandSafetyStatus(safety_status);
67-
bool is_protective_stopped = safety_status.find("PROTECTIVE_STOP") != std::string::npos;
68-
if (is_protective_stopped)
69-
{
70-
// We forced a protective stop above. Some versions require waiting 5 seconds before releasing
71-
// the protective stop.
72-
std::this_thread::sleep_for(std::chrono::seconds(5));
73-
g_my_robot->dashboard_client_->commandCloseSafetyPopup();
74-
ASSERT_TRUE(g_my_robot->dashboard_client_->commandUnlockProtectiveStop());
75-
}
65+
g_my_robot->clearProtectiveStop();
7666
// Make sure script is running on the robot
7767
if (!g_my_robot->waitForProgramRunning())
7868
{

0 commit comments

Comments
 (0)