ObjectEvidence.cpp
Go to the documentation of this file.
1 
19 
21 
23  {
24  ros::NodeHandle mNodeHandle("~");
25 
26  // Try to get the timeout for object evidences.
27  if(!mNodeHandle.getParam("evidence_timeout", mTimeout))
28  throw std::runtime_error("Please specify parameter " + std::string("evidence_timeout") + " when starting this node.");
29  }
30 
32  {
33  }
34 
36 
37  {
38  mBuffer.push_back(*pObject);
39  }
40 
42  {
43  return mBuffer.size() > 0;
44  }
45 
47  {
48  // Iterate over all accumulated evidences and add each one to the list.
49  // Also keep book about if a new object has been found.
50 
51  BOOST_FOREACH(ISM::Object object, mBuffer)
52 
53  {
54  // Create iterator for the outer index (object type).
55  std::map<std::string, std::map<std::string, KalmanFilter> >::iterator it;
56 
57  // Exists an entry with the given object type?
58  if((it = mObjectEvidences.find(object.type)) != mObjectEvidences.end())
59  {
60  // Create iterator for the inner index (object instance).
61  std::map<std::string, KalmanFilter>::iterator it2;
62 
63  // Exists an entry with the given object instance name?
64  if((it2 = it->second.find(object.observedId)) != it->second.end())
65  {
66  // There exists an entry for type and instance, so we update the associated kalman filter.
67  it2->second.update(object);
68 
69  // Status information for the user.
70  ROS_DEBUG_STREAM("Object Evidence: replaced object (" << object.type << ", " << object.observedId << ").");
71  } else {
72 
73  // Create a new kalman filter.
74  it->second.insert(std::pair<std::string, KalmanFilter>(object.observedId, KalmanFilter(object)));
75 
76  // Status information for the user.
77  ROS_DEBUG_STREAM("Object Evidence: object with new identifier found (" << object.type << ", " << object.observedId << ").");
78  }
79  } else {
80  // There was no entry for the given object type and instance.
81  // So we first add a map for the instance to the evidences and then an entry to this map.
82  std::map<std::string, KalmanFilter> entry;
83  entry.insert(std::pair<std::string, KalmanFilter>(object.observedId, KalmanFilter(object)));
84  mObjectEvidences.insert(std::pair<std::string, std::map<std::string, KalmanFilter> >(object.type, entry));
85  // THIS IS WHY MANY PEOPLE PREFER JAVA...! OR PYTHON ;D!
86 
87  // Status information for the user.
88  ROS_DEBUG_STREAM("Object Evidence: object with new type and identifier found (" << object.type << ", " << object.observedId << ").");
89  }
90  }
91 
92  // Search for timed out evidences.
93  std::map<std::string, std::map<std::string, KalmanFilter> >::iterator it;
94  for(it = mObjectEvidences.begin(); it != mObjectEvidences.end(); ++it)
95  {
96 
97  // Create iterator for the inner index (object instance).
98  std::map<std::string, KalmanFilter>::iterator it2 = it->second.begin();
99  if(it2 != it->second.end())
100  {
101  // Remove timed out evidence.
102  if (it2->second.isTimedOut(mTimeout))
103  {
104  ISM::Object object = it2->second.getObject();
105 
106 
107  it->second.erase(it2++);
108  ROS_DEBUG_STREAM("Removed timed out evidence (" << object.type << ", " << object.observedId << ").");
109  } else {
110  ++it2;
111  }
112  }
113  }
114 
115  // Delete all entries in the buffer.
116  mBuffer.clear();
117  }
118 
119  void ObjectEvidence::getEvidences(std::vector<ISM::Object>& pEvidences)
120 
121  {
122  // Erase old evidences from history *dramatic drum roll*.
123  pEvidences.clear();
124 
125  // Create iterators for object type and instance indices.
126  std::map<std::string, std::map<std::string, KalmanFilter> >::iterator it;
127  std::map<std::string, KalmanFilter>::iterator it2;
128 
129  // Iterate over the object type index (the outer index).
130  for(it = mObjectEvidences.begin(); it != mObjectEvidences.end(); it++)
131  {
132  // Iterate over the object instance names (the inner index).
133  for(it2 = it->second.begin(); it2 != it->second.end(); it2++)
134  {
135  // Add every evidence to the vector.
136  pEvidences.push_back(it2->second.getObject());
137  }
138  }
139  }
140 
141 }
void push(const boost::shared_ptr< const ISM::Object > &pObject)
std::map< std::string, std::map< std::string, KalmanFilter > > mObjectEvidences
#define ROS_DEBUG_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
void getEvidences(std::vector< ISM::Object > &pEvidences)


asr_psm
Author(s): Braun Kai, Gehrung Joachim, Heizmann Heinrich, Meißner Pascal
autogenerated on Fri Nov 15 2019 03:57:54