rtde_parser.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019, FZI Forschungszentrum Informatik (refactor)
3  *
4  * Copyright 2017, 2018 Simon Rasmussen (refactor)
5  *
6  * Copyright 2015, 2016 Thomas Timm Andersen (original version)
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #pragma once
22 #include <vector>
26 
36 
37 namespace urcl
38 {
39 namespace rtde_interface
40 {
45 class RTDEParser : public comm::Parser<RTDEPackage>
46 {
47 public:
48  RTDEParser() = delete;
54  RTDEParser(const std::vector<std::string>& recipe) : recipe_(recipe), protocol_version_(1)
55  {
56  }
57  virtual ~RTDEParser() = default;
58 
68  bool parse(comm::BinParser& bp, std::vector<std::unique_ptr<RTDEPackage>>& results)
69 
70  {
72  PackageType type;
73  bp.parse(size);
74  bp.parse(type);
75 
76  if (!bp.checkSize(size - sizeof(size) - sizeof(type)))
77  {
78  URCL_LOG_ERROR("Buffer len shorter than expected packet length");
79  return false;
80  }
81 
82  switch (type)
83  {
85  {
86  std::unique_ptr<RTDEPackage> package(new DataPackage(recipe_, protocol_version_));
87 
88  if (!package->parseWith(bp))
89  {
90  URCL_LOG_ERROR("Package parsing of type %d failed!", static_cast<int>(type));
91  return false;
92  }
93  results.push_back(std::move(package));
94  break;
95  }
96  default:
97  {
98  std::unique_ptr<RTDEPackage> package(packageFromType(type));
99  if (!package->parseWith(bp))
100  {
101  URCL_LOG_ERROR("Package parsing of type %d failed!", static_cast<int>(type));
102  return false;
103  }
104 
105  results.push_back(std::move(package));
106  break;
107  }
108  }
109  if (!bp.empty())
110  {
111  URCL_LOG_ERROR("Package of type %d was not parsed completely!", static_cast<int>(type));
112  bp.debug();
113  return false;
114  }
115 
116  return true;
117  }
118 
119  void setProtocolVersion(uint16_t protocol_version)
120  {
121  protocol_version_ = protocol_version;
122  }
123 
124 private:
125  std::vector<std::string> recipe_;
127  {
128  switch (type)
129  {
131  return new TextMessage(protocol_version_);
132  break;
134  return new GetUrcontrolVersion;
135  break;
137  return new RequestProtocolVersion;
138  break;
140  return new ControlPackagePause;
141  break;
143  return new ControlPackageSetupInputs;
144  break;
147  break;
149  return new ControlPackageStart;
150  break;
151  default:
152  return new RTDEPackage(type);
153  }
154  }
156 };
157 
158 } // namespace rtde_interface
159 } // namespace urcl
urcl::rtde_interface::PackageType::RTDE_CONTROL_PACKAGE_START
@ RTDE_CONTROL_PACKAGE_START
get_urcontrol_version.h
data_package.h
pipeline.h
bin_parser.h
urcl::rtde_interface::ControlPackageStart
This class handles the robot's response to a requested start in RTDE data package communication.
Definition: control_package_start.h:42
urcl::rtde_interface::ControlPackageSetupInputs
This class handles the robot's response to a requested input recipe setup.
Definition: control_package_setup_inputs.h:43
urcl::rtde_interface::TextMessage
This class handles RTDE text messages sent by the robot.
Definition: text_message.h:41
urcl::rtde_interface::DataPackage
The DataPackage class handles communication in the form of RTDE data packages both to and from the ro...
Definition: data_package.h:60
control_package_setup_outputs.h
urcl::rtde_interface::ControlPackagePause
This class handles the robot's response to a requested stop in RTDE data package communication.
Definition: control_package_pause.h:42
control_package_setup_inputs.h
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
urcl::rtde_interface::PackageType::RTDE_CONTROL_PACKAGE_PAUSE
@ RTDE_CONTROL_PACKAGE_PAUSE
URCL_LOG_ERROR
#define URCL_LOG_ERROR(...)
Definition: log.h:26
urcl::comm::Parser
The parser is a general paser. The namsepace rtde_interface and primary_interface both iclude classes...
Definition: parser.h:36
urcl::rtde_interface::RTDEParser::setProtocolVersion
void setProtocolVersion(uint16_t protocol_version)
Definition: rtde_parser.h:119
urcl::rtde_interface::PackageType::RTDE_DATA_PACKAGE
@ RTDE_DATA_PACKAGE
urcl::rtde_interface::PackageType::RTDE_REQUEST_PROTOCOL_VERSION
@ RTDE_REQUEST_PROTOCOL_VERSION
urcl::rtde_interface::RTDEParser::parse
bool parse(comm::BinParser &bp, std::vector< std::unique_ptr< RTDEPackage >> &results)
Uses the given BinParser to create package objects from the contained serialization.
Definition: rtde_parser.h:68
urcl::rtde_interface::PackageType::RTDE_CONTROL_PACKAGE_SETUP_INPUTS
@ RTDE_CONTROL_PACKAGE_SETUP_INPUTS
urcl::comm::BinParser::empty
bool empty()
Checks if no unparsed bytes remain in the buffer.
Definition: bin_parser.h:362
urcl::rtde_interface::RTDEParser::protocol_version_
uint16_t protocol_version_
Definition: rtde_parser.h:155
urcl::rtde_interface::RTDEParser::packageFromType
RTDEPackage * packageFromType(PackageType type)
Definition: rtde_parser.h:126
urcl::rtde_interface::RequestProtocolVersion
This class handles the robot's response after trying to set the used RTDE protocol version.
Definition: request_protocol_version.h:42
urcl::rtde_interface::RTDEPackage
Definition: rtde_package.h:43
text_message.h
urcl::rtde_interface::PackageType::RTDE_GET_URCONTROL_VERSION
@ RTDE_GET_URCONTROL_VERSION
urcl::rtde_interface::PackageType
PackageType
Possible package types.
Definition: rtde/package_header.h:45
urcl::rtde_interface::RTDEParser::RTDEParser
RTDEParser(const std::vector< std::string > &recipe)
Creates a new RTDEParser object, registering the used recipe.
Definition: rtde_parser.h:54
urcl::rtde_interface::RTDEParser::RTDEParser
RTDEParser()=delete
urcl::comm::BinParser::checkSize
bool checkSize(size_t bytes)
Checks if at least a given number of bytes is still remaining unparsed in the buffer.
Definition: bin_parser.h:339
parser.h
urcl::rtde_interface::RTDEParser::recipe_
std::vector< std::string > recipe_
Definition: rtde_parser.h:125
package_header.h
urcl::rtde_interface::PackageHeader::_package_size_type
uint16_t _package_size_type
Definition: rtde/package_header.h:65
urcl::rtde_interface::RTDEParser::~RTDEParser
virtual ~RTDEParser()=default
urcl::rtde_interface::PackageType::RTDE_CONTROL_PACKAGE_SETUP_OUTPUTS
@ RTDE_CONTROL_PACKAGE_SETUP_OUTPUTS
urcl::rtde_interface::ControlPackageSetupOutputs
This class handles the robot's response to a requested output recipe setup.
Definition: control_package_setup_outputs.h:44
control_package_start.h
urcl::comm::BinParser::parse
void parse(T &val)
Parses the next bytes as given type.
Definition: bin_parser.h:139
urcl::rtde_interface::PackageType::RTDE_TEXT_MESSAGE
@ RTDE_TEXT_MESSAGE
urcl::comm::BinParser
The BinParser class handles a byte buffer and functionality to iteratively parse the content.
Definition: bin_parser.h:44
request_protocol_version.h
control_package_pause.h
urcl::rtde_interface::GetUrcontrolVersion
This class handles the package detailing the UR control version sent by the robot.
Definition: get_urcontrol_version.h:42
urcl::comm::BinParser::debug
void debug()
Logs debugging information about the BinParser object.
Definition: bin_parser.h:370


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