Skip to content

Commit 9f794d3

Browse files
committed
Add option to autostart a polyscope program when not using headless mode
1 parent 6cfa794 commit 9f794d3

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

examples/freedrive_example.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ int main(int argc, char* argv[])
8080
second_to_run = std::chrono::seconds(std::stoi(argv[2]));
8181
}
8282

83-
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, true);
83+
bool headless_mode = true;
84+
85+
g_my_robot = std::make_unique<ExampleRobotWrapper>(robot_ip, OUTPUT_RECIPE, INPUT_RECIPE, headless_mode,
86+
"external_control.urp");
8487

8588
if (!g_my_robot->waitForProgramRunning())
8689
{

include/ur_client_library/example_robot_wrapper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ExampleRobotWrapper
1616
ExampleRobotWrapper() = delete;
1717
ExampleRobotWrapper(const std::string& robot_ip, const std::string& output_recipe_file,
1818
const std::string& input_recipe_file, const bool headless_mode = true,
19-
const std::string& script_file = SCRIPT_FILE);
19+
const std::string& autostart_program = "", const std::string& script_file = SCRIPT_FILE);
2020

2121
void initializeRobotWithDashboard();
2222

@@ -26,6 +26,8 @@ class ExampleRobotWrapper
2626

2727
bool waitForProgramRunning(int milliseconds = 100);
2828

29+
bool startRobotProgram(const std::string& program_file_name);
30+
2931
std::shared_ptr<urcl::DashboardClient> dashboard_client_;
3032
std::shared_ptr<urcl::UrDriver> ur_driver_;
3133

src/example_robot_wrapper.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace urcl
55
{
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,
8-
const std::string& script_file)
8+
const std::string& autostart_program, const std::string& script_file)
99
{
1010
dashboard_client_ = std::make_shared<DashboardClient>(robot_ip);
1111

@@ -21,6 +21,11 @@ ExampleRobotWrapper::ExampleRobotWrapper(const std::string& robot_ip, const std:
2121
std::make_shared<UrDriver>(robot_ip, script_file, output_recipe_file, input_recipe_file,
2222
std::bind(&ExampleRobotWrapper::handleRobotProgramState, this, std::placeholders::_1),
2323
headless_mode, std::move(tool_comm_setup));
24+
25+
if (!headless_mode && !std::empty(autostart_program))
26+
{
27+
startRobotProgram(autostart_program);
28+
}
2429
}
2530
void ExampleRobotWrapper::initializeRobotWithDashboard()
2631
{
@@ -106,4 +111,15 @@ bool ExampleRobotWrapper::waitForProgramRunning(int milliseconds)
106111
return false;
107112
}
108113

114+
bool ExampleRobotWrapper::startRobotProgram(const std::string& program_file_name)
115+
{
116+
if (!dashboard_client_->commandLoadProgram(program_file_name))
117+
{
118+
URCL_LOG_ERROR("Could not load program '%s'", program_file_name.c_str());
119+
return false;
120+
}
121+
122+
return dashboard_client_->commandPlay();
123+
}
124+
109125
} // namespace urcl

0 commit comments

Comments
 (0)