|
| 1 | +// -- BEGIN LICENSE BLOCK ---------------------------------------------- |
| 2 | +// Copyright 2025 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 | + |
1 | 31 | #ifndef UR_CLIENT_LIBRARY_EXAMPLE_ROBOT_WRAPPER_H_INCLUDED |
2 | 32 | #define UR_CLIENT_LIBRARY_EXAMPLE_ROBOT_WRAPPER_H_INCLUDED |
3 | 33 |
|
|
7 | 37 |
|
8 | 38 | namespace urcl |
9 | 39 | { |
| 40 | +/*! |
| 41 | + * \class ExampleRobotWrapper |
| 42 | + * \brief This class is a high-level abstraction around UrDriver and DashboardClient. It's main |
| 43 | + * purpose is to help us avoiding repetitive robot initialization code in our examples and tests. |
| 44 | + * |
| 45 | + * It is therefore not intended to be used in production code, but rather as a helper class for |
| 46 | + * developers. If you want to use this wrapper in your own code, please make sure to understand the |
| 47 | + * logic behind it and adjust it to your needs. |
| 48 | + * |
| 49 | + * Since this is mainly intended for internal use, don't count on the API being stable for this |
| 50 | + * class! |
| 51 | + */ |
10 | 52 | class ExampleRobotWrapper |
11 | 53 | { |
12 | 54 | public: |
13 | 55 | inline static const std::string DEFAULT_ROBOT_IP = "192.168.56.101"; |
14 | 56 | inline static const std::string SCRIPT_FILE = "resources/external_control.urscript"; |
15 | 57 |
|
16 | 58 | ExampleRobotWrapper() = delete; |
| 59 | + /*! |
| 60 | + * \brief Construct a new Example Robot Wrapper object |
| 61 | + * |
| 62 | + * This will connect to a robot and initialize it. In headless mode the program will be running |
| 63 | + * instantly, in teach pendant mode the from \p autostart_program will be started. |
| 64 | + * |
| 65 | + * Note: RTDE communication has to be started separately. |
| 66 | + * |
| 67 | + * \param robot_ip IP address of the robot to connect to |
| 68 | + * \param output_recipe_file Output recipe file for RTDE communication |
| 69 | + * \param input_recipe_file Input recipe file for RTDE communication |
| 70 | + * \param headless_mode Should the driver be started in headless mode or not? |
| 71 | + * \param autostart_program Program to start automatically after initialization when not in |
| 72 | + * headless mode. This flag is ignored in headless mode. |
| 73 | + * \param script_file URScript file to send to the robot. That should be script code |
| 74 | + * communicating to the driver's reverse interface and trajectory interface. |
| 75 | + */ |
17 | 76 | ExampleRobotWrapper(const std::string& robot_ip, const std::string& output_recipe_file, |
18 | 77 | const std::string& input_recipe_file, const bool headless_mode = true, |
19 | 78 | const std::string& autostart_program = "", const std::string& script_file = SCRIPT_FILE); |
20 | 79 | ~ExampleRobotWrapper(); |
21 | 80 |
|
| 81 | + /** |
| 82 | + * @brief Initializes the robot in order to be able to start a program. |
| 83 | + * |
| 84 | + * The robot will be power-cycled once and end up switched on, breaks released. |
| 85 | + */ |
22 | 86 | void initializeRobotWithDashboard(); |
23 | 87 |
|
| 88 | + /** |
| 89 | + * @brief Starts RTDE communication with the robot. |
| 90 | + * |
| 91 | + * @param consume_data Once the RTDE client is started, it's data has to be consumed. If you |
| 92 | + * don't actually care about that data, this class can silently consume RTDE data when `true` is |
| 93 | + * passed. This can be stopped and started at any time using the startConsumingRTDEData() and |
| 94 | + * stopConsumingRTDEData() methods. |
| 95 | + */ |
24 | 96 | void startRTDECommununication(const bool consume_data = false); |
| 97 | + |
| 98 | + /** |
| 99 | + * @brief Start consuming RTDE data in the background. |
| 100 | + */ |
25 | 101 | void startConsumingRTDEData(); |
| 102 | + |
| 103 | + /** |
| 104 | + * @brief Stop consuming RTDE data in the background. Note that data has to be consumed manually |
| 105 | + * using readDataPackage(). |
| 106 | + */ |
26 | 107 | void stopConsumingRTDEData(); |
| 108 | + |
| 109 | + /** |
| 110 | + * @brief Get the latest RTDE package. |
| 111 | + * |
| 112 | + * Do not call this, while RTDE data is being consumed in the background. In doubt, call |
| 113 | + * stopConsumingRTDEData() before calling this function. |
| 114 | + * |
| 115 | + * @param[out] data_pkg The data package will be stored in that object |
| 116 | + * @return true on a successful read, false if no package can be read or when RTDE data is |
| 117 | + * already being consumed in the background. |
| 118 | + */ |
27 | 119 | bool readDataPackage(std::unique_ptr<rtde_interface::DataPackage>& data_pkg); |
28 | 120 |
|
| 121 | + /** |
| 122 | + * @brief Blocks until there is a robot program connected to the driver's reverse interface or |
| 123 | + * until the timeout is hit. |
| 124 | + * |
| 125 | + * @param milliseconds How long to wait for a successful connection. |
| 126 | + * @return True on a successful connection, false if not connection could be detected before the |
| 127 | + * timeout. |
| 128 | + */ |
29 | 129 | bool waitForProgramRunning(int milliseconds = 100); |
| 130 | + |
| 131 | + /** |
| 132 | + * @brief Blocks until there is a disconnection event from the driver's reverse interface |
| 133 | + * detected or until the timeout is hit. |
| 134 | + * |
| 135 | + * @param milliseconds How long to wait for a disconnection. |
| 136 | + * @return True on a disconnection event has been detected, false if no event could be detected before the |
| 137 | + * timeout. |
| 138 | + */ |
30 | 139 | bool waitForProgramNotRunning(int milliseconds = 100); |
31 | 140 |
|
32 | | - // Depending on whether it is headless or not start autostart_program or call driver's |
33 | | - // resendRobotProgram function. |
| 141 | + /** |
| 142 | + * @brief Depending on whether it is headless or not start autostart_program or call driver's resendRobotProgram |
| 143 | + * function. |
| 144 | + * |
| 145 | + * @return True on successful program start, false otherwise. |
| 146 | + */ |
34 | 147 | bool resendRobotProgram(); |
35 | 148 |
|
| 149 | + /** |
| 150 | + * @brief Start the program \p program_file_name on the robot. |
| 151 | + * |
| 152 | + * The program has be be present on the robot, otherwise this call does not succeed. The robot |
| 153 | + * needs to be in remote_control mode for this to work properly. |
| 154 | + * |
| 155 | + * @param program_file_name Filename on the robot including the ".urp" extension. |
| 156 | + * @return True on successful program start, false otherwise. |
| 157 | + */ |
36 | 158 | bool startRobotProgram(const std::string& program_file_name); |
37 | 159 |
|
38 | | - std::shared_ptr<urcl::DashboardClient> dashboard_client_; |
39 | | - std::shared_ptr<urcl::UrDriver> ur_driver_; |
| 160 | + std::shared_ptr<urcl::DashboardClient> dashboard_client_; /*!< Dashboard client to interact with the robot */ |
| 161 | + std::shared_ptr<urcl::UrDriver> ur_driver_; /*!< UR driver to interact with the robot */ |
40 | 162 |
|
41 | 163 | private: |
42 | 164 | void handleRobotProgramState(bool program_running); |
|
0 commit comments