Main MRPT website > C++ reference for MRPT 1.5.7
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  */
25 {
26 }
27 
28 /*---------------------------------------------------------------
29  Implements the writing to a CStream capability of CSerializable objects
30  ---------------------------------------------------------------*/
32 {
33  //std::cout << "AP-1" << std::endl;
34  MRPT_UNUSED_PARAM(out);
35  if (version)
36  *version = 4;
37  else
38  {
39  // The data
40  const uint32_t Ntags = tag_readings.size();
41  out << Ntags; // new in v4
42 
43  // (Fields are dumped in separate for loops for backward compatibility with old serialization versions)
44  for (uint32_t i=0;i<Ntags;i++) out << tag_readings[i].power;
45  for (uint32_t i=0;i<Ntags;i++) out << tag_readings[i].epc;
46  for (uint32_t i=0;i<Ntags;i++) out << tag_readings[i].antennaPort;
47 
48  out << sensorLabel;
49  out << timestamp;
50  out << sensorPoseOnRobot; // Added in v3
51  }
52 }
53 
54 /*---------------------------------------------------------------
55  Implements the reading from a CStream capability of CSerializable objects
56  ---------------------------------------------------------------*/
58 {
59  //MRPT_UNUSED_PARAM(in);
60  switch(version)
61  {
62  case 0:
63  case 1:
64  case 2:
65  case 3:
66  case 4:
67  {
68  uint32_t Ntags=0;
69  if (version<4)
70  {
71  std::string ntags;
72  in >> ntags;
73  Ntags = atoi(ntags.c_str());
74  }
75  else
76  {
77  in >> Ntags;
78  }
79 
80  // (Fields are read in separate for loops for backward compatibility 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++) in >> tag_readings[i].antennaPort;
85 
86  if (version>=1)
87  in >> sensorLabel;
88  else sensorLabel="";
89 
90  if (version>=2)
91  in >> timestamp;
92  else timestamp = INVALID_TIMESTAMP;
93 
94  if (version>=3)
95  in >> sensorPoseOnRobot;
96  else sensorPoseOnRobot = CPose3D();
97 
98  } break;
99  default:
101  };
102 
103 }
104 
105 
106 void CObservationRFID::getSensorPose( CPose3D &out_sensorPose ) const
107 {
108  out_sensorPose=sensorPoseOnRobot;
109 }
110 
111 void CObservationRFID::setSensorPose( const CPose3D &newSensorPose )
112 {
113  sensorPoseOnRobot = newSensorPose;
114 }
115 
116 void CObservationRFID::getDescriptionAsText(std::ostream &o) const
117 {
119 
120  std::cout << "Number of RFID tags sensed: " << tag_readings.size() << std::endl << std::endl;
121 
122  for (size_t i=0;i<tag_readings.size();i++)
123  {
124  const CObservationRFID::TTagReading &rfid = tag_readings[i];
125  std::cout << "#"<< i
126  << ": Power=" << rfid.power
127  << " (dBm) | AntennaPort=" << rfid.antennaPort
128  << " | EPC=" << rfid.epc << std::endl;
129  }
130 }
131 
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.
Definition: zip.h:16
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) MRPT_OVERRIDE
A general method to change the sensor pose on the robot.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
#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.
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const MRPT_OVERRIDE
A general method to retrieve the sensor pose on the robot.
double power
The power or signal strength as sensed by the RFID receiver (in dBm)
int version
Definition: mrpt_jpeglib.h:898
GLsizei const GLchar ** string
Definition: glext.h:3919
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:17
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
Declares a class that represents any robot&#39;s observation.
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
void getDescriptionAsText(std::ostream &o) const MRPT_OVERRIDE
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
GLuint in
Definition: glext.h:6301
Each of the individual readings of a RFID tag.
This represents one or more RFID tags observed by a receiver.
unsigned __int32 uint32_t
Definition: rptypes.h:49
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
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.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019