libvisiontransfer  8.0.0
data_channels_example.cpp
1 /*******************************************************************************
2  * Copyright (c) 2019 Nerian Vision GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #include <visiontransfer/deviceenumeration.h>
16 #include <iostream>
17 #include <exception>
18 #include <iomanip>
19 #include <stdio.h>
20 #include <stdlib.h>
21 
22 #include <visiontransfer/datachannelservice.h>
23 
24 #ifdef _WIN32
25 #include <windows.h>
26 #define usleep(X) Sleep(X/1000)
27 #else
28 #include <unistd.h>
29 #endif
30 
31 
32 using namespace visiontransfer;
33 
34 int main(int argc, const char** argv) {
35  try {
36  // Search for SceneScan devices
37  DeviceEnumeration deviceEnum;
38 
39  DeviceEnumeration::DeviceList devices = deviceEnum.discoverDevices();
40  if(devices.size() == 0) {
41  std::cout << "No devices discovered!" << std::endl;
42  return -1;
43  }
44 
45  // Print devices
46  std::cout << "Discovered devices:" << std::endl;
47  for(unsigned int i = 0; i< devices.size(); i++) {
48  std::cout << devices[i].toString() << std::endl;
49  }
50  std::cout << std::endl;
51 
52  std::cout << "Connecting to " << devices[0].toString() << std::endl;
53  // DataChannelService will run asynchronously in the background
54  DataChannelService service(devices[0]);
55 
56  // Allow some grace time for UDP host<->device handshake
57  usleep(250000);
58 
59  std::cout << std::endl <<"Device reports " << (service.imuAvailable()?"an inertial measurement unit.":"inertial measurement unit is not available.") << std::endl << std::endl;
60 
61  if (!service.imuAvailable()) {
62  return 1;
63  }
64 
65  std::vector<TimestampedQuaternion> quaternionBufferData;
66  std::vector<TimestampedVector> vectorBufferData;
67  while(true) {
68  usleep(20000);
69  TimestampedQuaternion quat = service.imuGetRotationQuaternion();
70  TimestampedVector lin = service.imuGetLinearAcceleration();
71  quaternionBufferData = service.imuGetRotationQuaternionSeries();
72  vectorBufferData = service.imuGetLinearAccelerationSeries();
73  std::cout << "Device orientation: " << quat.i() << " " << quat.j() << " " << quat.k() << " " << quat.r() << std::endl;
74  std::cout << " and read orientation time series of size " << quaternionBufferData.size() << std::endl;
75  std::cout << "Linear acceleration: " << lin.x() << " " << lin.y() << " " << lin.z() << std::endl;
76  std::cout << " and read linear accel time series of size " << vectorBufferData.size() << std::endl;
77  std::cout << std::endl;
78  }
79 
80  return 0;
81  } catch(const std::exception& ex) {
82  std::cerr << "Exception occurred: " << ex.what() << std::endl;
83  }
84 
85  return 0;
86 }
87 
Encapsulate a 4D (quaternion) sensor report, containing i, j, k, r, as well as timestamp and status f...
Definition: sensordata.h:66
DeviceList discoverDevices()
Discovers new devices and returns the list of all devices that have been found.
Encapsulate a 3D sensor report, containing X, Y, Z, as well as timestamp and status fields...
Definition: sensordata.h:50
Allows for the discovery of devices in the network.
Nerian Vision Technologies