ObjectHelper.h
Go to the documentation of this file.
1 
20 #pragma once
21 
22 #include <ros/ros.h>
23 #include <string>
24 #include <map>
25 #include "asr_object_database/ObjectMetaData.h"
26 #include "asr_world_model/GetRecognizerName.h"
27 #include "asr_world_model/GetIntermediateObjectWeight.h"
28 
29 namespace next_best_view {
30  typedef asr_object_database::ObjectMetaData::Response ObjectMetaDataResponse;
31  typedef ObjectMetaDataResponse::Ptr ObjectMetaDataResponsePtr;
32  typedef asr_world_model::GetIntermediateObjectWeight::Response IntermediateObjectWeightResponse;
33  typedef IntermediateObjectWeightResponse::Ptr IntermediateObjectWeightResponsePtr;
34 
38  class ObjectHelper {
39  private:
40  struct State {
41  private:
43  public:
47 
48  std::map<std::string, ObjectMetaDataResponsePtr> object_metadata_cache;
49  std::map<std::string, IntermediateObjectWeightResponsePtr> intermediate_object_cache;
50 
51  State() : mNodeHandle() {
52  object_metadata_service_client = mNodeHandle.serviceClient
53  <asr_object_database::ObjectMetaData>("/asr_object_database/object_meta_data");
54  recognizer_name_service_client = mNodeHandle.serviceClient
55  <asr_world_model::GetRecognizerName>("/env/asr_world_model/get_recognizer_name");
56  intermediate_object_weight_service_client = mNodeHandle.serviceClient
57  <asr_world_model::GetIntermediateObjectWeight>("/env/asr_world_model/get_intermediate_object_weight");
58  }
59  };
60 
62  static const boost::shared_ptr<State> statePtr = boost::shared_ptr<State>(new State());
63  return statePtr;
64  }
65 
66 
67  public:
69 
70  /* Gets the meta date of one object from the world_model with the name of objectTypeName.
71  *
72  */
73  ObjectMetaDataResponsePtr getObjectMetaData(std::string objectTypeName) {
75 
76  ObjectMetaDataResponsePtr responsePtr = statePtr->object_metadata_cache[objectTypeName];
77 
78  if (!responsePtr) {
79  asr_world_model::GetRecognizerName getRecognizerName;
80  getRecognizerName.request.object_type = objectTypeName;
81 
82  if (!statePtr->recognizer_name_service_client.exists()) {
83  ROS_ERROR_STREAM("/env/asr_world_model/get_recognizer_name service is not available");
84  }
85  statePtr->recognizer_name_service_client.call(getRecognizerName);
86 
87  std::string recognizer = getRecognizerName.response.recognizer_name;
88 
89  if (recognizer.compare("") == 0) {
90  ROS_ERROR_STREAM("No recognizer name received from world_model for object type " << objectTypeName << ".");
91  }
92 
93  asr_object_database::ObjectMetaData objectMetaData;
94  objectMetaData.request.object_type = objectTypeName;
95  objectMetaData.request.recognizer = recognizer;
96 
97  if (!statePtr->object_metadata_service_client.exists()) {
98  ROS_ERROR_STREAM("/asr_object_database/object_meta_data service is not available");
100  }
101  statePtr->object_metadata_service_client.call(objectMetaData);
102 
103  if (!objectMetaData.response.is_valid) {
104  ROS_ERROR_STREAM("objectMetadata response is not valid for object type " << objectTypeName);
105  return ObjectMetaDataResponsePtr();
106  }
107 
108  responsePtr = ObjectMetaDataResponsePtr(new ObjectMetaDataResponse(objectMetaData.response));
109  statePtr->object_metadata_cache[objectTypeName] = responsePtr;
110  }
111  return responsePtr;
112  }
113 
114  /* Gets the intermediate object from the world_model with the name of objectTypeName.
115  *
116  */
117  IntermediateObjectWeightResponsePtr getIntermediateObjectValue(std::string objectTypeName) {
119 
120  IntermediateObjectWeightResponsePtr responsePtr = statePtr->intermediate_object_cache[objectTypeName];
121 
122  if (!responsePtr) {
123  asr_world_model::GetIntermediateObjectWeight getIntermediateObjectWeight;
124  getIntermediateObjectWeight.request.object_type = objectTypeName;
125 
126  if (!statePtr->intermediate_object_weight_service_client.exists()) {
127  ROS_ERROR_STREAM("/env/asr_world_model/get_intermediate_object_weight service is not available");
129  }
130  statePtr->intermediate_object_weight_service_client.call(getIntermediateObjectWeight);
131 
132  ROS_ERROR_STREAM("GOT WEIGHT FROM WORLD MODEL " << getIntermediateObjectWeight.response.value);
133 
134  responsePtr = IntermediateObjectWeightResponsePtr(new IntermediateObjectWeightResponse(getIntermediateObjectWeight.response));
135 
136  statePtr->intermediate_object_cache[objectTypeName] = responsePtr;
137  }
138 
139  return responsePtr;
140  }
141  };
142 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
ros::ServiceClient object_metadata_service_client
Definition: ObjectHelper.h:44
IntermediateObjectWeightResponse::Ptr IntermediateObjectWeightResponsePtr
Definition: ObjectHelper.h:33
ros::ServiceClient recognizer_name_service_client
Definition: ObjectHelper.h:45
std::map< std::string, IntermediateObjectWeightResponsePtr > intermediate_object_cache
Definition: ObjectHelper.h:49
std::map< std::string, ObjectMetaDataResponsePtr > object_metadata_cache
Definition: ObjectHelper.h:48
IntermediateObjectWeightResponsePtr getIntermediateObjectValue(std::string objectTypeName)
Definition: ObjectHelper.h:117
this namespace contains all generally usable classes.
ObjectMetaDataResponsePtr getObjectMetaData(std::string objectTypeName)
Definition: ObjectHelper.h:73
static boost::shared_ptr< State > InstancePtr()
Definition: ObjectHelper.h:61
asr_object_database::ObjectMetaData::Response ObjectMetaDataResponse
Definition: ObjectHelper.h:30
asr_world_model::GetIntermediateObjectWeight::Response IntermediateObjectWeightResponse
Definition: ObjectHelper.h:32
ObjectMetaDataResponse::Ptr ObjectMetaDataResponsePtr
Definition: ObjectHelper.h:31
#define ROS_ERROR_STREAM(args)
ros::ServiceClient intermediate_object_weight_service_client
Definition: ObjectHelper.h:46


asr_next_best_view
Author(s): Aumann Florian, Borella Jocelyn, Heller Florian, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
autogenerated on Thu Jan 9 2020 07:20:18