primary_consumer.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 2020 FZI Forschungszentrum Informatik
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 // -- END LICENSE BLOCK ------------------------------------------------
18 
19 //----------------------------------------------------------------------
26 //----------------------------------------------------------------------
27 
28 #ifndef UR_CLIENT_LIBRARY_PRIMARY_CONSUMER_H_INCLUDED
29 #define UR_CLIENT_LIBRARY_PRIMARY_CONSUMER_H_INCLUDED
30 
35 
36 #include <functional>
37 #include <mutex>
38 #include <condition_variable>
39 
40 namespace urcl
41 {
42 namespace primary_interface
43 {
51 {
52 public:
54  {
55  }
56  virtual ~PrimaryConsumer() = default;
57 
65  virtual bool consume(RobotMessage& msg) override
66  {
67  return true;
68  }
69 
77  virtual bool consume(RobotState& msg) override
78  {
79  return true;
80  }
81 
89  virtual bool consume(VersionMessage& pkg) override
90  {
91  std::scoped_lock lock(version_information_mutex_);
92  version_information_ = std::make_shared<VersionInformation>();
95  version_information_->bugfix = pkg.svn_version_;
97  return true;
98  }
99 
107  virtual bool consume(KinematicsInfo& pkg) override
108  {
109  URCL_LOG_DEBUG("%s", pkg.toString().c_str());
110  kinematics_info_ = std::make_shared<KinematicsInfo>(pkg);
111  return true;
112  }
113 
121  virtual bool consume(ErrorCodeMessage& pkg) override
122  {
124  code.message_code = pkg.message_code_;
126  code.report_level = pkg.report_level_;
127  code.data_type = pkg.data_type_;
128  code.data = pkg.data_;
129  code.text = pkg.text_;
130  code.timestamp = pkg.timestamp_;
131  code.to_string = pkg.toString();
132 
133  const auto log_contents = "Logging an ErrorCodeMessage from the UR Controller Box: " + pkg.toString();
134 
135  switch (code.report_level)
136  {
143  URCL_LOG_DEBUG(log_contents.c_str());
144  break;
146  URCL_LOG_INFO(log_contents.c_str());
147  break;
149  URCL_LOG_WARN(log_contents.c_str());
150  break;
151  default:
152  // urcl::primary_interface::ReportLevel::VIOLATION:
153  // urcl::primary_interface::ReportLevel::FAULT:
154  URCL_LOG_ERROR(log_contents.c_str());
155  break;
156  }
157 
158  if (error_code_message_callback_ != nullptr)
159  {
161  }
162  return true;
163  }
164 
165  virtual bool consume(RobotModeData& pkg) override
166  {
167  URCL_LOG_DEBUG("Robot mode is now %s", robotModeString(static_cast<RobotMode>(pkg.robot_mode_)).c_str());
168  std::scoped_lock lock(robot_mode_mutex_);
169  robot_mode_ = std::make_shared<RobotModeData>(pkg);
170  return true;
171  }
172 
173  virtual bool consume(ConfigurationData& pkg) override
174  {
175  std::scoped_lock lock(configuration_data_mutex_);
176  configuration_data_ = std::make_shared<ConfigurationData>(pkg);
177  return true;
178  }
179 
186  void setErrorCodeMessageCallback(std::function<void(ErrorCode&)> callback_function)
187  {
188  error_code_message_callback_ = callback_function;
189  }
190 
196  std::shared_ptr<KinematicsInfo> getKinematicsInfo()
197  {
198  return kinematics_info_;
199  }
200 
207  std::shared_ptr<RobotModeData> getRobotModeData()
208  {
209  std::scoped_lock lock(robot_mode_mutex_);
210  return robot_mode_;
211  }
212 
220  std::shared_ptr<VersionInformation> getVersionInformation()
221  {
222  std::scoped_lock lock(version_information_mutex_);
223  return version_information_;
224  }
225 
233  std::shared_ptr<ConfigurationData> getConfigurationData()
234  {
235  std::scoped_lock lock(configuration_data_mutex_);
236  return configuration_data_;
237  }
238 
239 private:
241  std::shared_ptr<KinematicsInfo> kinematics_info_;
242  std::mutex robot_mode_mutex_;
243  std::shared_ptr<RobotModeData> robot_mode_;
245  std::shared_ptr<VersionInformation> version_information_;
246  std::shared_ptr<ConfigurationData> configuration_data_;
248 };
249 
250 } // namespace primary_interface
251 } // namespace urcl
252 
253 #endif // ifndef UR_CLIENT_LIBRARY_PRIMARY_CONSUMER_H_INCLUDED
urcl::primary_interface::ErrorCode::report_level
ReportLevel report_level
Definition: error_code_message.h:55
robot_mode_data.h
urcl::primary_interface::PrimaryConsumer::consume
virtual bool consume(ConfigurationData &pkg) override
Definition: primary_consumer.h:173
urcl::primary_interface::ErrorCode::data_type
uint32_t data_type
Definition: error_code_message.h:56
version_information.h
urcl::primary_interface::RobotMessage::timestamp_
uint64_t timestamp_
Definition: robot_message.h:108
urcl::primary_interface::ErrorCodeMessage
The ErrorCodeMessage class handles the error code messages sent via the primary UR interface.
Definition: error_code_message.h:66
urcl::primary_interface::PrimaryConsumer::consume
virtual bool consume(ErrorCodeMessage &pkg) override
Handle an ErrorCodeMessage.
Definition: primary_consumer.h:121
urcl::primary_interface::PrimaryConsumer::robot_mode_mutex_
std::mutex robot_mode_mutex_
Definition: primary_consumer.h:242
urcl::primary_interface::RobotModeData
This messages contains data about the mode of the robot.
Definition: robot_mode_data.h:45
urcl::primary_interface::VersionMessage::minor_version_
uint8_t minor_version_
Definition: version_message.h:85
urcl::primary_interface::PrimaryConsumer
Primary consumer implementation.
Definition: primary_consumer.h:50
urcl::robotModeString
std::string robotModeString(const RobotMode &mode)
Definition: datatypes.h:102
urcl::primary_interface::PrimaryConsumer::getConfigurationData
std::shared_ptr< ConfigurationData > getConfigurationData()
Get the latest configuration data.
Definition: primary_consumer.h:233
urcl::primary_interface::ErrorCode::to_string
std::string to_string
Definition: error_code_message.h:60
urcl::primary_interface::RobotModeData::robot_mode_
int8_t robot_mode_
Definition: robot_mode_data.h:101
urcl::primary_interface::PrimaryConsumer::consume
virtual bool consume(VersionMessage &pkg) override
Handle a VersionMessage.
Definition: primary_consumer.h:89
urcl::primary_interface::PrimaryConsumer::kinematics_info_
std::shared_ptr< KinematicsInfo > kinematics_info_
Definition: primary_consumer.h:241
urcl
Definition: bin_parser.h:36
urcl::primary_interface::PrimaryConsumer::consume
virtual bool consume(RobotState &msg) override
Consume a RobotState.
Definition: primary_consumer.h:77
urcl::primary_interface::PrimaryConsumer::configuration_data_mutex_
std::mutex configuration_data_mutex_
Definition: primary_consumer.h:247
URCL_LOG_ERROR
#define URCL_LOG_ERROR(...)
Definition: log.h:26
urcl::primary_interface::RobotMessage
The RobotMessage class is a parent class for the different received robot messages.
Definition: robot_message.h:57
urcl::primary_interface::ReportLevel::DEBUG
@ DEBUG
urcl::primary_interface::ErrorCode::data
uint32_t data
Definition: error_code_message.h:57
datatypes.h
urcl::primary_interface::VersionMessage::major_version_
uint8_t major_version_
Definition: version_message.h:84
URCL_LOG_DEBUG
#define URCL_LOG_DEBUG(...)
Definition: log.h:23
urcl::primary_interface::PrimaryConsumer::version_information_
std::shared_ptr< VersionInformation > version_information_
Definition: primary_consumer.h:245
urcl::primary_interface::ErrorCodeMessage::message_argument_
int32_t message_argument_
Definition: error_code_message.h:109
urcl::primary_interface::PrimaryConsumer::PrimaryConsumer
PrimaryConsumer()
Definition: primary_consumer.h:53
urcl::primary_interface::ConfigurationData
The ConfigurationData class handles the configuration data sent via the primary UR interface.
Definition: configuration_data.h:44
urcl::primary_interface::PrimaryConsumer::consume
virtual bool consume(RobotMessage &msg) override
Consume a RobotMessage.
Definition: primary_consumer.h:65
urcl::primary_interface::ErrorCodeMessage::text_
std::string text_
Definition: error_code_message.h:113
urcl::primary_interface::PrimaryConsumer::setErrorCodeMessageCallback
void setErrorCodeMessageCallback(std::function< void(ErrorCode &)> callback_function)
Set callback function which will be triggered whenever error code messages are received.
Definition: primary_consumer.h:186
urcl::primary_interface::PrimaryConsumer::consume
virtual bool consume(KinematicsInfo &pkg) override
Handle a KinematicsInfo.
Definition: primary_consumer.h:107
urcl::primary_interface::KinematicsInfo::toString
virtual std::string toString() const
Produces a human readable representation of the package object.
Definition: kinematics_info.cpp:56
urcl::primary_interface::ReportLevel::INFO
@ INFO
urcl::primary_interface::ReportLevel::DEVL_WARNING
@ DEVL_WARNING
urcl::primary_interface::ErrorCode::text
std::string text
Definition: error_code_message.h:58
urcl::primary_interface::ErrorCodeMessage::toString
virtual std::string toString() const
Produces a human readable representation of the package object.
Definition: error_code_message.cpp:53
urcl::primary_interface::PrimaryConsumer::getRobotModeData
std::shared_ptr< RobotModeData > getRobotModeData()
Get the latest robot mode.
Definition: primary_consumer.h:207
urcl::primary_interface::PrimaryConsumer::~PrimaryConsumer
virtual ~PrimaryConsumer()=default
urcl::primary_interface::PrimaryConsumer::robot_mode_
std::shared_ptr< RobotModeData > robot_mode_
Definition: primary_consumer.h:243
urcl::primary_interface::ErrorCode::timestamp
uint64_t timestamp
Definition: error_code_message.h:59
urcl::primary_interface::ErrorCode::message_code
int32_t message_code
Definition: error_code_message.h:53
urcl::primary_interface::PrimaryConsumer::version_information_mutex_
std::mutex version_information_mutex_
Definition: primary_consumer.h:244
URCL_LOG_INFO
#define URCL_LOG_INFO(...)
Definition: log.h:25
urcl::primary_interface::ErrorCodeMessage::report_level_
ReportLevel report_level_
Definition: error_code_message.h:110
urcl::primary_interface::ErrorCode::message_argument
int32_t message_argument
Definition: error_code_message.h:54
urcl::primary_interface::ErrorCode
Definition: error_code_message.h:51
urcl::primary_interface::ErrorCodeMessage::data_type_
uint32_t data_type_
Definition: error_code_message.h:111
urcl::primary_interface::ReportLevel::DEVL_DEBUG
@ DEVL_DEBUG
urcl::primary_interface::ReportLevel::WARNING
@ WARNING
urcl::primary_interface::VersionMessage
The VersionMessage class handles the version messages sent via the primary UR interface.
Definition: version_message.h:41
abstract_primary_consumer.h
urcl::primary_interface::ReportLevel::DEVL_FAULT
@ DEVL_FAULT
urcl::primary_interface::VersionMessage::svn_version_
int32_t svn_version_
Definition: version_message.h:86
urcl::primary_interface::PrimaryConsumer::error_code_message_callback_
std::function< void(ErrorCode &)> error_code_message_callback_
Definition: primary_consumer.h:240
urcl::primary_interface::ErrorCodeMessage::message_code_
int32_t message_code_
Definition: error_code_message.h:108
urcl::primary_interface::ReportLevel::DEVL_INFO
@ DEVL_INFO
URCL_LOG_WARN
#define URCL_LOG_WARN(...)
Definition: log.h:24
urcl::primary_interface::RobotState
Base class for a RobotState data packages will be used directly.
Definition: robot_state.h:59
urcl::primary_interface::ErrorCodeMessage::data_
uint32_t data_
Definition: error_code_message.h:112
urcl::primary_interface::PrimaryConsumer::configuration_data_
std::shared_ptr< ConfigurationData > configuration_data_
Definition: primary_consumer.h:246
urcl::primary_interface::PrimaryConsumer::getKinematicsInfo
std::shared_ptr< KinematicsInfo > getKinematicsInfo()
Get the kinematics info.
Definition: primary_consumer.h:196
urcl::primary_interface::PrimaryConsumer::getVersionInformation
std::shared_ptr< VersionInformation > getVersionInformation()
Get the latest version information.
Definition: primary_consumer.h:220
urcl::primary_interface::VersionMessage::build_number_
int32_t build_number_
Definition: version_message.h:87
urcl::primary_interface::ReportLevel::DEVL_VIOLATION
@ DEVL_VIOLATION
urcl::primary_interface::KinematicsInfo
This messages contains information about the robot's calibration. The DH parameters are a combination...
Definition: kinematics_info.h:43
urcl::RobotMode
RobotMode
Definition: datatypes.h:36
urcl::primary_interface::PrimaryConsumer::consume
virtual bool consume(RobotModeData &pkg) override
Definition: primary_consumer.h:165
urcl::primary_interface::AbstractPrimaryConsumer
Base consumer for primary packages.
Definition: abstract_primary_consumer.h:50


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