Main MRPT website > C++ reference for MRPT 1.9.9
CObservationBearingRange.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/system/os.h>
15 #include <mrpt/math/matrix_serialization.h> // for << ops
16 #include <mrpt/math/wrap2pi.h>
17 #include <set>
18 
19 using namespace mrpt::obs;
20 using namespace mrpt::utils;
21 using namespace mrpt::poses;
22 
23 // This must be added to any CSerializable class implementation file.
25 
26 /*---------------------------------------------------------------
27  Default constructor.
28  ---------------------------------------------------------------*/
30  : minSensorDistance(0),
31  maxSensorDistance(0),
32  fieldOfView_yaw(DEG2RAD(180)),
33  fieldOfView_pitch(DEG2RAD(90)),
34  sensorLocationOnRobot(),
35  sensedData(),
36  validCovariances(false),
37  sensor_std_range(0),
38  sensor_std_yaw(0),
39  sensor_std_pitch(0)
40 {
41 }
42 
43 /*---------------------------------------------------------------
44  Implements the writing to a CStream capability of CSerializable objects
45  ---------------------------------------------------------------*/
47  mrpt::utils::CStream& out, int* version) const
48 {
49  if (version)
50  *version = 3;
51  else
52  {
53  uint32_t i, n;
54 
55  // The data
56  out << minSensorDistance << maxSensorDistance << fieldOfView_yaw
57  << fieldOfView_pitch << sensorLocationOnRobot << timestamp;
58 
59  out << validCovariances;
60  if (!validCovariances)
61  out << sensor_std_range << sensor_std_yaw << sensor_std_pitch;
62 
63  // Detect duplicate landmarks ID, which is an error!
64  std::set<int32_t> lstIDs;
65 
66  n = sensedData.size();
67  out << n;
68  for (i = 0; i < n; i++)
69  {
70  int32_t id = sensedData[i].landmarkID;
71  if (id != INVALID_LANDMARK_ID)
72  {
73  if (0 != lstIDs.count(id))
75  "Duplicate landmark ID=%i found.", (int)id);
76  lstIDs.insert(id);
77  }
78 
79  out << sensedData[i].range << sensedData[i].yaw
80  << sensedData[i].pitch << id;
81 
82  if (validCovariances) out << sensedData[i].covariance;
83  }
84 
85  out << sensorLabel;
86  }
87 }
88 
89 /*---------------------------------------------------------------
90  Implements the reading from a CStream capability of CSerializable objects
91  ---------------------------------------------------------------*/
93  mrpt::utils::CStream& in, int version)
94 {
95  switch (version)
96  {
97  case 0:
98  case 1:
99  case 2:
100  case 3:
101  {
102  uint32_t i, n;
103 
104  // The data
105  in >> minSensorDistance >> maxSensorDistance;
106 
107  if (version >= 3)
108  {
109  in >> fieldOfView_yaw >> fieldOfView_pitch;
110  }
111  else
112  {
113  float fieldOfView;
114  in >> fieldOfView;
115 
116  fieldOfView_yaw = fieldOfView_pitch = fieldOfView;
117  }
118 
119  in >> sensorLocationOnRobot;
120 
121  if (version >= 2)
122  in >> timestamp;
123  else
124  timestamp = INVALID_TIMESTAMP;
125 
126  if (version >= 3)
127  {
128  in >> validCovariances;
129  if (!validCovariances)
130  in >> sensor_std_range >> sensor_std_yaw >>
131  sensor_std_pitch;
132  }
133  else
134  validCovariances = false;
135 
136  in >> n;
137  sensedData.resize(n);
138 
139  // Detect duplicate landmarks ID, what is an error!
140  std::set<int32_t> lstIDs;
141 
142  for (i = 0; i < n; i++)
143  {
144  in >> sensedData[i].range >> sensedData[i].yaw >>
145  sensedData[i].pitch >> sensedData[i].landmarkID;
146 
147  if (version >= 3 && validCovariances)
148  in >> sensedData[i].covariance;
149 
150  int32_t id = sensedData[i].landmarkID;
151  if (id != INVALID_LANDMARK_ID)
152  {
153  if (0 != lstIDs.count(id))
155  "Duplicate landmark ID=%i found.", (int)id);
156  lstIDs.insert(id);
157  }
158  }
159 
160  if (version >= 1)
161  in >> sensorLabel;
162  else
163  sensorLabel = "";
164  }
165  break;
166  default:
168  };
169 }
170 
171 /*---------------------------------------------------------------
172  Implements the writing to a CStream capability of CSerializable objects
173  ---------------------------------------------------------------*/
175 {
176  printf("[CObservationBearingRange::debugPrintOut] Dumping:\n");
177  printf(
178  "[CObservationBearingRange::debugPrintOut] minSensorDistance:\t%f\n",
179  minSensorDistance);
180  printf(
181  "[CObservationBearingRange::debugPrintOut] maxSensorDistance:\t%f:\n",
182  maxSensorDistance);
183  printf(
184  "[CObservationBearingRange::debugPrintOut] %u landmarks:\n",
185  static_cast<unsigned>(sensedData.size()));
186 
187  size_t i, n = sensedData.size();
188  for (i = 0; i < n; i++)
189  printf(
190  "[CObservationBearingRange::debugPrintOut] \tID[%i]: y:%fdeg "
191  "p:%fdeg range: %f\n",
192  sensedData[i].landmarkID, RAD2DEG(sensedData[i].yaw),
193  RAD2DEG(sensedData[i].pitch), sensedData[i].range);
194 }
195 
197 {
198  using namespace std;
200 
201  o << "Homogeneous matrix for the sensor's 3D pose, relative to robot "
202  "base:\n";
203  o << sensorLocationOnRobot.getHomogeneousMatrixVal()
204  << sensorLocationOnRobot << endl
205  << endl;
206 
207  o << "Do observations have individual covariance matrices? "
208  << (validCovariances ? "YES" : "NO") << endl
209  << endl;
210 
211  o << "Default noise sigmas:" << endl;
212  o << "sensor_std_range (m) : " << sensor_std_range << endl;
213  o << "sensor_std_yaw (deg) : " << RAD2DEG(sensor_std_yaw) << endl;
214  o << "sensor_std_pitch (deg) : " << RAD2DEG(sensor_std_pitch) << endl;
215 
216  o << endl;
217 
218  // For each entry in this sequence:
219  o << " LANDMARK_ID RANGE (m) YAW (deg) PITCH (deg) COV. MATRIX "
220  "(optional)"
221  << endl;
222  o << "---------------------------------------------------------------------"
223  "-----------------"
224  << endl;
225  for (size_t q = 0; q < sensedData.size(); q++)
226  {
227  o << " ";
228  if (sensedData[q].landmarkID == INVALID_LANDMARK_ID)
229  o << "(NO ID)";
230  else
231  o << format("%7u", sensedData[q].landmarkID);
232 
233  o << format(
234  " %10.03f %10.03f %10.03f ", sensedData[q].range,
235  RAD2DEG(mrpt::math::wrapToPi(sensedData[q].yaw)),
236  RAD2DEG(mrpt::math::wrapToPi(sensedData[q].pitch)));
237 
238  if (validCovariances)
239  o << sensedData[q].covariance.inMatlabFormat() << endl;
240  else
241  o << " (N/A)\n";
242  }
243 }
GLsizei range
Definition: glext.h:5907
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.
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:3721
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
GLenum GLsizei n
Definition: glext.h:5074
STL namespace.
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
#define DEG2RAD
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
Definition: wrap2pi.h:53
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
Definition: datetime.h:16
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
__int32 int32_t
Definition: rptypes.h:46
#define RAD2DEG
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:41
This file implements matrix/vector text and binary serialization.
GLuint id
Definition: glext.h:3909
This observation represents a number of range-bearing value pairs, each one for a detected landmark...
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...
GLuint in
Definition: glext.h:7274
#define INVALID_LANDMARK_ID
Used for CObservationBearingRange::TMeasurement::beaconID and others.
Definition: CObservation.h:25
void debugPrintOut()
Prints out the contents of the object.
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
unsigned __int32 uint32_t
Definition: rptypes.h:47
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