Skip to content

Commit 943fb57

Browse files
committed
Update example file name and use same setup as other examples
1 parent d5427f9 commit 943fb57

3 files changed

Lines changed: 69 additions & 54 deletions

File tree

examples/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ add_executable(primary_pipeline_example
1111
primary_pipeline.cpp)
1212
target_link_libraries(primary_pipeline_example ur_client_library::urcl)
1313

14-
add_executable(primary_client
15-
primary_client.cpp)
16-
target_link_libraries(primary_client ur_client_library::urcl)
14+
add_executable(send_script_blocking
15+
send_script_blocking.cpp)
16+
target_link_libraries(send_script_blocking ur_client_library::urcl)
1717

1818
add_executable(primary_pipeline_calibration_example
1919
primary_pipeline_calibration.cpp)

examples/primary_client.cpp

Lines changed: 0 additions & 51 deletions
This file was deleted.

examples/send_script_blocking.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <ur_client_library/primary/primary_client.h>
2+
#include <thread>
3+
#include <chrono>
4+
5+
std::string DEFAULT_ROBOT_IP = "192.168.56.101";
6+
7+
int main(int argc, char* argv[])
8+
{
9+
// Set the loglevel to info to print info logs
10+
urcl::setLogLevel(urcl::LogLevel::INFO);
11+
12+
// Parse the ip arguments if given
13+
std::string robot_ip = DEFAULT_ROBOT_IP;
14+
if (argc > 1)
15+
{
16+
robot_ip = std::string(argv[1]);
17+
}
18+
auto notif = urcl::comm::INotifier();
19+
auto client = urcl::primary_interface::PrimaryClient(robot_ip, notif);
20+
client.start(10);
21+
std::cout << "Client connected" << std::endl;
22+
23+
// --------------- INITIALIZATION END -------------------
24+
25+
// Make sure the robot is running
26+
client.commandBrakeRelease();
27+
28+
if (!client.safetyModeAllowsExecution())
29+
{
30+
std::cout << "Robot is not in a safety state where script execution is possible. Exiting." << std::endl;
31+
return 0;
32+
}
33+
34+
// The sendScriptBlocking accepts script code, and will return true or false,
35+
// depending on whether the script is successfully executed
36+
const std::string fully_defined_script = R"""(
37+
# This is a fully defined script, function definition and all
38+
# All comments in this script will be stripped before sending the script to the robot
39+
40+
# Any whitespace-only lines will also be removed
41+
def example_fun():
42+
movej([0,-0.75,0,0,0,0])
43+
sleep(0.1)
44+
movel([0,0,-1.5,0,0,0], t=5)
45+
end)""";
46+
47+
if (client.sendScriptBlocking(fully_defined_script))
48+
{
49+
// The function definition can also be omitted
50+
// A function name will then be auto generated
51+
client.sendScriptBlocking(R"(textmsg("Successful program execution"))");
52+
}
53+
// A script-function name can also be passed to the method
54+
// A timeout can also be given to limit the wait for the passed function to start. If timeout = 0, it will
55+
// wait indefinitely.
56+
client.sendScriptBlocking(R"(textmsg("hello"))", "cool_function_name", std::chrono::milliseconds(0));
57+
// There is no feedback on secondary programs, so it will return successful as soon as the script is sent to the
58+
// robot (Behavior is the same the sendScript function)
59+
// Note that secondary scripts have to be "fully defined" by the user.
60+
std::string secondary_script = R"(
61+
sec sec_script():
62+
textmsg("Named secondary program"
63+
end
64+
)";
65+
client.sendScriptBlocking(secondary_script);
66+
}

0 commit comments

Comments
 (0)