1+ // -- BEGIN LICENSE BLOCK ----------------------------------------------
2+ // Copyright 2024 Universal Robots A/S
3+ //
4+ // Redistribution and use in source and binary forms, with or without
5+ // modification, are permitted provided that the following conditions are met:
6+ //
7+ // * Redistributions of source code must retain the above copyright
8+ // notice, this list of conditions and the following disclaimer.
9+ //
10+ // * Redistributions in binary form must reproduce the above copyright
11+ // notice, this list of conditions and the following disclaimer in the
12+ // documentation and/or other materials provided with the distribution.
13+ //
14+ // * Neither the name of the {copyright_holder} nor the names of its
15+ // contributors may be used to endorse or promote products derived from
16+ // this software without specific prior written permission.
17+ //
18+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+ // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+ // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+ // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+ // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+ // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+ // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+ // POSSIBILITY OF SUCH DAMAGE.
29+ // -- END LICENSE BLOCK ------------------------------------------------
30+
31+ #include < chrono>
32+ #include < string>
33+ #include < thread>
34+
35+ #include " ur_client_library/types.h"
36+ #include " ur_client_library/ur/ur_driver.h"
37+ #include " ur_client_library/log.h"
38+ #include " ur_client_library/control/trajectory_point_interface.h"
39+ #include " ur_client_library/ur/dashboard_client.h"
40+ #include " ur_client_library/ur/instruction_executor.h"
41+
42+ const std::string DEFAULT_ROBOT_IP = " 192.168.56.101" ;
43+ const std::string SCRIPT_FILE = " resources/external_control.urscript" ;
44+ const std::string OUTPUT_RECIPE = " examples/resources/rtde_output_recipe.txt" ;
45+ const std::string INPUT_RECIPE = " examples/resources/rtde_input_recipe.txt" ;
46+ const std::string CALIBRATION_CHECKSUM = " calib_12788084448423163542" ;
47+
48+ std::unique_ptr<urcl::DashboardClient> g_my_dashboard;
49+ std::shared_ptr<urcl::UrDriver> g_my_driver;
50+
51+ // We need a callback function to register. See UrDriver's parameters for details.
52+ void handleRobotProgramState (bool program_running)
53+ {
54+ // Print the text in green so we see it better
55+ std::cout << " \033 [1;32mProgram running: " << std::boolalpha << program_running << " \033 [0m\n " << std::endl;
56+ }
57+
58+ int main (int argc, char * argv[])
59+ {
60+ urcl::setLogLevel (urcl::LogLevel::INFO);
61+ // Parse the ip arguments if given
62+ std::string robot_ip = DEFAULT_ROBOT_IP;
63+ if (argc > 1 )
64+ {
65+ robot_ip = std::string (argv[1 ]);
66+ }
67+
68+ // --------------- INITIALIZATION BEGIN -------------------
69+ // Making the robot ready for the program by:
70+ // Connect the robot Dashboard
71+ g_my_dashboard.reset (new urcl::DashboardClient (robot_ip));
72+ // if (!g_my_dashboard->connect())
73+ // {
74+ // URCL_LOG_ERROR("Could not connect to dashboard");
75+ // return 1;
76+ // }
77+ //
78+ // // // Stop program, if there is one running
79+ // if (!g_my_dashboard->commandStop())
80+ // {
81+ // URCL_LOG_ERROR("Could not send stop program command");
82+ // return 1;
83+ // }
84+ //
85+ // // Power it off
86+ // if (!g_my_dashboard->commandPowerOff())
87+ // {
88+ // URCL_LOG_ERROR("Could not send Power off command");
89+ // return 1;
90+ // }
91+ //
92+ // // Power it on
93+ // if (!g_my_dashboard->commandPowerOn())
94+ // {
95+ // URCL_LOG_ERROR("Could not send Power on command");
96+ // return 1;
97+ // }
98+ //
99+ // // Release the brakes
100+ // if (!g_my_dashboard->commandBrakeRelease())
101+ // {
102+ // URCL_LOG_ERROR("Could not send BrakeRelease command");
103+ // return 1;
104+ // }
105+
106+ std::unique_ptr<urcl::ToolCommSetup> tool_comm_setup;
107+ const bool headless = true ;
108+ g_my_driver.reset (new urcl::UrDriver (robot_ip, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE, &handleRobotProgramState,
109+ headless, std::move (tool_comm_setup), CALIBRATION_CHECKSUM));
110+ auto instruction_executor = std::make_shared<urcl::InstructionExecutor>(g_my_driver);
111+ // --------------- INITIALIZATION END -------------------
112+
113+ URCL_LOG_INFO (" Running motion" );
114+ // Trajectory definition
115+ std::vector<std::shared_ptr<urcl::control::MotionPrimitive>> motion_sequence{
116+ std::make_shared<urcl::control::MoveJPrimitive>(urcl::vector6d_t { -1.57 , -1.57 , 0 , 0 , 0 , 0 }, 0.1 ,
117+ std::chrono::seconds (5 )),
118+ std::make_shared<urcl::control::MoveJPrimitive>(urcl::vector6d_t { -1.57 , -1.6 , 1.6 , -0.7 , 0.7 , 0.2 }, 0.1 ,
119+ std::chrono::seconds (5 )),
120+
121+ std::make_shared<urcl::control::MoveLPrimitive>(urcl::Pose (-0.203 , 0.263 , 0.559 , 0.68 , -1.083 , -2.076 ), 0.1 ,
122+ std::chrono::seconds (2 )),
123+ std::make_shared<urcl::control::MoveLPrimitive>(urcl::Pose{ -0.203 , 0.463 , 0.559 , 0.68 , -1.083 , -2.076 }, 0.1 ,
124+ std::chrono::seconds (2 )),
125+ };
126+ instruction_executor->executeMotion (motion_sequence); // That could also receive velocity parametrization
127+
128+ instruction_executor->moveJ ({ -1.57 , -1.57 , 0 , 0 , 0 , 0 });
129+ instruction_executor->moveJ ({ -1.57 , -1.6 , 1.6 , -0.7 , 0.7 , 0.2 });
130+ instruction_executor->moveL ({ -0.203 , 0.263 , 0.559 , 0.68 , -1.083 , -2.076 });
131+ instruction_executor->moveL ({ -0.203 , 0.463 , 0.559 , 0.68 , -1.083 , -2.076 });
132+
133+ g_my_driver->stopControl ();
134+ return 0 ;
135+ }
0 commit comments