primary_pipeline_calibration.cpp
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 2022 Universal Robots A/S
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 
23 
24 using namespace urcl;
25 
26 class CalibrationConsumer : public urcl::comm::IConsumer<urcl::primary_interface::PrimaryPackage>
27 {
28 public:
29  CalibrationConsumer() : calibrated_(0), have_received_data(false)
30  {
31  }
32  virtual ~CalibrationConsumer() = default;
33 
34  virtual bool consume(std::shared_ptr<urcl::primary_interface::PrimaryPackage> product)
35  {
36  auto kin_info = std::dynamic_pointer_cast<urcl::primary_interface::KinematicsInfo>(product);
37  if (kin_info != nullptr)
38  {
39  URCL_LOG_INFO("%s", product->toString().c_str());
40  calibrated_ = kin_info->calibration_status_;
41  have_received_data = true;
42  }
43  return true;
44  }
45 
46  bool isCalibrated() const
47  {
48  const uint32_t LINEARIZED = 2;
49  return calibrated_ == LINEARIZED;
50  }
51 
53  {
54  return have_received_data;
55  }
56 
57 private:
58  uint32_t calibrated_;
60 };
61 
62 // In a real-world example it would be better to get those values from command line parameters / a better configuration
63 // system such as Boost.Program_options
64 const std::string DEFAULT_ROBOT_IP = "192.168.56.101";
65 
66 int main(int argc, char* argv[])
67 {
68  // Set the loglevel to info get print out the DH parameters
70 
71  // Parse the ip arguments if given
72  std::string robot_ip = DEFAULT_ROBOT_IP;
73  if (argc > 1)
74  {
75  robot_ip = std::string(argv[1]);
76  }
77 
78  // First of all, we need a stream that connects to the robot
80 
81  // This will parse the primary packages
83 
84  // The producer needs both, the stream and the parser to fully work
85  comm::URProducer<primary_interface::PrimaryPackage> prod(primary_stream, parser);
86  prod.setupProducer();
87 
88  // The calibration consumer will print the package contents to the shell
89  CalibrationConsumer calib_consumer;
90 
91  // The notifer will be called at some points during connection setup / loss. This isn't fully
92  // implemented atm.
93  comm::INotifier notifier;
94 
95  // Now that we have all components, we can create and start the pipeline to run it all.
96  comm::Pipeline<primary_interface::PrimaryPackage> calib_pipeline(prod, &calib_consumer, "Pipeline", notifier);
97  calib_pipeline.run();
98 
99  // Package contents will be printed while not being interrupted
100  // Note: Packages for which the parsing isn't implemented, will only get their raw bytes printed.
101  while (!calib_consumer.calibrationStatusReceived())
102  {
103  std::this_thread::sleep_for(std::chrono::seconds(1));
104  }
105 
106  if (calib_consumer.isCalibrated())
107  {
108  printf("The robot on IP: %s is calibrated\n", robot_ip.c_str());
109  }
110  else
111  {
112  printf("The robot controller on IP: %s do not have a valid calibration\n", robot_ip.c_str());
113  printf("Remeber to turn on the robot to get calibration stored on the robot!\n");
114  }
115 
116  return 0;
117 }
void setupProducer() override
Triggers the stream to connect to the robot.
Definition: producer.h:63
void run()
Starts the producer and, if existing, the consumer in new threads.
Definition: pipeline.h:300
The stream is an abstraction of the TCPSocket that offers reading a full UR data package out of the s...
Definition: stream.h:42
The primary specific parser. Interprets a given byte stream as serialized primary packages and parses...
Parent class for for arbitrary consumers.
Definition: pipeline.h:43
void setLogLevel(LogLevel level)
Set log level this will disable messages with lower log level.
Definition: log.cpp:101
This messages contains information about the robot&#39;s calibration. The DH parameters are a combination...
Parent class for notifiers.
Definition: pipeline.h:210
int main(int argc, char *argv[])
The Pipepline manages the production and optionally consumption of packages. Cyclically the producer ...
Definition: pipeline.h:235
#define URCL_LOG_INFO(...)
Definition: log.h:25
A general producer for URPackages. Implements funcionality to produce packages by reading and parsing...
Definition: producer.h:40
const std::string DEFAULT_ROBOT_IP
virtual bool consume(std::shared_ptr< urcl::primary_interface::PrimaryPackage > product)
Consumes a product, utilizing it&#39;s contents.


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Tue Jul 4 2023 02:09:47