Skip to content

Commit aecbe07

Browse files
committed
Add waitForProgramNotRunning to wrapper
1 parent 9f794d3 commit aecbe07

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

include/ur_client_library/example_robot_wrapper.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class ExampleRobotWrapper
2525
void stopConsumingRTDEData();
2626

2727
bool waitForProgramRunning(int milliseconds = 100);
28+
bool waitForProgramNotRunning(int milliseconds = 100);
29+
30+
// Depending on whether it is headless or not start autostart_program or call driver's
31+
// resendRobotProgram function.
32+
bool resendRobotProgram();
2833

2934
bool startRobotProgram(const std::string& program_file_name);
3035

@@ -41,9 +46,14 @@ class ExampleRobotWrapper
4146

4247
bool program_running_;
4348
std::condition_variable program_running_cv_;
49+
std::condition_variable program_not_running_cv_;
4450
std::mutex program_running_mutex_;
51+
std::mutex program_not_running_mutex_;
4552

4653
std::thread rtde_consumer_thread_;
54+
55+
bool headless_mode_;
56+
std::string autostart_program_;
4757
};
4858
} // namespace urcl
4959

src/example_robot_wrapper.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace urcl
66
ExampleRobotWrapper::ExampleRobotWrapper(const std::string& robot_ip, const std::string& output_recipe_file,
77
const std::string& input_recipe_file, const bool headless_mode,
88
const std::string& autostart_program, const std::string& script_file)
9+
: headless_mode_(headless_mode), autostart_program_(autostart_program)
910
{
1011
dashboard_client_ = std::make_shared<DashboardClient>(robot_ip);
1112

@@ -111,6 +112,17 @@ bool ExampleRobotWrapper::waitForProgramRunning(int milliseconds)
111112
return false;
112113
}
113114

115+
bool ExampleRobotWrapper::waitForProgramNotRunning(int milliseconds)
116+
{
117+
std::unique_lock<std::mutex> lk(program_not_running_mutex_);
118+
if (program_not_running_cv_.wait_for(lk, std::chrono::milliseconds(milliseconds)) == std::cv_status::no_timeout ||
119+
program_running_ == false)
120+
{
121+
return true;
122+
}
123+
return false;
124+
}
125+
114126
bool ExampleRobotWrapper::startRobotProgram(const std::string& program_file_name)
115127
{
116128
if (!dashboard_client_->commandLoadProgram(program_file_name))
@@ -121,5 +133,13 @@ bool ExampleRobotWrapper::startRobotProgram(const std::string& program_file_name
121133

122134
return dashboard_client_->commandPlay();
123135
}
136+
bool ExampleRobotWrapper::resendRobotProgram()
137+
{
138+
if (headless_mode_)
139+
{
140+
return ur_driver_->sendRobotProgram();
141+
}
142+
return startRobotProgram(autostart_program_);
143+
}
124144

125145
} // namespace urcl

0 commit comments

Comments
 (0)