Visual Servoing Platform version 3.5.0
testOccipitalStructure_Core_imu.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2021 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 http://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
52main()
53{
54 try
55 {
56 double initial_ts, ts;
58 vpColVector imu_vel, imu_acc;
59
60 ST::CaptureSessionSettings settings;
61 settings.source = ST::CaptureSessionSourceId::StructureCore;
62 settings.structureCore.depthEnabled = true;
63 settings.structureCore.visibleEnabled = true;
64 settings.structureCore.accelerometerEnabled = true;
65 settings.structureCore.gyroscopeEnabled = true;
66 settings.structureCore.imuUpdateRate = ST::StructureCoreIMUUpdateRate::AccelAndGyro_1000Hz;
67
68 sc.open( settings );
69
70 // Create plotters
71 vpPlot acceleration_plotter( 1, 400, 800, 10, 10, "Accelerations" );
72 vpPlot rotationRate_plotter( 1, 400, 800, 10, 450, "Rotation rates" );
73 acceleration_plotter.initGraph( 0, 3 );
74 rotationRate_plotter.initGraph( 0, 3 );
75
76 acceleration_plotter.setColor( 0, 0, vpColor::blue );
77 acceleration_plotter.setColor( 0, 1, vpColor::red );
78 acceleration_plotter.setColor( 0, 2, vpColor::green );
79 rotationRate_plotter.setColor( 0, 0, vpColor::blue );
80 rotationRate_plotter.setColor( 0, 1, vpColor::red );
81 rotationRate_plotter.setColor( 0, 2, vpColor::green );
82
83 acceleration_plotter.plot( 0, 0, 0, 0 );
84 acceleration_plotter.plot( 0, 1, 0, 0 );
85 acceleration_plotter.plot( 0, 2, 0, 0 );
86 rotationRate_plotter.plot( 0, 0, 0, 0 );
87 rotationRate_plotter.plot( 0, 1, 0, 0 );
88 rotationRate_plotter.plot( 0, 2, 0, 0 );
89
90 acceleration_plotter.setLegend( 0, 0, "X axis" );
91 acceleration_plotter.setLegend( 0, 1, "Y axis" );
92 acceleration_plotter.setLegend( 0, 2, "Z axis" );
93 rotationRate_plotter.setLegend( 0, 0, "X axis" );
94 rotationRate_plotter.setLegend( 0, 1, "Y axis" );
95 rotationRate_plotter.setLegend( 0, 2, "Z axis" );
96
97 sc.getIMUData( &imu_vel, &imu_acc, &initial_ts );
98
99 bool quit = false;
100 while ( !quit )
101 {
102 sc.getIMUData( &imu_vel, &imu_acc, &ts );
103
104 acceleration_plotter.plot( 0, ts - initial_ts, imu_acc );
105 rotationRate_plotter.plot( 0, ts - initial_ts, imu_vel );
106 if ( vpDisplay::getClick( acceleration_plotter.I, false ) ||
107 vpDisplay::getClick( rotationRate_plotter.I, false ) )
108 {
109 quit = true;
110 }
111 }
112 }
113 catch ( const vpException &e )
114 {
115 std::cerr << "Structure SDK error " << e.what() << std::endl;
116 }
117 catch ( const std::exception &e )
118 {
119 std::cerr << e.what() << std::endl;
120 }
121
122 return EXIT_SUCCESS;
123}
124#else
125int
126main()
127{
128#if !defined( VISP_HAVE_OCCIPITAL_STRUCTURE )
129 std::cout << "You do not have Occipital Structure SDK functionality enabled..." << std::endl;
130 std::cout << "Tip:" << std::endl;
131 std::cout << "- Install libStructure, configure again ViSP using cmake and build again this example" << std::endl;
132 return EXIT_SUCCESS;
133#elif ( VISP_CXX_STANDARD < VISP_CXX_STANDARD_11 )
134 std::cout << "You do not build ViSP with c++11 or higher compiler flag" << std::endl;
135 std::cout << "Tip:" << std::endl;
136 std::cout << "- Configure ViSP again using cmake -DUSE_CXX_STANDARD=11, and build again this example" << std::endl;
137#endif
138 return EXIT_SUCCESS;
139}
140#endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
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 emited by ViSP classes.
Definition: vpException.h:72
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:116