iri_deformable_analysis.cpp
Go to the documentation of this file.
00001 #include "iri_deformable_analysis.h"
00002 #include "iri_deformable_analysis/SetScoreMixAlgorithmID.h"
00003 #include <sensor_msgs/PointCloud2.h>
00004 
00005 IRIDeformableAnalysis::IRIDeformableAnalysis() :
00006     score_results_recieved_event_("score_results")
00007 {
00008     /* Enable the input service */
00009     deformable_service_ = nh_.advertiseService("do_deformable_analysis", 
00010                                                & IRIDeformableAnalysis::deformable_analysis_callback, this);
00011     /* Output topic */
00012     deformable_pcl_publisher_ = nh_.advertise<sensor_msgs::PointCloud2>("pcl_input", 100);
00013     /* Returning topic */
00014     score_results_subscriber_ = nh_.subscribe<iri_deformable_analysis::ScoreMapMixResults>("deformable_score_results", 1,
00015                                                           & IRIDeformableAnalysis::score_results_callback, this);
00016     score_results_recieved_event_.reset();
00017     ROS_INFO("Deformable analysis ready");
00018 }
00019 
00020 bool
00021 IRIDeformableAnalysis::deformable_analysis_callback(iri_deformable_analysis::DoDeformableAnalysis::Request & req,
00022                                                     iri_deformable_analysis::DoDeformableAnalysis::Response & res)
00023 {
00024     ROS_INFO("Deformable analysis request recieved");
00025 
00026     /* 1. Call to config */
00027     iri_deformable_analysis::SetScoreMixAlgorithmID algorihtm_srv;
00028     algorihtm_srv.request.algorithm_id = req.fusion_criteria_id;
00029 
00030     if (! ros::service::exists("score_map_mix_node/set_score_mix_algorithm_id", true)) {
00031         ROS_ERROR("Algorithm ID can not be set");
00032         return false;
00033     }
00034 
00035     if (! ros::service::call("score_map_mix_node/set_score_mix_algorithm_id", algorihtm_srv)) {
00036         ROS_WARN("Set fusion algorithm criteria failed");
00037         return false;
00038     }
00039 
00040     /* 2. Publish PCL */
00041     deformable_pcl_publisher_.publish(req.pcl_to_analyze);
00042 
00043     /* 3. Wait for response */
00044     try
00045     {
00046         score_results_recieved_event_.wait(timeout_for_score_results_);
00047         ROS_INFO("Analysis recieved");
00048         score_results_recieved_event_.reset();
00049     }
00050     catch (CEventTimeoutException & e)
00051     {
00052         ROS_WARN("Timeout for deformable analysis");
00053         score_results_recieved_event_.reset();
00054         return false;
00055     }
00056     catch (CEventException & e)
00057     {
00058         ROS_WARN("Unexpected event exception %s", e.what().c_str());
00059         score_results_recieved_event_.reset();
00060         return false;
00061     }
00062 
00063     /* 4. return the service response */
00064     res.deformable_analysis.graspability.best_grasp_pose = last_score_results_.best_scored_pose;
00065 
00066     return true;
00067 }
00068 
00069 void
00070 IRIDeformableAnalysis::score_results_callback(const iri_deformable_analysis::ScoreMapMixResults::ConstPtr & msg)
00071 {
00072     /* Save the results and activate the event */
00073     ROS_INFO("Score results recieved");
00074     last_score_results_ = * msg;
00075     score_results_recieved_event_.set();
00076 }
00077 
00078 // Set up a default time of 60 seconds
00079 const IRIDeformableAnalysis::microseconds IRIDeformableAnalysis::timeout_for_score_results_ = 60 * 1000 * 1000;
00080 
00081 int main(int argc, char** argv)
00082 {
00083     ros::init(argc, argv, "deformable_analysis");
00084     IRIDeformableAnalysis server;
00085 
00086     ros::AsyncSpinner spinner(4); // Use 4 threads
00087     spinner.start();
00088     ros::waitForShutdown();
00089 
00090     return 0;
00091 }


iri_deformable_analysis
Author(s): Pol Monso, Arnau Ramisa, Jose Luis Rivero
autogenerated on Fri Dec 6 2013 21:15:35