Main MRPT website > C++ reference for MRPT 1.9.9
CObservationRFID.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 
13 #include <mrpt/utils/CStream.h>
14 
15 using namespace mrpt::obs;
16 using namespace mrpt::utils;
17 using namespace mrpt::poses;
18 
19 // This must be added to any CSerializable class implementation file.
21 
22 /** Constructor
23  */
24 CObservationRFID::CObservationRFID() : tag_readings() {}
25 /*---------------------------------------------------------------
26  Implements the writing to a CStream capability of CSerializable objects
27  ---------------------------------------------------------------*/
29  mrpt::utils::CStream& out, int* version) const
30 {
31  // std::cout << "AP-1" << std::endl;
32  MRPT_UNUSED_PARAM(out);
33  if (version)
34  *version = 4;
35  else
36  {
37  // The data
38  const uint32_t Ntags = tag_readings.size();
39  out << Ntags; // new in v4
40 
41  // (Fields are dumped in separate for loops for backward compatibility
42  // with old serialization versions)
43  for (uint32_t i = 0; i < Ntags; i++) out << tag_readings[i].power;
44  for (uint32_t i = 0; i < Ntags; i++) out << tag_readings[i].epc;
45  for (uint32_t i = 0; i < Ntags; i++) out << tag_readings[i].antennaPort;
46 
47  out << sensorLabel;
48  out << timestamp;
49  out << sensorPoseOnRobot; // Added in v3
50  }
51 }
52 
53 /*---------------------------------------------------------------
54  Implements the reading from a CStream capability of CSerializable objects
55  ---------------------------------------------------------------*/
57 {
58  // MRPT_UNUSED_PARAM(in);
59  switch (version)
60  {
61  case 0:
62  case 1:
63  case 2:
64  case 3:
65  case 4:
66  {
67  uint32_t Ntags = 0;
68  if (version < 4)
69  {
70  std::string ntags;
71  in >> ntags;
72  Ntags = atoi(ntags.c_str());
73  }
74  else
75  {
76  in >> Ntags;
77  }
78 
79  // (Fields are read in separate for loops for backward compatibility
80  // with old serialization versions)
81  tag_readings.resize(Ntags);
82  for (uint32_t i = 0; i < Ntags; i++) in >> tag_readings[i].power;
83  for (uint32_t i = 0; i < Ntags; i++) in >> tag_readings[i].epc;
84  for (uint32_t i = 0; i < Ntags; i++)
85  in >> tag_readings[i].antennaPort;
86 
87  if (version >= 1)
88  in >> sensorLabel;
89  else
90  sensorLabel = "";
91 
92  if (version >= 2)
93  in >> timestamp;
94  else
95  timestamp = INVALID_TIMESTAMP;
96 
97  if (version >= 3)
98  in >> sensorPoseOnRobot;
99  else
100  sensorPoseOnRobot = CPose3D();
101  }
102  break;
103  default:
105  };
106 }
107 
108 void CObservationRFID::getSensorPose(CPose3D& out_sensorPose) const
109 {
110  out_sensorPose = sensorPoseOnRobot;
111 }
112 
113 void CObservationRFID::setSensorPose(const CPose3D& newSensorPose)
114 {
115  sensorPoseOnRobot = newSensorPose;
116 }
117 
118 void CObservationRFID::getDescriptionAsText(std::ostream& o) const
119 {
121 
122  std::cout << "Number of RFID tags sensed: " << tag_readings.size()
123  << std::endl
124  << std::endl;
125 
126  for (size_t i = 0; i < tag_readings.size(); i++)
127  {
128  const CObservationRFID::TTagReading& rfid = tag_readings[i];
129  std::cout << "#" << i << ": Power=" << rfid.power
130  << " (dBm) | AntennaPort=" << rfid.antennaPort
131  << " | EPC=" << rfid.epc << std::endl;
132  }
133 }
std::string antennaPort
Port of the antenna that did the reading.
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.
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const override
A general method to retrieve the sensor pose on the robot.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) override
A general method to change the sensor pose on the robot.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
std::string epc
EPC code of the observed tag.
This namespace contains representation of robot actions and observations.
double power
The power or signal strength as sensed by the RFID receiver (in dBm)
GLsizei const GLchar ** string
Definition: glext.h:4101
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 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...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:41
GLuint in
Definition: glext.h:7274
Each of the individual readings of a RFID tag.
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
This represents one or more RFID tags observed by a receiver.
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...
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.



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