Main MRPT website > C++ reference for MRPT 1.9.9
CObservationIMU.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "obs-precomp.h" // Precompiled headers
11 
12 #include <mrpt/utils/CStream.h>
14 //#include <mrpt/math/CMatrixD.h>
15 
16 using namespace mrpt::obs;
17 using namespace mrpt::utils;
18 using namespace mrpt::poses;
19 
20 // This must be added to any CSerializable class implementation file.
22 
23 /*---------------------------------------------------------------
24  Implements the writing to a CStream capability of CSerializable objects
25  ---------------------------------------------------------------*/
26 void CObservationIMU::writeToStream(
27  mrpt::utils::CStream& out, int* version) const
28 {
29  if (version)
30  *version = 3; // v1->v2 was only done to fix a bug in the ordering of
31  // YAW/PITCH/ROLL rates.
32  else
33  {
34  out << sensorPose << dataIsPresent << timestamp;
35 
36  out << rawMeasurements;
37  // Version 3: Added 6 new raw measurements (IMU_MAG_X=15 to
38  // IMU_TEMPERATURE=20)
39 
40  out << sensorLabel;
41  }
42 }
43 
44 /*---------------------------------------------------------------
45  Implements the reading from a CStream capability of CSerializable objects
46  ---------------------------------------------------------------*/
48 {
49  switch (version)
50  {
51  case 0:
52  case 1:
53  case 2:
54  case 3:
55  in >> sensorPose;
56  in >> dataIsPresent;
57 
58  in >> timestamp;
59 
60  // In version 0 it was a vector of floats:
61  if (version < 1)
62  {
64  in >> tmp;
65  rawMeasurements.resize(tmp.size());
66  for (size_t i = 0; i < rawMeasurements.size(); i++)
67  rawMeasurements[i] = tmp[i];
68  }
69  else
70  {
71  in >> rawMeasurements;
72  }
73 
74  if (version < 2)
75  {
76  // A bug in the grabbing from XSens IMU's made /ROLL rates to be
77  // stored in the wrong order:
78  std::swap(
79  rawMeasurements[IMU_YAW_VEL],
80  rawMeasurements[IMU_ROLL_VEL]);
81  }
82  else
83  {
84  // v2: nothing to do, data is already in the right order.
85  }
86 
87  in >> sensorLabel;
88 
89  // Fill new entries with default values:
90  if (dataIsPresent.size() < COUNT_IMU_DATA_FIELDS)
91  {
92  const size_t nOld = dataIsPresent.size();
93  ASSERT_(rawMeasurements.size() == dataIsPresent.size());
94 
95  dataIsPresent.resize(COUNT_IMU_DATA_FIELDS);
96  rawMeasurements.resize(COUNT_IMU_DATA_FIELDS);
97  for (size_t i = nOld; i < COUNT_IMU_DATA_FIELDS; i++)
98  {
99  dataIsPresent[i] = false;
100  rawMeasurements[i] = 0;
101  }
102  }
103  break;
104  default:
106  };
107 }
108 
109 void CObservationIMU::getDescriptionAsText(std::ostream& o) const
110 {
111  using namespace std;
112  ;
114 
115  o << "Sensor pose on the robot: " << sensorPose << endl;
116 
117  o << format(
118  "Orientation (degrees): (yaw,pitch,roll)=(%.06f, %.06f, %.06f)\n\n",
119  RAD2DEG(rawMeasurements[IMU_YAW]), RAD2DEG(rawMeasurements[IMU_PITCH]),
120  RAD2DEG(rawMeasurements[IMU_ROLL]));
121 
122  // Units:
123  // Use "COUNT_IMU_DATA_FIELDS" so a compile error happens if the sizes don't
124  // fit ;-)
125  static const char* imu_units[mrpt::obs::COUNT_IMU_DATA_FIELDS] = {
126  "m/s^2", // IMU_X_ACC,
127  "m/s^2", // IMU_Y_ACC,
128  "m/s^2", // IMU_Z_ACC,
129  "rad/s", // IMU_YAW_VEL,
130  "rad/s", // IMU_PITCH_VEL,
131  "rad/s", // IMU_ROLL_VEL,
132  "m/s", // IMU_X_VEL,
133  "m/s", // IMU_Y_VEL,
134  "m/s", // IMU_Z_VEL,
135  "rad", // IMU_YAW,
136  "rad", // IMU_PITCH,
137  "rad", // IMU_ROLL,
138  "m", // IMU_X,
139  "m", // IMU_Y,
140  "m", // IMU_Z
141  "gauss", // IMU_MAG_X,
142  "gauss", // IMU_MAG_Y,
143  "gauss", // IMU_MAG_Z,
144  "Pa", // IMU_PRESSURE,
145  "m", // IMU_ALTITUDE,
146  "deg.", // IMU_TEMPERATURE,
147  "qx", // IMU_ORI_QUAT_X,
148  "qy", // IMU_ORI_QUAT_Y,
149  "qz", // IMU_ORI_QUAT_Z,
150  "qw", // IMU_ORI_QUAT_W,
151  "rad/s", // IMU_YAW_VEL_GLOBAL
152  "rad/s", // IMU_PITCH_VEL_GLOBAL
153  "rad/s", // IMU_ROLL_VEL_GLOBAL
154  "m/s^2", // IMU_X_ACC_GLOBAL
155  "m/s^2", // IMU_Y_ACC_GLOBAL
156  "m/s^2" // IMU_Z_ACC_GLOBAL
157  };
158 
159 #define DUMP_IMU_DATA(x) \
160  o << format("%15s = ", #x); \
161  if (dataIsPresent[x]) \
162  o << format("%10f %s\n", rawMeasurements[x], imu_units[x]); \
163  else \
164  o << "(not present)\n";
165 
197 }
x-axis acceleration (global/navigation frame) (m/sec2)
z-axis acceleration (global/navigation frame) (m/sec2)
yaw angular velocity (global/navigation frame) (rad/sec)
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
orientation pitch absolute value (global/navigation frame) (rad)
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:42
temperature (degrees Celsius)
x magnetic field value (local/vehicle frame) (gauss)
y-axis acceleration (local/vehicle frame) (m/sec2)
STL namespace.
Orientation Quaternion X (global/navigation frame)
This class stores measurements from an Inertial Measurement Unit (IMU) (attitude estimation, raw gyroscope and accelerometer values), altimeters or magnetometers.
z-axis acceleration (local/vehicle frame) (m/sec2)
x-axis velocity (global/navigation frame) (m/sec)
roll angular velocity (global/navigation frame) (rad/sec)
pitch angular velocity (local/vehicle frame) (rad/sec)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
This namespace contains representation of robot actions and observations.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
pitch angular velocity (global/navigation frame) (rad/sec)
#define DUMP_IMU_DATA(x)
Orientation Quaternion Y (global/navigation frame)
Orientation Quaternion Z (global/navigation frame)
z magnetic field value (local/vehicle frame) (gauss)
Orientation Quaternion W (global/navigation frame)
y absolute value (global/navigation frame) (meters)
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
y magnetic field value (local/vehicle frame) (gauss)
#define RAD2DEG
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:41
y-axis acceleration (global/navigation frame) (m/sec2)
GLuint in
Definition: glext.h:7274
#define ASSERT_(f)
air pressure (Pascals)
z absolute value (global/navigation frame) (meters)
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
orientation yaw absolute value (global/navigation frame) (rad)
y-axis velocity (global/navigation frame) (m/sec)
orientation roll absolute value (global/navigation frame) (rad)
yaw angular velocity (local/vehicle frame) (rad/sec)
x absolute value (global/navigation frame) (meters)
roll angular velocity (local/vehicle frame) (rad/sec)
x-axis acceleration (local/vehicle frame) (m/sec2)
z-axis velocity (global/navigation frame) (m/sec)
altitude from an altimeter (meters)
virtual void getDescriptionAsText(std::ostream &o) const
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019