rtde_client.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // Copyright 2019 FZI Forschungszentrum Informatik
5 // Created on behalf of Universal Robots A/S
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // -- END LICENSE BLOCK ------------------------------------------------
19 
20 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 
29 #ifndef UR_CLIENT_LIBRARY_RTDE_CLIENT_H_INCLUDED
30 #define UR_CLIENT_LIBRARY_RTDE_CLIENT_H_INCLUDED
31 
32 #include <memory>
33 
44 #include "ur_client_library/log.h"
46 
47 static const int UR_RTDE_PORT = 30004;
48 static const std::string PIPELINE_NAME = "RTDE Data Pipeline";
49 
50 namespace urcl
51 {
52 namespace rtde_interface
53 {
54 static const uint16_t MAX_RTDE_PROTOCOL_VERSION = 2;
55 static const unsigned MAX_REQUEST_RETRIES = 5;
56 
58 {
59  IS_POWER_ON = 0,
63 };
64 
66 {
67  IS_NORMAL_MODE = 0,
68  IS_REDUCED_MODE = 1,
70  IS_RECOVERY_MODE = 3,
75  IS_VIOLATION = 8,
76  IS_FAULT = 9,
78 };
79 
80 enum class ClientState
81 {
82  UNINITIALIZED = 0,
83  INITIALIZING = 1,
84  INITIALIZED = 2,
85  RUNNING = 3,
86  PAUSED = 4
87 };
88 
94 {
95 public:
96  RTDEClient() = delete;
109  RTDEClient(std::string robot_ip, comm::INotifier& notifier, const std::string& output_recipe_file,
110  const std::string& input_recipe_file, double target_frequency = 0.0,
111  bool ignore_unavailable_outputs = false);
112 
125  RTDEClient(std::string robot_ip, comm::INotifier& notifier, const std::vector<std::string>& output_recipe,
126  const std::vector<std::string>& input_recipe, double target_frequency = 0.0,
127  bool ignore_unavailable_outputs = false);
128  ~RTDEClient();
144  bool init(const size_t max_connection_attempts = 0,
145  const std::chrono::milliseconds reconnection_timeout = comm::TCPSocket::DEFAULT_RECONNECTION_TIME,
146  const size_t max_initialization_attempts = 3,
147  const std::chrono::milliseconds initialization_timeout = std::chrono::seconds(1));
153  bool start();
159  bool pause();
167  std::unique_ptr<rtde_interface::DataPackage> getDataPackage(std::chrono::milliseconds timeout);
168 
174  double getMaxFrequency() const
175  {
176  return max_frequency_;
177  }
178 
184  double getTargetFrequency() const
185  {
186  return target_frequency_;
187  }
188 
195  {
196  return urcontrol_version_;
197  }
198 
204  std::string getIP() const;
205 
213 
219  std::vector<std::string> getOutputRecipe()
220  {
221  return output_recipe_;
222  }
223 
224 private:
226  std::vector<std::string> output_recipe_;
228  std::vector<std::string> input_recipe_;
230  std::unique_ptr<comm::URProducer<RTDEPackage>> prod_;
232  std::unique_ptr<comm::Pipeline<RTDEPackage>> pipeline_;
234 
236 
239 
241 
242  constexpr static const double CB3_MAX_FREQUENCY = 125.0;
243  constexpr static const double URE_MAX_FREQUENCY = 500.0;
244 
245  // Reads output or input recipe from a file
246  std::vector<std::string> readRecipe(const std::string& recipe_file) const;
247 
248  // Helper function to ensure that timestamp is present in the output recipe. The timestamp is needed to ensure that
249  // the robot is booted.
250  std::vector<std::string> ensureTimestampIsPresent(const std::vector<std::string>& output_recipe) const;
251 
252  void setupCommunication(const size_t max_num_tries = 0,
253  const std::chrono::milliseconds reconnection_time = std::chrono::seconds(10));
254  bool negotiateProtocolVersion(const uint16_t protocol_version);
255  void queryURControlVersion();
256  void setupOutputs(const uint16_t protocol_version);
257  void setupInputs();
258  void disconnect();
259 
266  void resetOutputRecipe(const std::vector<std::string> new_recipe);
267 
278  bool isRobotBooted();
279  bool sendStart();
280  bool sendPause();
281 
290  std::vector<std::string> splitVariableTypes(const std::string& variable_types) const;
291 };
292 
293 } // namespace rtde_interface
294 } // namespace urcl
295 
296 #endif // UR_CLIENT_LIBRARY_RTDE_CLIENT_H_INCLUDED
urcl::rtde_interface::RTDEClient::readRecipe
std::vector< std::string > readRecipe(const std::string &recipe_file) const
Definition: src/rtde/rtde_client.cpp:640
urcl::rtde_interface::RTDEWriter
The RTDEWriter class offers an abstraction layer to send data to the robot via the RTDE interface....
Definition: rtde_writer.h:50
urcl::rtde_interface::RTDEClient::negotiateProtocolVersion
bool negotiateProtocolVersion(const uint16_t protocol_version)
Definition: src/rtde/rtde_client.cpp:181
data_package.h
pipeline.h
urcl::comm::URStream
The stream is an abstraction of the TCPSocket that offers reading a full UR data package out of the s...
Definition: stream.h:40
urcl::rtde_interface::UrRtdeSafetyStatusBits::IS_PROTECTIVE_STOPPED
@ IS_PROTECTIVE_STOPPED
urcl::rtde_interface::ClientState::PAUSED
@ PAUSED
urcl::rtde_interface::RTDEClient::notifier_
comm::INotifier notifier_
Definition: rtde_client.h:231
urcl::rtde_interface::RTDEClient::sendPause
bool sendPause()
Definition: src/rtde/rtde_client.cpp:608
urcl::rtde_interface::RTDEClient::pause
bool pause()
Pauses RTDE data package communication.
Definition: src/rtde/rtde_client.cpp:545
urcl::rtde_interface::RTDEClient::start
bool start()
Triggers the robot to start sending RTDE data packages in the negotiated format.
Definition: src/rtde/rtde_client.cpp:521
control_package_setup_outputs.h
urcl::rtde_interface::UrRtdeSafetyStatusBits::IS_FAULT
@ IS_FAULT
urcl::rtde_interface::RTDEClient::getTargetFrequency
double getTargetFrequency() const
Getter for the target frequency that the robot will publish RTDE data packages with.
Definition: rtde_client.h:184
urcl::rtde_interface::UrRtdeSafetyStatusBits::IS_EMERGENCY_STOPPED
@ IS_EMERGENCY_STOPPED
urcl::rtde_interface::RTDEClient::sendStart
bool sendStart()
Definition: src/rtde/rtde_client.cpp:566
urcl::rtde_interface::RTDEClient::disconnect
void disconnect()
Definition: src/rtde/rtde_client.cpp:464
urcl::rtde_interface::ClientState::INITIALIZING
@ INITIALIZING
urcl::rtde_interface::RTDEClient::pipeline_
std::unique_ptr< comm::Pipeline< RTDEPackage > > pipeline_
Definition: rtde_client.h:232
urcl::rtde_interface::ClientState::UNINITIALIZED
@ UNINITIALIZED
urcl
Definition: bin_parser.h:36
urcl::rtde_interface::RTDEParser
The RTDE specific parser. Interprets a given byte stream as serialized RTDE packages and parses it ac...
Definition: rtde_parser.h:45
rtde_parser.h
urcl::rtde_interface::RTDEClient::ignore_unavailable_outputs_
bool ignore_unavailable_outputs_
Definition: rtde_client.h:227
urcl::rtde_interface::RTDEClient::getOutputRecipe
std::vector< std::string > getOutputRecipe()
Getter for the RTDE output recipe.
Definition: rtde_client.h:219
urcl::rtde_interface::UrRtdeRobotStatusBits::IS_PROGRAM_RUNNING
@ IS_PROGRAM_RUNNING
urcl::rtde_interface::RTDEClient::getDataPackage
std::unique_ptr< rtde_interface::DataPackage > getDataPackage(std::chrono::milliseconds timeout)
Reads the pipeline to fetch the next data package.
Definition: src/rtde/rtde_client.cpp:683
urcl::rtde_interface::MAX_REQUEST_RETRIES
static const unsigned MAX_REQUEST_RETRIES
Definition: rtde_client.h:55
urcl::comm::TCPSocket::DEFAULT_RECONNECTION_TIME
static constexpr std::chrono::milliseconds DEFAULT_RECONNECTION_TIME
Definition: tcp_socket.h:70
urcl::rtde_interface::RTDEClient::init
bool init(const size_t max_connection_attempts=0, const std::chrono::milliseconds reconnection_timeout=comm::TCPSocket::DEFAULT_RECONNECTION_TIME, const size_t max_initialization_attempts=3, const std::chrono::milliseconds initialization_timeout=std::chrono::seconds(1))
Sets up RTDE communication with the robot. The handshake includes negotiation of the used protocol ve...
Definition: src/rtde/rtde_client.cpp:79
urcl::rtde_interface::UrRtdeSafetyStatusBits::IS_REDUCED_MODE
@ IS_REDUCED_MODE
urcl::rtde_interface::UrRtdeSafetyStatusBits::IS_NORMAL_MODE
@ IS_NORMAL_MODE
urcl::rtde_interface::UrRtdeSafetyStatusBits::IS_STOPPED_DUE_TO_SAFETY
@ IS_STOPPED_DUE_TO_SAFETY
urcl::rtde_interface::RTDEClient::target_frequency_
double target_frequency_
Definition: rtde_client.h:238
urcl::rtde_interface::RTDEClient::urcontrol_version_
VersionInformation urcontrol_version_
Definition: rtde_client.h:235
urcl::rtde_interface::UrRtdeSafetyStatusBits::IS_VIOLATION
@ IS_VIOLATION
urcl::VersionInformation
Struct containing a robot's version information.
Definition: version_information.h:42
urcl::comm::INotifier
Parent class for notifiers.
Definition: pipeline.h:253
urcl::rtde_interface::RTDEClient::resetOutputRecipe
void resetOutputRecipe(const std::vector< std::string > new_recipe)
Updates the output recipe to the given one and recreates all the objects which depend on it....
Definition: src/rtde/rtde_client.cpp:275
urcl::rtde_interface::RTDEClient::isRobotBooted
bool isRobotBooted()
Checks whether the robot is booted, this is done by looking at the timestamp from the robot controlle...
Definition: src/rtde/rtde_client.cpp:482
producer.h
urcl::rtde_interface::MAX_RTDE_PROTOCOL_VERSION
static const uint16_t MAX_RTDE_PROTOCOL_VERSION
Definition: rtde_client.h:54
urcl::rtde_interface::RTDEClient::client_state_
ClientState client_state_
Definition: rtde_client.h:240
stream.h
urcl::rtde_interface::UrRtdeRobotStatusBits::IS_POWER_BUTTON_PRESSED
@ IS_POWER_BUTTON_PRESSED
urcl::rtde_interface::RTDEClient::prod_
std::unique_ptr< comm::URProducer< RTDEPackage > > prod_
Definition: rtde_client.h:230
urcl::rtde_interface::ClientState
ClientState
Definition: rtde_client.h:80
urcl::rtde_interface::ClientState::INITIALIZED
@ INITIALIZED
urcl::rtde_interface::UrRtdeSafetyStatusBits
UrRtdeSafetyStatusBits
Definition: rtde_client.h:65
urcl::rtde_interface::RTDEClient::getWriter
RTDEWriter & getWriter()
Getter for the RTDE writer, which is used to send data via the RTDE interface to the robot.
Definition: src/rtde/rtde_client.cpp:703
urcl::rtde_interface::RTDEClient::getMaxFrequency
double getMaxFrequency() const
Getter for the maximum frequency the robot can publish RTDE data packages with.
Definition: rtde_client.h:174
urcl::rtde_interface::RTDEClient::setupCommunication
void setupCommunication(const size_t max_num_tries=0, const std::chrono::milliseconds reconnection_time=std::chrono::seconds(10))
Definition: src/rtde/rtde_client.cpp:118
rtde_package.h
urcl::rtde_interface::RTDEClient::writer_
RTDEWriter writer_
Definition: rtde_client.h:233
urcl::rtde_interface::RTDEClient::output_recipe_
std::vector< std::string > output_recipe_
Definition: rtde_client.h:226
urcl::rtde_interface::RTDEClient::getVersion
VersionInformation getVersion()
Getter for the UR control version received from the robot.
Definition: rtde_client.h:194
urcl::rtde_interface::UrRtdeSafetyStatusBits::IS_SAFEGUARD_STOPPED
@ IS_SAFEGUARD_STOPPED
PIPELINE_NAME
static const std::string PIPELINE_NAME
Definition: rtde_client.h:48
urcl::rtde_interface::UrRtdeSafetyStatusBits::IS_SYSTEM_EMERGENCY_STOPPED
@ IS_SYSTEM_EMERGENCY_STOPPED
urcl::rtde_interface::UrRtdeSafetyStatusBits::IS_RECOVERY_MODE
@ IS_RECOVERY_MODE
urcl::rtde_interface::RTDEClient::~RTDEClient
~RTDEClient()
Definition: src/rtde/rtde_client.cpp:74
UR_RTDE_PORT
static const int UR_RTDE_PORT
Definition: rtde_client.h:47
rtde_writer.h
urcl::rtde_interface::UrRtdeRobotStatusBits::IS_TEACH_BUTTON_PRESSED
@ IS_TEACH_BUTTON_PRESSED
urcl::rtde_interface::UrRtdeRobotStatusBits
UrRtdeRobotStatusBits
Definition: rtde_client.h:57
urcl::rtde_interface::RTDEClient::getIP
std::string getIP() const
Returns the IP address (of the machine running this driver) used for the socket connection.
Definition: src/rtde/rtde_client.cpp:698
urcl::rtde_interface::RTDEClient::RTDEClient
RTDEClient()=delete
urcl::rtde_interface::UrRtdeRobotStatusBits::IS_POWER_ON
@ IS_POWER_ON
urcl::rtde_interface::UrRtdeSafetyStatusBits::IS_ROBOT_EMERGENCY_STOPPED
@ IS_ROBOT_EMERGENCY_STOPPED
log.h
urcl::rtde_interface::RTDEClient::queryURControlVersion
void queryURControlVersion()
Definition: src/rtde/rtde_client.cpp:229
urcl::rtde_interface::RTDEClient::max_frequency_
double max_frequency_
Definition: rtde_client.h:237
urcl::rtde_interface::RTDEClient::splitVariableTypes
std::vector< std::string > splitVariableTypes(const std::string &variable_types) const
Splits a variable_types string as reported from the robot into single variable type strings.
Definition: src/rtde/rtde_client.cpp:708
urcl::rtde_interface::RTDEClient::input_recipe_
std::vector< std::string > input_recipe_
Definition: rtde_client.h:228
package_header.h
urcl::rtde_interface::RTDEClient::setupInputs
void setupInputs()
Definition: src/rtde/rtde_client.cpp:397
urcl::rtde_interface::RTDEClient::parser_
RTDEParser parser_
Definition: rtde_client.h:229
control_package_start.h
urcl::rtde_interface::RTDEClient::setupOutputs
void setupOutputs(const uint16_t protocol_version)
Definition: src/rtde/rtde_client.cpp:285
request_protocol_version.h
urcl::rtde_interface::RTDEClient::stream_
comm::URStream< RTDEPackage > stream_
Definition: rtde_client.h:225
urcl::rtde_interface::ClientState::RUNNING
@ RUNNING
urcl::rtde_interface::RTDEClient::URE_MAX_FREQUENCY
constexpr static const double URE_MAX_FREQUENCY
Definition: rtde_client.h:243
urcl::rtde_interface::RTDEClient
The RTDEClient class manages communication over the RTDE interface. It contains the RTDE handshake an...
Definition: rtde_client.h:93
urcl::rtde_interface::RTDEClient::CB3_MAX_FREQUENCY
constexpr static const double CB3_MAX_FREQUENCY
Definition: rtde_client.h:242
urcl::rtde_interface::RTDEClient::ensureTimestampIsPresent
std::vector< std::string > ensureTimestampIsPresent(const std::vector< std::string > &output_recipe) const
Definition: src/rtde/rtde_client.cpp:669


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Mon May 26 2025 02:35:58