Visual Servoing Platform version 3.5.0
testRealSense2_T265_imu.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2019 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 * Acquisition of IMU data with RealSense T265 sensor and librealsense2.
33 *
34 *****************************************************************************/
35
43#include <iostream>
44
45#include <visp3/gui/vpDisplayX.h>
46#include <visp3/core/vpMeterPixelConversion.h>
47#include <visp3/sensor/vpRealSense2.h>
48
49#if defined(VISP_HAVE_REALSENSE2) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && \
50 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && \
51 (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))
52
53int main()
54{
55 vpColVector imu_acc, imu_vel;
56
57 try {
58 vpRealSense2 rs;
59 std::string product_line = rs.getProductLine();
60 std::cout << "Product line: " << product_line << std::endl;
61
62 if (product_line != "T200") {
63 std::cout << "This example doesn't support devices that are not part of T200 product line family !" << std::endl;
64 return EXIT_SUCCESS;
65 }
66 rs2::config config;
67 config.enable_stream(RS2_STREAM_ACCEL);
68 config.enable_stream(RS2_STREAM_GYRO);
69 rs.open(config);
70
71 while (true) {
72
73 rs.getIMUData(&imu_acc, &imu_vel, NULL);
74
75 std::cout << "Gyro vel: x = " << std::setw(12) << imu_vel[0] << " y = " << std::setw(12) << imu_vel[1] << " z = " << std::setw(12) << imu_vel[2];
76 std::cout << " Accel: x = " << std::setw(12) << imu_acc[0] << " y = " << std::setw(12) << imu_acc[1] << " z = " << std::setw(12) << imu_acc[2];
77 std::cout << std::endl;
78 }
79 } catch (const vpException &e) {
80 std::cerr << "RealSense error " << e.what() << std::endl;
81 } catch (const std::exception &e) {
82 std::cerr << e.what() << std::endl;
83 }
84
85 return EXIT_SUCCESS;
86}
87#else
88int main()
89{
90#if !defined(VISP_HAVE_REALSENSE2)
91 std::cout << "You do not realsense2 SDK functionality enabled..." << std::endl;
92 std::cout << "Tip:" << std::endl;
93 std::cout << "- Install librealsense2, configure again ViSP using cmake and build again this example" << std::endl;
94 return EXIT_SUCCESS;
95#elif (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
96 std::cout << "You do not build ViSP with c++11 or higher compiler flag" << std::endl;
97 std::cout << "Tip:" << std::endl;
98 std::cout << "- Configure ViSP again using cmake -DUSE_CXX_STANDARD=11, and build again this example" << std::endl;
99#elif !(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
100 std::cout << "You don't have X11 or GDI display capabilities" << std::endl;
101#elif !(RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))
102 std::cout << "Install librealsense version > 2.31.0" << std::endl;
103#endif
104 return EXIT_SUCCESS;
105}
106#endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
error that can be emited by ViSP classes.
Definition: vpException.h:72
const char * what() const
bool open(const rs2::config &cfg=rs2::config())
std::string getProductLine()
void getIMUData(vpColVector *imu_vel, vpColVector *imu_acc, double *ts)