primary_client.h
Go to the documentation of this file.
1 // -- BEGIN LICENSE BLOCK ----------------------------------------------
2 // Copyright © 2024-2025 Ocado Group
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 #ifndef UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED
32 #define UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED
33 
34 #include <chrono>
35 #include <memory>
36 #include <deque>
37 
45 
46 namespace urcl
47 {
48 namespace primary_interface
49 {
51 {
52 public:
53  PrimaryClient() = delete;
54  PrimaryClient(const std::string& robot_ip, comm::INotifier& notifier);
56 
62  void addPrimaryConsumer(std::shared_ptr<comm::IConsumer<PrimaryPackage>> primary_consumer);
63 
69  void removePrimaryConsumer(std::shared_ptr<comm::IConsumer<PrimaryPackage>> primary_consumer);
70  void start(const size_t max_connection_attempts = 0,
71  const std::chrono::milliseconds reconnection_timeout = urcl::comm::TCPSocket::DEFAULT_RECONNECTION_TIME);
72  void stop();
73 
78  std::deque<ErrorCode> getErrorCodes();
79 
89  bool sendScript(const std::string& program);
90 
91  bool checkCalibration(const std::string& checksum);
92 
103  void commandPowerOn(const bool validate = true, const std::chrono::milliseconds timeout = std::chrono::seconds(30));
104 
115  void commandPowerOff(const bool validate = true, const std::chrono::milliseconds timeout = std::chrono::seconds(30));
116 
128  void commandBrakeRelease(const bool validate = true,
129  const std::chrono::milliseconds timeout = std::chrono::seconds(30));
130 
143  void commandUnlockProtectiveStop(const bool validate = true,
144  const std::chrono::milliseconds timeout = std::chrono::milliseconds(5000));
145 
156  void commandStop(const bool validate = true, const std::chrono::milliseconds timeout = std::chrono::seconds(2));
157 
165  {
166  std::shared_ptr<RobotModeData> robot_mode_data = consumer_->getRobotModeData();
167  if (robot_mode_data == nullptr)
168  {
169  return RobotMode::UNKNOWN;
170  }
171  return static_cast<RobotMode>(consumer_->getRobotModeData()->robot_mode_);
172  }
173 
188  std::shared_ptr<VersionInformation>
189  getRobotVersion(bool wait_for_message = true, const std::chrono::milliseconds timeout = std::chrono::seconds(2));
190 
198  std::shared_ptr<RobotModeData> getRobotModeData()
199  {
200  return consumer_->getRobotModeData();
201  }
202 
212  {
213  std::shared_ptr<RobotModeData> robot_mode_data = consumer_->getRobotModeData();
214  if (robot_mode_data == nullptr)
215  {
216  throw UrException("Robot mode data is a nullptr. Probably it hasn't been received, yet.");
217  }
218  return robot_mode_data->is_protective_stopped_;
219  }
220 
228  std::shared_ptr<ConfigurationData> getConfigurationData()
229  {
230  return consumer_->getConfigurationData();
231  }
232 
239 
240 private:
248  bool reconnectStream();
249 
250  // The function is called whenever an error code message is received
251  void errorMessageCallback(ErrorCode& code);
252 
254  std::shared_ptr<PrimaryConsumer> consumer_;
255  std::unique_ptr<comm::MultiConsumer<PrimaryPackage>> multi_consumer_;
256 
258 
260  std::unique_ptr<comm::URProducer<PrimaryPackage>> prod_;
261  std::unique_ptr<comm::Pipeline<PrimaryPackage>> pipeline_;
262 
264  std::deque<ErrorCode> error_code_queue_;
265 };
266 
267 } // namespace primary_interface
268 } // namespace urcl
269 
270 #endif // ifndef UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED
urcl::primary_interface::PrimaryClient::addPrimaryConsumer
void addPrimaryConsumer(std::shared_ptr< comm::IConsumer< PrimaryPackage >> primary_consumer)
Adds a primary consumer to the list of consumers.
Definition: primary_client.cpp:78
urcl::primary_interface::PrimaryClient::stream_
comm::URStream< PrimaryPackage > stream_
Definition: primary_client.h:259
pipeline.h
urcl::primary_interface::PrimaryClient::multi_consumer_
std::unique_ptr< comm::MultiConsumer< PrimaryPackage > > multi_consumer_
Definition: primary_client.h:255
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::primary_interface::PrimaryClient::parser_
PrimaryParser parser_
Definition: primary_client.h:253
urcl::primary_interface::PrimaryClient::getConfigurationData
std::shared_ptr< ConfigurationData > getConfigurationData()
Get the latest configuration data.
Definition: primary_client.h:228
urcl::primary_interface::PrimaryClient::checkCalibration
bool checkCalibration(const std::string &checksum)
Definition: primary_client.cpp:152
urcl::primary_interface::PrimaryClient::sendScript
bool sendScript(const std::string &program)
Sends a custom script program to the robot.
Definition: primary_client.cpp:103
primary_consumer.h
urcl::primary_interface::PrimaryClient::pipeline_
std::unique_ptr< comm::Pipeline< PrimaryPackage > > pipeline_
Definition: primary_client.h:261
urcl::primary_interface::PrimaryClient::error_code_queue_
std::deque< ErrorCode > error_code_queue_
Definition: primary_client.h:264
urcl
Definition: bin_parser.h:36
urcl::primary_interface::PrimaryClient::getRobotModeData
std::shared_ptr< RobotModeData > getRobotModeData()
Get the latest robot mode data.
Definition: primary_client.h:198
urcl::primary_interface::PrimaryClient::stop
void stop()
Definition: primary_client.cpp:72
urcl::RobotMode::UNKNOWN
@ UNKNOWN
urcl::primary_interface::PrimaryClient::getRobotType
RobotType getRobotType()
Get the Robot type.
Definition: primary_client.cpp:282
urcl::primary_interface::PrimaryParser
The primary specific parser. Interprets a given byte stream as serialized primary packages and parses...
Definition: primary_parser.h:43
urcl::primary_interface::PrimaryClient::commandBrakeRelease
void commandBrakeRelease(const bool validate=true, const std::chrono::milliseconds timeout=std::chrono::seconds(30))
Commands the robot to release the brakes.
Definition: primary_client.cpp:204
urcl::comm::TCPSocket::DEFAULT_RECONNECTION_TIME
static constexpr std::chrono::milliseconds DEFAULT_RECONNECTION_TIME
Definition: tcp_socket.h:70
primary_package.h
urcl::primary_interface::PrimaryClient::commandStop
void commandStop(const bool validate=true, const std::chrono::milliseconds timeout=std::chrono::seconds(2))
Definition: primary_client.cpp:242
urcl::UrException
Our base class for exceptions. Specialized exceptions should inherit from those.
Definition: exceptions.h:53
urcl::primary_interface::PrimaryClient::commandUnlockProtectiveStop
void commandUnlockProtectiveStop(const bool validate=true, const std::chrono::milliseconds timeout=std::chrono::milliseconds(5000))
Commands the robot to unlock the protective stop.
Definition: primary_client.cpp:223
urcl::comm::INotifier
Parent class for notifiers.
Definition: pipeline.h:253
urcl::primary_interface::PrimaryClient::getRobotMode
RobotMode getRobotMode()
Get the latest robot mode.
Definition: primary_client.h:164
urcl::primary_interface::PrimaryClient::errorMessageCallback
void errorMessageCallback(ErrorCode &code)
Definition: primary_client.cpp:88
producer.h
stream.h
urcl::primary_interface::PrimaryClient
Definition: primary_client.h:50
urcl::primary_interface::PrimaryClient::prod_
std::unique_ptr< comm::URProducer< PrimaryPackage > > prod_
Definition: primary_client.h:260
urcl::primary_interface::PrimaryClient::getRobotVersion
std::shared_ptr< VersionInformation > getRobotVersion(bool wait_for_message=true, const std::chrono::milliseconds timeout=std::chrono::seconds(2))
Get the robot's software version as Major.Minor.Bugfix.
Definition: primary_client.cpp:271
urcl::primary_interface::PrimaryClient::error_code_queue_mutex_
std::mutex error_code_queue_mutex_
Definition: primary_client.h:263
urcl::primary_interface::PrimaryClient::notifier_
comm::INotifier notifier_
Definition: primary_client.h:257
urcl::primary_interface::PrimaryClient::isRobotProtectiveStopped
bool isRobotProtectiveStopped()
Query if the robot is protective stopped.
Definition: primary_client.h:211
urcl::primary_interface::ErrorCode
Definition: error_code_message.h:51
urcl::primary_interface::PrimaryClient::~PrimaryClient
~PrimaryClient()
Definition: primary_client.cpp:59
abstract_primary_consumer.h
urcl::primary_interface::PrimaryClient::PrimaryClient
PrimaryClient()=delete
urcl::comm::IConsumer< PrimaryPackage >
urcl::primary_interface::PrimaryClient::consumer_
std::shared_ptr< PrimaryConsumer > consumer_
Definition: primary_client.h:254
urcl::primary_interface::PrimaryClient::removePrimaryConsumer
void removePrimaryConsumer(std::shared_ptr< comm::IConsumer< PrimaryPackage >> primary_consumer)
Remove a primary consumer from the list of consumers.
Definition: primary_client.cpp:83
urcl::primary_interface::PrimaryClient::commandPowerOn
void commandPowerOn(const bool validate=true, const std::chrono::milliseconds timeout=std::chrono::seconds(30))
Commands the robot to power on.
Definition: primary_client.cpp:165
urcl::primary_interface::PrimaryClient::start
void start(const size_t max_connection_attempts=0, const std::chrono::milliseconds reconnection_timeout=urcl::comm::TCPSocket::DEFAULT_RECONNECTION_TIME)
Definition: primary_client.cpp:65
urcl::primary_interface::PrimaryClient::getErrorCodes
std::deque< ErrorCode > getErrorCodes()
Retrieves previously raised error codes from PrimaryClient. After calling this, recorded errors will ...
Definition: primary_client.cpp:94
urcl::primary_interface::PrimaryClient::commandPowerOff
void commandPowerOff(const bool validate=true, const std::chrono::milliseconds timeout=std::chrono::seconds(30))
Commands the robot to power off.
Definition: primary_client.cpp:185
urcl::primary_interface::PrimaryClient::reconnectStream
bool reconnectStream()
Reconnects the primary stream used to send program to the robot.
Definition: primary_client.cpp:139
primary_parser.h
urcl::RobotMode
RobotMode
Definition: datatypes.h:36
urcl::RobotType
RobotType
Definition: datatypes.h:90


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