19 #include <sensor_msgs/PointCloud2.h> 20 #include <asr_msgs/AsrAttributedPointCloud.h> 21 #include <asr_msgs/AsrObject.h> 22 #include <inference/SceneInferenceEngine.h> 23 #include <inference/model/SceneIdentifier.h> 24 #include <asr_recognizer_prediction_psm/recognizer_prediction_psm.h> 25 #include <asr_recognizer_prediction_psm/psm_node.h> 28 std::vector<ProbabilisticSceneRecognition::SceneIdentifier>
doPSMInference(asr_recognizer_prediction_psm::psm_node::Request &req)
30 std::string base_frame_id =
"/map";
32 nh.
getParam(
"/psm_node/base_frame_id", base_frame_id);
33 nh.
setParam(
"/js_probabilistic_scene_inference_engine/base_frame_id", base_frame_id);
35 std::vector<asr_msgs::AsrObject> objects = req.objects;
36 std::vector<boost::shared_ptr<asr_msgs::AsrObject>> object_pointers;
39 for(asr_msgs::AsrObject o : objects)
43 p->identifier = o.identifier;
44 p->header.frame_id = o.header.frame_id;
45 if(!o.sampledPoses.size()){
46 std::cerr <<
"Got a AsrObject without poses." << std::endl;
49 p->sampledPoses.push_back(o.sampledPoses.front());
50 object_pointers.push_back(p);
63 ProbabilisticSceneRecognition::SceneInferenceEngine ie;
68 ie.newObservationCallback(o);
77 std::vector<ProbabilisticSceneRecognition::SceneIdentifier> pSceneList;
78 ie.getModel().getSceneListWithProbabilities(pSceneList);
87 printf(
"\nThis are the scene probabilities:\n");
88 for(ProbabilisticSceneRecognition::SceneIdentifier i : pSceneList)
89 printf(
" -> %s (%s): %f (%f)\n", i.mDescription.c_str(), i.mType.c_str(), i.mLikelihood, i.mPriori);
95 void doPrediction(std::vector<ProbabilisticSceneRecognition::SceneIdentifier> &pSceneList,
96 asr_recognizer_prediction_psm::psm_node::Request &req,
97 asr_recognizer_prediction_psm::psm_node::Response &res)
102 n.
getParam(
"/psm_node/visualize_hypothesis", vis);
103 n.
setParam(
"/recognizer_prediction_psm/visualize_hypothesis", vis);
106 asr_recognizer_prediction_psm::recognizer_prediction_psm srv;
115 std::string base_frame_id;
116 n.
getParam(
"/js_probabilistic_scene_inference_engine/scene_model_filename", path);
117 n.
getParam(
"/psm_node/num_hypothesis", votes);
118 n.
getParam(
"/psm_node/base_frame_id", base_frame_id);
119 srv.request.num_votes = votes;
120 srv.request.objects = req.objects;
121 srv.request.base_frame_id = base_frame_id;
122 srv.request.pathToXML = path;
124 std::vector<std::string> scenes;
125 std::vector<float> scene_probabilities;
127 for(ProbabilisticSceneRecognition::SceneIdentifier i : pSceneList)
129 scenes.push_back(i.mDescription.c_str());
130 scene_probabilities.push_back(i.mLikelihood);
133 srv.request.scenes = scenes;
134 srv.request.scene_probabilities = scene_probabilities;
140 if (client.
call(srv))
160 res.pose_hypothesis = srv.response.pose_hypothesis;
161 res.all_scene_objects_found = srv.response.all_scene_objects_found;
165 ROS_ERROR(
"Failed to call service recognizer_prediction_psm");
175 bool run(asr_recognizer_prediction_psm::psm_node::Request &req,
176 asr_recognizer_prediction_psm::psm_node::Response &res)
179 std::vector<ProbabilisticSceneRecognition::SceneIdentifier> pSceneList;
199 int main(
int argc,
char **argv)
201 ros::init(argc, argv,
"psm_node_server");
205 ROS_INFO(
"Ready to do the inference\n");
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
bool getNumberOfUnobservedObjects()
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
bool run(asr_recognizer_prediction_psm::psm_node::Request &req, asr_recognizer_prediction_psm::psm_node::Response &res)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ROSCPP_DECL void spin(Spinner &spinner)
void doPrediction(std::vector< ProbabilisticSceneRecognition::SceneIdentifier > &pSceneList, asr_recognizer_prediction_psm::psm_node::Request &req, asr_recognizer_prediction_psm::psm_node::Response &res)
std::vector< ProbabilisticSceneRecognition::SceneIdentifier > doPSMInference(asr_recognizer_prediction_psm::psm_node::Request &req)
bool getParam(const std::string &key, std::string &s) const
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
int main(int argc, char **argv)