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