driver_example.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014, Pepperl+Fuchs GmbH, Mannheim
2 // Copyright (c) 2014, Denis Dillenberger
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice, this
9 // list of conditions and the following disclaimer.
10 //
11 // * Redistributions in binary form must reproduce the above copyright notice, this
12 // list of conditions and the following disclaimer in the documentation and/or
13 // other materials provided with the distribution.
14 //
15 // * Neither the name of Pepperl+Fuchs nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #include <iostream>
31 #include <string>
32 #include <thread>
33 #include <chrono>
35 
36 int main(int argc, char **argv)
37 {
38  std::cout << "Hello world!" << std::endl;
39  std::string scanner_ip("192.168.1.71");
41 
42  for( int i=0; i<2; i++ )
43  {
44  std::cout << "Connecting to scanner at " << scanner_ip << " ... ";
45  if (driver.connect(scanner_ip, 80))
46  std::cout << "OK" << std::endl;
47  else
48  {
49  std::cout << "FAILED!" << std::endl;
50  std::cerr << "Connection to scanner at " << scanner_ip << " failed!" << std::endl;
51  return 1;
52  }
53 
54  driver.setScanFrequency(35);
55  driver.setSamplesPerScan(3600);
56  auto params = driver.getParameters();
57  std::cout << "Current scanner settings:" << std::endl;
58  std::cout << "============================================================" << std::endl;
59  for (const auto& p : params)
60  std::cout << p.first << " : " << p.second << std::endl;
61  std::cout << "============================================================" << std::endl;
62 
63 
64  // Start capturing scanner data
65  //-------------------------------------------------------------------------
66  std::cout << "Starting capturing: ";
67  if (driver.startCapturingUDP())
68  std::cout << "OK" << std::endl;
69  else
70  {
71  std::cout << "FAILED!" << std::endl;
72  return 1;
73  }
74 
75  for (int s = 0; s < 5; s++)
76  {
77  std::this_thread::sleep_for(std::chrono::seconds(1));
78  int scans_captured = 0;
79  int scans_available = driver.getFullScansAvailable();
80  for (int i = 0; i < scans_available; i++)
81  {
82  auto scandata = driver.getScan();
83  scans_captured++;
84  }
85  std::cout << "Received " << scans_captured << " from scanner" << std::endl;
86  }
87 
88  std::cout << "Trying to stop capture" << std::endl;
89 
90  std::cout << "Stopping capture: " << driver.stopCapturing() << std::endl;
91 
92  }
93 
94  std::cout << "Goodbye world!" << std::endl;
95  return 0;
96 }
Driver for the laserscanner R2000 of Pepperl+Fuchs.
Definition: r2000_driver.h:47
XmlRpcServer s
bool setSamplesPerScan(unsigned int samples)
bool setScanFrequency(unsigned int frequency)
bool connect(const std::string hostname, int port=80)
std::size_t getFullScansAvailable() const
Get the total number of fully received laserscans available.
const std::map< std::string, std::string > & getParameters()
int main(int argc, char **argv)


pepperl_fuchs_r2000
Author(s): Denis Dillenberger
autogenerated on Mon Jun 10 2019 14:12:48