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