Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
testOccipitalStructure_Core_imu.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * IMU data acquisition with Structure Core sensor and libStructure.
32  */
33 
40 #include <iostream>
41 
42 #include <visp3/core/vpConfig.h>
43 
44 #if defined(VISP_HAVE_OCCIPITAL_STRUCTURE) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
45 
46 #include <visp3/gui/vpPlot.h>
47 #include <visp3/sensor/vpOccipitalStructure.h>
48 
49 int main()
50 {
51 #ifdef ENABLE_VISP_NAMESPACE
52  using namespace VISP_NAMESPACE_NAME;
53 #endif
54  try {
55  double initial_ts, ts;
57  vpColVector imu_vel, imu_acc;
58 
59  ST::CaptureSessionSettings settings;
60  settings.source = ST::CaptureSessionSourceId::StructureCore;
61  settings.structureCore.depthEnabled = true;
62  settings.structureCore.visibleEnabled = true;
63  settings.structureCore.accelerometerEnabled = true;
64  settings.structureCore.gyroscopeEnabled = true;
65  settings.structureCore.imuUpdateRate = ST::StructureCoreIMUUpdateRate::AccelAndGyro_1000Hz;
66 
67  sc.open(settings);
68 
69  // Create plotters
70  vpPlot acceleration_plotter(1, 400, 800, 10, 10, "Accelerations");
71  vpPlot rotationRate_plotter(1, 400, 800, 10, 450, "Rotation rates");
72  acceleration_plotter.initGraph(0, 3);
73  rotationRate_plotter.initGraph(0, 3);
74 
75  acceleration_plotter.setColor(0, 0, vpColor::blue);
76  acceleration_plotter.setColor(0, 1, vpColor::red);
77  acceleration_plotter.setColor(0, 2, vpColor::green);
78  rotationRate_plotter.setColor(0, 0, vpColor::blue);
79  rotationRate_plotter.setColor(0, 1, vpColor::red);
80  rotationRate_plotter.setColor(0, 2, vpColor::green);
81 
82  acceleration_plotter.plot(0, 0, 0, 0);
83  acceleration_plotter.plot(0, 1, 0, 0);
84  acceleration_plotter.plot(0, 2, 0, 0);
85  rotationRate_plotter.plot(0, 0, 0, 0);
86  rotationRate_plotter.plot(0, 1, 0, 0);
87  rotationRate_plotter.plot(0, 2, 0, 0);
88 
89  acceleration_plotter.setLegend(0, 0, "X axis");
90  acceleration_plotter.setLegend(0, 1, "Y axis");
91  acceleration_plotter.setLegend(0, 2, "Z axis");
92  rotationRate_plotter.setLegend(0, 0, "X axis");
93  rotationRate_plotter.setLegend(0, 1, "Y axis");
94  rotationRate_plotter.setLegend(0, 2, "Z axis");
95 
96  sc.getIMUData(&imu_vel, &imu_acc, &initial_ts);
97 
98  bool quit = false;
99  while (!quit) {
100  sc.getIMUData(&imu_vel, &imu_acc, &ts);
101 
102  acceleration_plotter.plot(0, ts - initial_ts, imu_acc);
103  rotationRate_plotter.plot(0, ts - initial_ts, imu_vel);
104  if (vpDisplay::getClick(acceleration_plotter.I, false) || vpDisplay::getClick(rotationRate_plotter.I, false)) {
105  quit = true;
106  }
107  }
108  }
109  catch (const vpException &e) {
110  std::cerr << "Structure SDK error " << e.what() << std::endl;
111  }
112  catch (const std::exception &e) {
113  std::cerr << e.what() << std::endl;
114  }
115 
116  return EXIT_SUCCESS;
117 }
118 #else
119 int main()
120 {
121 #if !defined( VISP_HAVE_OCCIPITAL_STRUCTURE )
122  std::cout << "You do not have Occipital Structure SDK functionality enabled..." << std::endl;
123  std::cout << "Tip:" << std::endl;
124  std::cout << "- Install libStructure, configure again ViSP using cmake and build again this example" << std::endl;
125  return EXIT_SUCCESS;
126 #elif ( VISP_CXX_STANDARD < VISP_CXX_STANDARD_11 )
127  std::cout << "You do not build ViSP with c++11 or higher compiler flag" << std::endl;
128  std::cout << "Tip:" << std::endl;
129  std::cout << "- Configure ViSP again using cmake -DUSE_CXX_STANDARD=11, and build again this example" << std::endl;
130 #endif
131  return EXIT_SUCCESS;
132 }
133 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
static const vpColor red
Definition: vpColor.h:217
static const vpColor blue
Definition: vpColor.h:223
static const vpColor green
Definition: vpColor.h:220
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
error that can be emitted by ViSP classes.
Definition: vpException.h:60
const char * what() const
Definition: vpException.cpp:71
void getIMUData(vpColVector *imu_vel, vpColVector *imu_acc, double *ts=nullptr)
bool open(const ST::CaptureSessionSettings &settings)
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:112