primary_pipeline.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 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 
32 
33 using namespace urcl;
34 
35 // In a real-world example it would be better to get those values from command line parameters / a better configuration
36 // system such as Boost.Program_options
37 const std::string DEFAULT_ROBOT_IP = "192.168.56.101";
38 
39 int main(int argc, char* argv[])
40 {
41  // Set the loglevel to info get print out the DH parameters
43 
44  // Parse the ip arguments if given
45  std::string robot_ip = DEFAULT_ROBOT_IP;
46  if (argc > 1)
47  {
48  robot_ip = std::string(argv[1]);
49  }
50 
51  // Parse how many seconds to run
52  int second_to_run = -1;
53  if (argc > 2)
54  {
55  second_to_run = std::stoi(argv[2]);
56  }
57 
58  // First of all, we need a stream that connects to the robot
60 
61  // This will parse the primary packages
63 
64  // The producer needs both, the stream and the parser to fully work
65  comm::URProducer<primary_interface::PrimaryPackage> prod(primary_stream, parser);
66  prod.setupProducer();
67 
68  // The shell consumer will print the package contents to the shell
69  std::unique_ptr<comm::IConsumer<primary_interface::PrimaryPackage>> consumer;
71 
72  // The notifer will be called at some points during connection setup / loss. This isn't fully
73  // implemented atm.
74  comm::INotifier notifier;
75 
76  // Now that we have all components, we can create and start the pipeline to run it all.
77  comm::Pipeline<primary_interface::PrimaryPackage> pipeline(prod, consumer.get(), "Pipeline", notifier);
78  pipeline.run();
79 
80  // Package contents will be printed while not being interrupted
81  // Note: Packages for which the parsing isn't implemented, will only get their raw bytes printed.
82  do
83  {
84  std::this_thread::sleep_for(std::chrono::seconds(second_to_run));
85  } while (second_to_run < 0);
86  return 0;
87 }
The ShellConsumer class is a simple consumer that writes a readable representation to the logging inf...
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...
const std::string DEFAULT_ROBOT_IP
void setLogLevel(LogLevel level)
Set log level this will disable messages with lower log level.
Definition: log.cpp:101
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
A general producer for URPackages. Implements funcionality to produce packages by reading and parsing...
Definition: producer.h:40


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