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-2018, 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 
14 
15 using namespace mrpt::obs;
16 using namespace mrpt::poses;
17 
18 // This must be added to any CSerializable class implementation file.
20 
21 /** Constructor
22  */
23 CObservationRFID::CObservationRFID() : tag_readings() {}
26 {
27  // The data
28  const uint32_t Ntags = tag_readings.size();
29  out << Ntags; // new in v4
30 
31  // (Fields are dumped in separate for loops for backward compatibility
32  // with old serialization versions)
33  for (uint32_t i = 0; i < Ntags; i++) out << tag_readings[i].power;
34  for (uint32_t i = 0; i < Ntags; i++) out << tag_readings[i].epc;
35  for (uint32_t i = 0; i < Ntags; i++) out << tag_readings[i].antennaPort;
36 
37  out << sensorLabel;
38  out << timestamp;
39  out << sensorPoseOnRobot; // Added in v3
40 }
41 
44 {
45  // MRPT_UNUSED_PARAM(in);
46  switch (version)
47  {
48  case 0:
49  case 1:
50  case 2:
51  case 3:
52  case 4:
53  {
54  uint32_t Ntags = 0;
55  if (version < 4)
56  {
57  std::string ntags;
58  in >> ntags;
59  Ntags = atoi(ntags.c_str());
60  }
61  else
62  {
63  in >> Ntags;
64  }
65 
66  // (Fields are read in separate for loops for backward compatibility
67  // with old serialization versions)
68  tag_readings.resize(Ntags);
69  for (uint32_t i = 0; i < Ntags; i++) in >> tag_readings[i].power;
70  for (uint32_t i = 0; i < Ntags; i++) in >> tag_readings[i].epc;
71  for (uint32_t i = 0; i < Ntags; i++)
72  in >> tag_readings[i].antennaPort;
73 
74  if (version >= 1)
75  in >> sensorLabel;
76  else
77  sensorLabel = "";
78 
79  if (version >= 2)
80  in >> timestamp;
81  else
82  timestamp = INVALID_TIMESTAMP;
83 
84  if (version >= 3)
85  in >> sensorPoseOnRobot;
86  else
87  sensorPoseOnRobot = CPose3D();
88  }
89  break;
90  default:
92  };
93 }
94 
95 void CObservationRFID::getSensorPose(CPose3D& out_sensorPose) const
96 {
97  out_sensorPose = sensorPoseOnRobot;
98 }
99 
100 void CObservationRFID::setSensorPose(const CPose3D& newSensorPose)
101 {
102  sensorPoseOnRobot = newSensorPose;
103 }
104 
105 void CObservationRFID::getDescriptionAsText(std::ostream& o) const
106 {
108 
109  o << "Number of RFID tags sensed: " << tag_readings.size() << "\n";
110  for (size_t i = 0; i < tag_readings.size(); i++)
111  {
112  const auto& rfid = tag_readings[i];
113  o << "#" << i << ": Power=" << rfid.power
114  << " (dBm) | AntennaPort=" << rfid.antennaPort
115  << " | EPC=" << rfid.epc << std::endl;
116  }
117 }
INVALID_TIMESTAMP
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
Definition: datetime.h:15
mrpt::obs::CObservationRFID::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CObservationRFID.cpp:25
mrpt::obs::CObservationRFID::setSensorPose
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) override
A general method to change the sensor pose on the robot.
Definition: CObservationRFID.cpp:100
obs-precomp.h
CObservationRFID.h
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
mrpt::obs
This namespace contains representation of robot actions and observations.
Definition: CParticleFilter.h:17
mrpt::obs::CObservationRFID::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CObservationRFID.cpp:24
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
mrpt::obs::CObservationRFID::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CObservationRFID.cpp:42
mrpt::obs::CObservationRFID::getDescriptionAsText
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
Definition: CObservationRFID.cpp:105
mrpt::obs::CObservation::getDescriptionAsText
virtual void getDescriptionAsText(std::ostream &o) const
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
Definition: CObservation.cpp:44
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Definition: CSerializable.h:114
mrpt::obs::CObservationRFID::getSensorPose
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const override
A general method to retrieve the sensor pose on the robot.
Definition: CObservationRFID.cpp:95
mrpt::obs::CObservationRFID
This represents one or more RFID tags observed by a receiver.
Definition: CObservationRFID.h:27
mrpt::obs::CObservation
Declares a class that represents any robot's observation.
Definition: CObservation.h:43
in
GLuint in
Definition: glext.h:7274
string
GLsizei const GLchar ** string
Definition: glext.h:4101
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
uint32_t
unsigned __int32 uint32_t
Definition: rptypes.h:47



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST