MRPT  2.0.1
CObservationRFID.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://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() {}
24 uint8_t CObservationRFID::serializeGetVersion() const { return 4; }
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 
43  mrpt::serialization::CArchive& in, uint8_t version)
44 {
45  switch (version)
46  {
47  case 0:
48  case 1:
49  case 2:
50  case 3:
51  case 4:
52  {
53  uint32_t Ntags = 0;
54  if (version < 4)
55  {
56  std::string ntags;
57  in >> ntags;
58  Ntags = atoi(ntags.c_str());
59  }
60  else
61  {
62  in >> Ntags;
63  }
64 
65  // (Fields are read in separate for loops for backward compatibility
66  // with old serialization versions)
67  tag_readings.resize(Ntags);
68  for (uint32_t i = 0; i < Ntags; i++) in >> tag_readings[i].power;
69  for (uint32_t i = 0; i < Ntags; i++) in >> tag_readings[i].epc;
70  for (uint32_t i = 0; i < Ntags; i++)
71  in >> tag_readings[i].antennaPort;
72 
73  if (version >= 1)
74  in >> sensorLabel;
75  else
76  sensorLabel = "";
77 
78  if (version >= 2)
79  in >> timestamp;
80  else
81  timestamp = INVALID_TIMESTAMP;
82 
83  if (version >= 3)
84  in >> sensorPoseOnRobot;
85  else
86  sensorPoseOnRobot = CPose3D();
87  }
88  break;
89  default:
91  };
92 }
93 
94 void CObservationRFID::getSensorPose(CPose3D& out_sensorPose) const
95 {
96  out_sensorPose = sensorPoseOnRobot;
97 }
98 
99 void CObservationRFID::setSensorPose(const CPose3D& newSensorPose)
100 {
101  sensorPoseOnRobot = newSensorPose;
102 }
103 
104 void CObservationRFID::getDescriptionAsText(std::ostream& o) const
105 {
107 
108  o << "Number of RFID tags sensed: " << tag_readings.size() << "\n";
109  for (size_t i = 0; i < tag_readings.size(); i++)
110  {
111  const auto& rfid = tag_readings[i];
112  o << "#" << i << ": Power=" << rfid.power
113  << " (dBm) | AntennaPort=" << rfid.antennaPort
114  << " | EPC=" << rfid.epc << std::endl;
115  }
116 }
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to 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.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) override
A general method to change the sensor pose on the robot.
This namespace contains representation of robot actions and observations.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::vision::TStereoCalibResults out
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:43
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.
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
Definition: datetime.h:43
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 serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020