found_object_handler.cpp
Go to the documentation of this file.
1 
19 
20 namespace world_model
21 {
22 
24  boost::shared_ptr<ros::ServiceClient> object_type_client_ptr,
25  ModelTypePtrPerTypeMapPtr model_type_ptr_per_type_map_ptr,
26  SettingsPtr settings_ptr) :
27  tf_transform_listener_(),
28  object_type_client_ptr_(object_type_client_ptr),
29  model_type_ptr_per_type_map_ptr_(model_type_ptr_per_type_map_ptr),
30  settings_ptr_(settings_ptr)
31 {
35  ROS_INFO_STREAM("FoundObjectHandler initialized");
36 }
37 
38 bool FoundObjectHandler::processPushFoundObjectListServiceCall(asr_world_model::PushFoundObjectList::Request &request,
39  asr_world_model::PushFoundObjectList::Response &response)
40 {
41  debug_helper_ptr_->write(std::stringstream() << "Calling processPushFoundObjectListServiceCall with " << request.found_object_list.size() << " estimates in list", (DebugHelper::SERVICE_CALLS + DebugHelper::FOUND_OBJECT));
42  bool result = true;
43  for (asr_msgs::AsrObject &foundObject : request.found_object_list)
44  {
45  result &= pushFoundObject(foundObject);
46  if(!result) ROS_ERROR_STREAM("Pushing found object to world model failed for type/id: " << foundObject.type << "/" << foundObject.identifier);
47  }
48  return result;
49 }
50 
51 bool FoundObjectHandler::pushFoundObject(asr_msgs::AsrObject &candidate)
52 {
53  const std::string &CANDIDATE_TYPE = candidate.type;
54  const std::string &CANDIDATE_IDENTIFIER = candidate.identifier;
55 
56  //Check if given candidate is known
57  ModelTypePtrPerTypeMap::iterator type_it = model_type_ptr_per_type_map_ptr_->find(CANDIDATE_TYPE);
58  if (type_it == model_type_ptr_per_type_map_ptr_->end()) {
59  ROS_WARN_STREAM("The given type was not in the ISM_Tables -> not all information are available for it: " << CANDIDATE_TYPE);
60  type_it = model_type_ptr_per_type_map_ptr_->insert(std::make_pair(CANDIDATE_TYPE, ModelTypePtr(new ModelType(CANDIDATE_TYPE)))).first;
61  }
62 
63  ModelObjectPtrPerIdMap::iterator id_it = type_it->second->model_object_ptr_per_id_map.find(CANDIDATE_IDENTIFIER);
64  if (id_it == type_it->second->model_object_ptr_per_id_map.end()) {
65  ROS_WARN_STREAM("The given type and id was not in the ISM_Tables -> not all information are available for it: type: " << CANDIDATE_TYPE << ", id: " << CANDIDATE_IDENTIFIER);
66  id_it = type_it->second->model_object_ptr_per_id_map.insert(std::make_pair(CANDIDATE_IDENTIFIER, ModelObjectPtr(new ModelObject(CANDIDATE_IDENTIFIER)))).first;
67  }
68 
69  if (!transformToBaseFrame(candidate)) {
70  return false;
71  }
72 
73  if (!sampleFoundObject(candidate)) {
74  return false;
75  }
76 
77  ModelObjectPtr &currentModelObjectPtr = id_it->second;
78  //In the past, this was just the best cluster for the object being currently pushed.
79  //Since multiple objects of the same type might be present in world_model now, replaced best cluster with set of best clusters (one for each object of same type and id).
80 
81  if (currentModelObjectPtr->bestHypotheses.size() == 0) {
82  //Create list for clusters of similiar object poses for given object type id
83  currentModelObjectPtr->allFoundHypotheses.push_back(std::make_pair(candidate, 1));
84  //Create first cluster in best_hypothesis for this pushed combination of type and id.
85  currentModelObjectPtr->bestHypotheses.push_back(std::make_pair(candidate, 1));
86 
87  debug_helper_ptr_->write(std::stringstream() << "Received object hypothesis for " << CANDIDATE_TYPE << " with ID " << CANDIDATE_IDENTIFIER << " is the first. Is trivially best hypothesis", DebugHelper::FOUND_OBJECT);
88  debug_helper_ptr_->write(std::stringstream() << "object_rating_min_count_ = " << settings_ptr_->object_rating_min_count << " ignored for first and only cluster", DebugHelper::FOUND_OBJECT);
89  } else {
90  updateBestHypothesis(currentModelObjectPtr, candidate);
91  }
92 
93  const geometry_msgs::Point &candidate_position = candidate.sampledPoses.front().pose.position;
94  debug_helper_ptr_->write(std::stringstream() << "Position of object estimate, having been added to cluster list: " << candidate_position.x << ", " << candidate_position.y << ", " << candidate_position.z, DebugHelper::FOUND_OBJECT);
95 
97  return true;
98 }
99 
100 void FoundObjectHandler::updateBestHypothesis(ModelObjectPtr &currentModelObjectPtr, const asr_msgs::AsrObject &candidate) {
101  PbdObjectClusterList currentBestHypothesis;
102  //If other objects already exist for this id, update the neighbor counter for potential neighbors and update the new best hypothesis
103  PbdObjectClusterList &allFoundHypotheses = currentModelObjectPtr->allFoundHypotheses;
104 
105  debug_helper_ptr_->write(std::stringstream() << "Received object hypothesis for " << candidate.type << " with ID " << candidate.identifier << " is NOT the first", DebugHelper::FOUND_OBJECT);
106  debug_helper_ptr_->write(std::stringstream() << "There are already " << allFoundHypotheses.size() << " clusters for that object", DebugHelper::FOUND_OBJECT);
107 
108  int neighborCount = 1;
109 
110  //Increment all sizes of clusters, neighbouring to currently pushed estimate.
111  for (PbdObjectCluster &pdbObjectCluster : allFoundHypotheses)
112  {
113  if (evaluateNeighborhood(pdbObjectCluster.first, candidate))
114  {
115  ++pdbObjectCluster.second;
116  ++neighborCount;
117  }
118  }
119  //Insert pushed object estimate into cluster list.
120  allFoundHypotheses.push_back(std::make_pair(candidate, neighborCount));
121 
122  debug_helper_ptr_->write(std::stringstream() << "Added new cluster for " << candidate.type << " with ID " << candidate.identifier << " with neighborCount " << neighborCount << " into clusterlist", DebugHelper::FOUND_OBJECT);
123  debug_helper_ptr_->write(std::stringstream() << "New cluster list size is " << allFoundHypotheses.size(), DebugHelper::FOUND_OBJECT);
124 
125 
126  //Sorting list of best clusters for currently pushed estimate.
127  allFoundHypotheses.sort(comparePbdObjectCluster);
128 
129 
130  //======== CREATE BEST CLUSTER LIST FOR PUSHED COMBINATION OF TYPE AND ID. ========
131 
132  //Iterate over the sorted cluster list for the pushed estimate.
133  for (const PbdObjectCluster &pdbObjectCurrentCluster : allFoundHypotheses)
134  {
135  //Fill new current_best_hypotheses list with currentClusterList.
136  //Filter out all clusters in currentClusterList that are either redundant to clusters in current_best_hypotheses or that do not have enough elements (object_rating_min_count_).
137  bool isInNeighborhood = false;
138 
139  const geometry_msgs::Pose &clusterListCenterPose = pdbObjectCurrentCluster.first.sampledPoses.front().pose;
140  for (const PbdObjectCluster &pdbObjectCurrentBestHypothese : currentBestHypothesis)
141  {
142  //Redundancy test
143  const geometry_msgs::Pose &bestCenterPose = pdbObjectCurrentBestHypothese.first.sampledPoses.front().pose;
144  isInNeighborhood |= pose_helper_ptr_->checkPosesAreApproxEquale(clusterListCenterPose, bestCenterPose, 0.1, 2.0*M_PI);
145  }
146 
147  if (!isInNeighborhood && pdbObjectCurrentCluster.second >= settings_ptr_->object_rating_min_count)
148  {
149  currentBestHypothesis.push_back(std::make_pair(pdbObjectCurrentCluster.first, pdbObjectCurrentCluster.second));
150  debug_helper_ptr_->write(std::stringstream() << "Added cluster to best cluster list (Neighborhood count: " << pdbObjectCurrentCluster.second << ")", DebugHelper::FOUND_OBJECT);
151  }
152  }
153 
154  debug_helper_ptr_->write(std::stringstream() << "Created new best cluster list with " << currentBestHypothesis.size() << " elements (objects) for " << candidate.type << " with ID " << candidate.identifier , DebugHelper::FOUND_OBJECT);
155 
156  //======= REPLACE BEST CLUSTER LIST FOR CURRENTLY PUSHED ESTIMATE IN MAP OF BEST CLUSTERS FOR ALL TYPES AND IDS =======
157  currentModelObjectPtr->bestHypotheses = currentBestHypothesis;
158 }
159 
160 bool FoundObjectHandler::evaluateNeighborhood(const asr_msgs::AsrObject &object1, const asr_msgs::AsrObject &object2) const {
161  const geometry_msgs::Pose &detected_pose1 = object1.sampledPoses.front().pose;
162  const geometry_msgs::Pose &detected_pose2 = object2.sampledPoses.front().pose;
163  return pose_helper_ptr_->checkPosesAreApproxEquale(detected_pose1, detected_pose2, settings_ptr_->object_position_distance_threshold,
164  settings_ptr_->object_orientation_rad_distance_threshold);
165 }
166 
167 bool FoundObjectHandler::transformToBaseFrame(asr_msgs::AsrObject &candidate) const {
168  geometry_msgs::PoseStamped cameraPose, mapPose;
169  cameraPose.header = candidate.header;
170  cameraPose.pose = candidate.sampledPoses.front().pose;
171  //transform to map frame
172 
173  try {
174  tf::StampedTransform transform;
175  tf_transform_listener_.lookupTransform(candidate.header.frame_id, "map", ros::Time(0), transform);
176  //Do not do this if objects are not static. Required for simulation.
177  cameraPose.header.stamp = transform.stamp_;
178  tf_transform_listener_.transformPose("map", cameraPose, mapPose);
179 
180  } catch (tf::TransformException ex) {
181  ROS_ERROR_STREAM("tf exception when converting object to map frame :: " << ex.what());
182  return false;
183  }
184 
185  candidate.header.frame_id = mapPose.header.frame_id;
186  geometry_msgs::PoseWithCovariance pose_with_c;
187  pose_with_c.pose = mapPose.pose;
188  candidate.sampledPoses.clear();
189  candidate.sampledPoses.push_back(pose_with_c);
190  return true;
191 }
192 
193 bool FoundObjectHandler::sampleFoundObject(asr_msgs::AsrObject &candidate) {
194  if (!settings_ptr_->enable_object_sampling) {
195  debug_helper_ptr_->write(std::stringstream() << "Sample found objects disabled", DebugHelper::FOUND_OBJECT);
196  return true;
197  }
198  debug_helper_ptr_->write(std::stringstream() << "Entering sampleFoundObject()", DebugHelper::FOUND_OBJECT);
199 
200  if (!settings_ptr_->objects_to_sample.empty()) {
201  bool isObjectToSample = false;
202  for (const std::pair<std::string, std::string> &type_to_id : settings_ptr_->objects_to_sample) {
203  if (type_to_id.first == candidate.type && type_to_id.second == candidate.identifier) {
204  isObjectToSample = true;
205  break;
206  }
207  }
208  if (!isObjectToSample) {
209  ROS_WARN_STREAM("Given object is disabled for sampling type: " << candidate.type << " id: " << candidate.identifier);
210  return true;
211  }
212  }
213 
214  double X_AXIS_ERROR;
215  double Y_AXIS_ERROR;
216  double Z_AXIS_ERROR;
217 
218  double ALPHA_ERROR;
219  double BETA_ERROR;
220  double GAMMA_ERROR;
221 
222  if (settings_ptr_->calculate_deviations) {
223  X_AXIS_ERROR = sqrt(3.0)/2.0 * settings_ptr_->bin_size;
224  Y_AXIS_ERROR = sqrt(3.0)/2.0 * settings_ptr_->bin_size;
225  Z_AXIS_ERROR = sqrt(3.0)/2.0 * settings_ptr_->bin_size;
226 
227  ALPHA_ERROR = settings_ptr_->maxProjectionAngleDeviation;
228  BETA_ERROR = settings_ptr_->maxProjectionAngleDeviation;
229  GAMMA_ERROR = settings_ptr_->maxProjectionAngleDeviation;
230  } else {
231  const std::string &recognizerName = (*model_type_ptr_per_type_map_ptr_)[candidate.type]->recognizerName;
232  if (recognizerName.size() == 0) {
233  ROS_ERROR_STREAM("RecognizerName for type/id" << candidate.type << "/" << candidate.identifier << " not found: Please check the ISM_Table.");
234  return false;
235  }
236 
237  asr_object_database::ObjectMetaData srv;
238  srv.request.object_type = candidate.type;
239  srv.request.recognizer = recognizerName;
240 
241  if (object_type_client_ptr_->call(srv)) {
242  std::vector<double> &deviations = srv.response.deviations;
243  if (deviations.size() == 6) {
244  std::vector<double>::iterator deviations_it = deviations.begin();
245 
246  debug_helper_ptr_->write(std::stringstream() << "Sampling object (type = " << candidate.type <<
247  ", id = " << candidate.identifier << ") with errors in", DebugHelper::FOUND_OBJECT);
248  X_AXIS_ERROR = *(deviations_it++);
249  Y_AXIS_ERROR = *(deviations_it++);
250  Z_AXIS_ERROR = *(deviations_it++);
251 
252  ALPHA_ERROR = *(deviations_it++);
253  BETA_ERROR = *(deviations_it++);
254  GAMMA_ERROR = *(deviations_it++);
255  } else {
256  ROS_ERROR_STREAM("The deviations from the objectdatabase has not 6 entries but " << deviations.size());
257  return false;
258  }
259  } else {
260  ROS_ERROR("Could not call the asr_object_database::ObjectMetaData service call");
261  return false;
262  }
263  }
264 
265  debug_helper_ptr_->write(std::stringstream() << "position.x [m] = " << X_AXIS_ERROR, DebugHelper::FOUND_OBJECT);
266  debug_helper_ptr_->write(std::stringstream() << "position.y [m] = " << Y_AXIS_ERROR, DebugHelper::FOUND_OBJECT);
267  debug_helper_ptr_->write(std::stringstream() << "position.z [m] = " << Z_AXIS_ERROR, DebugHelper::FOUND_OBJECT);
268  debug_helper_ptr_->write(std::stringstream() << "orientation.alpha [deg] = " << ALPHA_ERROR, DebugHelper::FOUND_OBJECT);
269  debug_helper_ptr_->write(std::stringstream() << "orientation.beta [deg] = " << BETA_ERROR, DebugHelper::FOUND_OBJECT);
270  debug_helper_ptr_->write(std::stringstream() << "orientation.gamma [deg] = " << GAMMA_ERROR, DebugHelper::FOUND_OBJECT);
271 
272  if (!candidate.sampledPoses.size()) {
273  ROS_ERROR_STREAM("Got a AsrObject without poses.");
274  return false;
275  }
276 
277  //Getting access to original pose estimation that resides in world model anyway.
278  const geometry_msgs::PoseWithCovariance detected_pose_with_c = candidate.sampledPoses.front();
279  const geometry_msgs::Pose &detected_pose = detected_pose_with_c.pose;
280 
281  debug_helper_ptr_->write(std::stringstream() << "Sampling around that position: x: "
282  << detected_pose.position.x << ", y: " << detected_pose.position.y << ", z: " << detected_pose.position.z, DebugHelper::FOUND_OBJECT);
283 
284  // *2, because we interpolate in + and - axis; +1, because we don't want the orginal pose to get lost
285  const int numberOfInterpolationsPerPosition = 2 * settings_ptr_->deviation_number_of_samples_position + 1;
286  const int numberOfInterpolationsPerOrientation = 2 * settings_ptr_->deviation_number_of_samples_orientation + 1;
287 
288 
289  //Sampling additional object poses for recognition result to consider pose uncertainty.
290  geometry_msgs::Pose interpolatedPoseMinX = detected_pose;
291  interpolatedPoseMinX.position.x -= X_AXIS_ERROR;
292  geometry_msgs::Pose interpolatedPoseMaxX = detected_pose;
293  interpolatedPoseMaxX.position.x += X_AXIS_ERROR;
294  std::vector<geometry_msgs::Pose> allInterpolatedPerX = interpolatePoses(interpolatedPoseMinX, interpolatedPoseMaxX, numberOfInterpolationsPerPosition);
295 
296  for (const geometry_msgs::Pose &interpolatedPerX : allInterpolatedPerX) {
297 
298  geometry_msgs::Pose interpolatedPoseMinY = interpolatedPerX;
299  interpolatedPoseMinY.position.y -= Y_AXIS_ERROR;
300  geometry_msgs::Pose interpolatedPoseMaxY = interpolatedPerX;
301  interpolatedPoseMaxY.position.y += Y_AXIS_ERROR;
302  std::vector<geometry_msgs::Pose> allInterpolatedPerY = interpolatePoses(interpolatedPoseMinY, interpolatedPoseMaxY, numberOfInterpolationsPerPosition);
303 
304  for (const geometry_msgs::Pose &interpolatedPerY : allInterpolatedPerY) {
305 
306  geometry_msgs::Pose interpolatedPoseMinZ = interpolatedPerY;
307  interpolatedPoseMinZ.position.z -= Z_AXIS_ERROR;
308  geometry_msgs::Pose interpolatedPoseMaxZ = interpolatedPerY;
309  interpolatedPoseMaxZ.position.z += Z_AXIS_ERROR;
310  std::vector<geometry_msgs::Pose> allInterpolatedPerZ = interpolatePoses(interpolatedPoseMinZ, interpolatedPoseMaxZ, numberOfInterpolationsPerPosition);
311 
312  for (const geometry_msgs::Pose &interpolatedPerZ : allInterpolatedPerZ) {
313 
314  std::vector<geometry_msgs::Pose> allInterpolatedPerAlpha =
315  interpolateOrientationAroundAxis(interpolatedPerZ, ALPHA_ERROR, Eigen::Vector3d::UnitX(), numberOfInterpolationsPerOrientation);
316 
317  for (const geometry_msgs::Pose &interpolatedPerAlpha : allInterpolatedPerAlpha) {
318 
319  std::vector<geometry_msgs::Pose> allInterpolatedPerBeta =
320  interpolateOrientationAroundAxis(interpolatedPerAlpha, BETA_ERROR, Eigen::Vector3d::UnitY(), numberOfInterpolationsPerOrientation);
321 
322  for (const geometry_msgs::Pose &interpolatedPerGamma : allInterpolatedPerBeta) {
323 
324  std::vector<geometry_msgs::Pose> allInterpolatedPerGamma =
325  interpolateOrientationAroundAxis(interpolatedPerGamma, GAMMA_ERROR, Eigen::Vector3d::UnitZ(), numberOfInterpolationsPerOrientation);
326 
327  for (const geometry_msgs::Pose &interpolatedPerGamma : allInterpolatedPerGamma) {
328 
329  double positionDistance = pose_helper_ptr_->calcDistancePositionEucl(interpolatedPerGamma, detected_pose);
330  double orientationDistance = fabs(pose_helper_ptr_->calcAngularDistanceInRad(interpolatedPerGamma, detected_pose));
331 
332  if (positionDistance <= EPSILON && orientationDistance <= EPSILON) {
333  // it is the same pose as the recorded one
334  continue;
335  }
336 
337  if (settings_ptr_->calculate_deviations) {
338  if (positionDistance - (sqrt(3.0)/2.0 * settings_ptr_->bin_size) >= EPSILON
339  || orientationDistance - (settings_ptr_->maxProjectionAngleDeviation * DEG_TO_RAD) >= EPSILON) {
340  continue;
341  }
342  }
343 
344  geometry_msgs::PoseWithCovariance current_pose_with_covariance;
345  current_pose_with_covariance.pose = interpolatedPerGamma;
346  current_pose_with_covariance.covariance = detected_pose_with_c.covariance;
347  candidate.sampledPoses.push_back(current_pose_with_covariance);
348  }
349  }
350  }
351  }
352  }
353  }
354 
355  ROS_INFO_STREAM("Number of sampled poses: " << candidate.sampledPoses.size() - 1);
356  return true;
357 }
358 
360  const geometry_msgs::Pose &poseToInterpolate, const double interpolationOffset, const Eigen::Vector3d &axisToRotate, const int numberOfInterpolationsPerOrientation) const {
361 
362  const geometry_msgs::Pose &interpolatedPoseMin = rotateOrientationAroundAxis(poseToInterpolate, interpolationOffset, axisToRotate);
363  const geometry_msgs::Pose &interpolatedPoseMax = rotateOrientationAroundAxis(poseToInterpolate, -1.0 * interpolationOffset, axisToRotate);
364 
365  return interpolatePoses(interpolatedPoseMin, interpolatedPoseMax, numberOfInterpolationsPerOrientation);
366 }
367 
369  const geometry_msgs::Pose &poseToRotate, const double interpolationOffset, const Eigen::Vector3d &axisToRotate) const {
370 
371  Eigen::Quaterniond poseToRotateQuat(poseToRotate.orientation.w,
372  poseToRotate.orientation.x,
373  poseToRotate.orientation.y,
374  poseToRotate.orientation.z);
375  poseToRotateQuat.normalize();
376 
377  Eigen::Matrix3d rotatedOffsetMat;
378  rotatedOffsetMat = Eigen::AngleAxisd(interpolationOffset * DEG_TO_RAD, axisToRotate);
379  Eigen::Quaterniond rotatedOffsetQuat(rotatedOffsetMat);
380  rotatedOffsetQuat.normalize();
381 
382  Eigen::Quaterniond rotatedPoseQuat = rotatedOffsetQuat * poseToRotateQuat;
383 
384  geometry_msgs::Pose rotatedPose = poseToRotate;
385  rotatedPose.orientation.w = rotatedPoseQuat.w();
386  rotatedPose.orientation.x = rotatedPoseQuat.x();
387  rotatedPose.orientation.y = rotatedPoseQuat.y();
388  rotatedPose.orientation.z = rotatedPoseQuat.z();
389  return rotatedPose;
390 }
391 
392 std::vector<geometry_msgs::Pose> FoundObjectHandler::interpolatePoses(const geometry_msgs::Pose &fromPose, const geometry_msgs::Pose &toPose, const int numberOfInterpolations) const {
393  std::vector<geometry_msgs::Pose> allInterpolatedPoses;
394 
395  Eigen::Vector3d fromPosition(fromPose.position.x, fromPose.position.y, fromPose.position.z);
396  Eigen::Vector3d toPosition(toPose.position.x, toPose.position.y, toPose.position.z);
397  Eigen::Quaterniond fromOrient(fromPose.orientation.w,
398  fromPose.orientation.x,
399  fromPose.orientation.y,
400  fromPose.orientation.z);
401  Eigen::Quaterniond toOrient(toPose.orientation.w,
402  toPose.orientation.x,
403  toPose.orientation.y,
404  toPose.orientation.z);
405 
406  double divisor = static_cast<double>(numberOfInterpolations + 1);
407  for (int i = 1; i <= numberOfInterpolations; ++i) {
408  double weightForFirst = (divisor - i) / divisor;
409  double weightForSecond = i / divisor;
410 
411  Eigen::Vector3d currentInterpolatedPosition = fromPosition * weightForFirst + toPosition * weightForSecond;
412  Eigen::Quaterniond currentInterpolatedQuat = fromOrient.slerp(weightForSecond, toOrient);
413 
414  geometry_msgs::Pose currentInterpolatedPose;
415  currentInterpolatedPose.position.x = currentInterpolatedPosition[0];
416  currentInterpolatedPose.position.y = currentInterpolatedPosition[1];
417  currentInterpolatedPose.position.z = currentInterpolatedPosition[2];
418  currentInterpolatedPose.orientation.w = currentInterpolatedQuat.w();
419  currentInterpolatedPose.orientation.x = currentInterpolatedQuat.x();
420  currentInterpolatedPose.orientation.y = currentInterpolatedQuat.y();
421  currentInterpolatedPose.orientation.z = currentInterpolatedQuat.z();
422 
423  bool isEquale = false;
424  for (const geometry_msgs::Pose &interpolatedPose : allInterpolatedPoses) {
425  if (pose_helper_ptr_->checkPosesAreApproxEquale(interpolatedPose, currentInterpolatedPose, EPSILON, EPSILON)) {
426  isEquale = true;
427  break;
428  }
429  }
430  if (!isEquale) {
431  allInterpolatedPoses.push_back(currentInterpolatedPose);
432  }
433  }
434  return allInterpolatedPoses;
435 }
436 
438  world_model_visualizer_ptr_->clearLastPublication();
439  for (const std::pair<std::string, ModelTypePtr> &model_type_ptr_per_type_pair: *model_type_ptr_per_type_map_ptr_) {
440  for (const std::pair<std::string, ModelObjectPtr> &model_object_ptr_per_id_pair : model_type_ptr_per_type_pair.second->model_object_ptr_per_id_map) {
441  for (const PbdObjectCluster &best_object_hypotheses : model_object_ptr_per_id_pair.second->bestHypotheses) {
442  world_model_visualizer_ptr_->addFoundObjectVisualization(best_object_hypotheses.first, false);
443  }
444  }
445  }
446  world_model_visualizer_ptr_->publishCollectedMarkers();
447 }
448 
449 bool FoundObjectHandler::processVisualizeSampledPosesCall(asr_world_model::VisualizeSampledPoses::Request &request,
450  asr_world_model::VisualizeSampledPoses::Response &response) {
451  debug_helper_ptr_->write(std::stringstream() << "Calling processVisualizeSampledPosesCall for object_type: "
452  << request.object_type << " object_id: " << request.object_id, (DebugHelper::SERVICE_CALLS + DebugHelper::FOUND_OBJECT));
453 
454  //Check if given candidate is known
455  ModelTypePtrPerTypeMap::iterator type_it = model_type_ptr_per_type_map_ptr_->find(request.object_type);
456  if (type_it == model_type_ptr_per_type_map_ptr_->end()) {
457  ROS_WARN_STREAM("The given type was not in the ISM_Tables -> processVisualizeSampledPosesCall not possible: " << request.object_type);
458  return false;
459  }
460 
461  ModelObjectPtrPerIdMap::iterator id_it = type_it->second->model_object_ptr_per_id_map.find(request.object_id);
462  if (id_it == type_it->second->model_object_ptr_per_id_map.end()) {
463  ROS_WARN_STREAM("The given type and id was not in the ISM_Tables -> processVisualizeSampledPosesCall not possible: type: " << request.object_type << ", id: " << request.object_id);
464  return false;
465  }
466 
467  const ModelObjectPtr &currentModelObjectPtr = id_it->second;
468 
469  for (const PbdObjectCluster &best_object_hypotheses : currentModelObjectPtr->bestHypotheses) {
470  world_model_visualizer_ptr_->addFoundObjectVisualization(best_object_hypotheses.first, true);
471  }
472 
473  world_model_visualizer_ptr_->publishCollectedMarkers();
474 
475  return true;
476 }
477 
478 
479 bool FoundObjectHandler::processEmptyFoundObjectListServiceCall(std_srvs::Empty::Request &request,
480  std_srvs::Empty::Response &response)
481 {
482  debug_helper_ptr_->write(std::stringstream() << "Calling processEmptyFoundObjectListServiceCall", (DebugHelper::SERVICE_CALLS + DebugHelper::FOUND_OBJECT));
483  for (const std::pair<std::string, ModelTypePtr> &model_type_ptr_per_type_pair: *model_type_ptr_per_type_map_ptr_) {
484  for (const std::pair<std::string, ModelObjectPtr> &model_object_ptr_per_id_pair : model_type_ptr_per_type_pair.second->model_object_ptr_per_id_map) {
485  model_object_ptr_per_id_pair.second->allFoundHypotheses.clear();
486  model_object_ptr_per_id_pair.second->bestHypotheses.clear();
487  }
488  }
489 
490  world_model_visualizer_ptr_->clearLastPublication();
491 
492  return true;
493 }
494 
495 bool FoundObjectHandler::processGetFoundObjectListServiceCall(asr_world_model::GetFoundObjectList::Request &request,
496  asr_world_model::GetFoundObjectList::Response &response)
497 {
498  debug_helper_ptr_->write(std::stringstream() << "Calling processGetFoundObjectListServiceCall", (DebugHelper::SERVICE_CALLS + DebugHelper::FOUND_OBJECT));
499 
500  unsigned int hypotheses_counter = 0;
501 
502  for (const std::pair<std::string, ModelTypePtr> &model_type_ptr_per_type_pair: *model_type_ptr_per_type_map_ptr_) {
503  for (const std::pair<std::string, ModelObjectPtr> &model_object_ptr_per_id_pair : model_type_ptr_per_type_pair.second->model_object_ptr_per_id_map) {
504  for (const PbdObjectCluster &best_object_hypotheses : model_object_ptr_per_id_pair.second->bestHypotheses) {
505  response.object_list.push_back(best_object_hypotheses.first);
506  ++hypotheses_counter;
507  }
508  }
509  }
510 
511  debug_helper_ptr_->write(std::stringstream() << "There are currently " << hypotheses_counter << " best hypotheses in the world_model", DebugHelper::FOUND_OBJECT);
512  return true;
513 }
514 
515 }
516 
boost::shared_ptr< ModelObject > ModelObjectPtr
bool processEmptyFoundObjectListServiceCall(std_srvs::Empty::Request &request, std_srvs::Empty::Response &response)
Empties the found object list.
geometry_msgs::Pose rotateOrientationAroundAxis(const geometry_msgs::Pose &poseToRotate, const double interpolationOffset, const Eigen::Vector3d &axisToRotate) const
boost::shared_ptr< WorldModelVisualizerRVIZ > WorldModelVisualizerRVIZPtr
FoundObjectHandler(boost::shared_ptr< ros::Publisher > marker_publisher_ptr, boost::shared_ptr< ros::ServiceClient > object_type_client_ptr, ModelTypePtrPerTypeMapPtr model_type_ptr_per_type_map_ptr, SettingsPtr settings_ptr)
Creates a new instance of FoundObjectHandler.
static boost::shared_ptr< PoseHelper > getInstance()
Definition: pose_helper.cpp:24
void updateBestHypothesis(ModelObjectPtr &currentModelObjectPtr, const asr_msgs::AsrObject &candidate)
bool processGetFoundObjectListServiceCall(asr_world_model::GetFoundObjectList::Request &request, asr_world_model::GetFoundObjectList::Response &response)
Returns the already found objects.
bool transformToBaseFrame(asr_msgs::AsrObject &candidate) const
Transform object pose to base frame of world model.
tf::TransformListener tf_transform_listener_
static boost::shared_ptr< DebugHelper > getInstance()
std::vector< geometry_msgs::Pose > interpolateOrientationAroundAxis(const geometry_msgs::Pose &poseToInterpolate, const double interpolationOffset, const Eigen::Vector3d &axisToRotate, const int numberOfInterpolationsPerOrientation) const
WorldModelVisualizerRVIZPtr world_model_visualizer_ptr_
#define ROS_WARN_STREAM(args)
boost::shared_ptr< ros::ServiceClient > object_type_client_ptr_
void lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, StampedTransform &transform) const
std::vector< geometry_msgs::Pose > interpolatePoses(const geometry_msgs::Pose &fromPose, const geometry_msgs::Pose &toPose, const int numberOfInterpolations) const
bool comparePbdObjectCluster(const PbdObjectCluster &first, const PbdObjectCluster &second)
bool processVisualizeSampledPosesCall(asr_world_model::VisualizeSampledPoses::Request &request, asr_world_model::VisualizeSampledPoses::Response &response)
#define ROS_INFO_STREAM(args)
void transformPose(const std::string &target_frame, const geometry_msgs::PoseStamped &stamped_in, geometry_msgs::PoseStamped &stamped_out) const
bool pushFoundObject(asr_msgs::AsrObject &candidate)
bool sampleFoundObject(asr_msgs::AsrObject &candidate)
Generates samples for object pose estimation to model uncertainty.
bool evaluateNeighborhood(const asr_msgs::AsrObject &object1, const asr_msgs::AsrObject &object2) const
Determines if two objects are neighbors to each other in terms of position and orientation distance...
#define ROS_ERROR_STREAM(args)
ModelTypePtrPerTypeMapPtr model_type_ptr_per_type_map_ptr_
boost::shared_ptr< ModelType > ModelTypePtr
Definition: model_type.hpp:36
#define ROS_ERROR(...)
bool processPushFoundObjectListServiceCall(asr_world_model::PushFoundObjectList::Request &request, asr_world_model::PushFoundObjectList::Response &response)
Pushes the found object to a list.
std::list< PbdObjectCluster > PbdObjectClusterList
std::pair< asr_msgs::AsrObject, int > PbdObjectCluster


asr_world_model
Author(s): Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Trautmann Jeremias
autogenerated on Thu Jan 9 2020 07:20:01