vws_alg_node.cpp
Go to the documentation of this file.
00001 #include "vws_alg_node.h"
00002 
00003 VwsAlgNode::VwsAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<VwsAlgorithm>()
00005 {
00006   //init class attributes if necessary
00007   //this->loop_rate_ = 2;//in [Hz]
00008 
00009   // [init publishers]
00010   
00011   // [init subscribers]
00012   
00013   // [init services]
00014   this->set_centroids_server_ = this->public_node_handle_.advertiseService("set_centroids", &VwsAlgNode::set_centroidsCallback, this);
00015   this->get_vws_server_ = this->public_node_handle_.advertiseService("get_vws", &VwsAlgNode::get_vwsCallback, this);
00016   
00017   // [init clients]
00018   
00019   // [init action servers]
00020   
00021   // [init action clients]
00022 }
00023 
00024 VwsAlgNode::~VwsAlgNode(void)
00025 {
00026   // [free dynamic memory]
00027 }
00028 
00029 void VwsAlgNode::mainNodeThread(void)
00030 {
00031   // [fill msg structures]
00032   
00033   // [fill srv structure and make request to the server]
00034   
00035   // [fill action structure and make request to the action server]
00036 
00037   // [publish messages]
00038 }
00039 
00040 /*  [subscriber callbacks] */
00041 
00042 /*  [service callbacks] */
00043 bool VwsAlgNode::set_centroidsCallback(iri_publish_params::classifier_update_service::Request &req, iri_publish_params::classifier_update_service::Response &res) 
00044 { 
00045         ROS_INFO("VwsAlgNode::set_centroidsCallback: New Request Received!"); 
00046         
00047         //use appropiate mutex to shared variables if necessary 
00048         this->alg_.lock(); 
00049         //this->set_centroids_mutex_.enter(); 
00050         
00051         // If something fails maybe size is incorrect
00052         ROS_INFO_STREAM("Size " << req.params.update_params.size() << " y "  << req.params.update_params[0].params.size());
00053         
00054         // each row is a descriptor
00055         this->alg_.centroids_ = cv::Mat::zeros(req.params.update_params.size(), req.params.update_params[0].params.size(), CV_32FC1); // (rows, cols)
00056         for(size_t i=0; i < req.params.update_params.size(); i++) {
00057                 for(size_t j=0; j< req.params.update_params[i].params.size(); j++) {
00058                   this->alg_.centroids_.at<float>(i,j) = (float)req.params.update_params[i].params[j];
00059                 }
00060         }
00061         
00062         this->alg_.centroids_ready_ = true;
00063         
00064         //unlock previously blocked shared variables 
00065         this->alg_.unlock(); 
00066         //this->set_centroids_mutex_.exit(); 
00067         res.result = true;
00068         
00069         return true; 
00070 }
00071 bool VwsAlgNode::get_vwsCallback(iri_perception_msgs::DescriptorsToVws::Request &req, iri_perception_msgs::DescriptorsToVws::Response &res) 
00072 { 
00073         ROS_INFO("VwsAlgNode::get_vwsCallback: New Request Received!"); 
00074 
00075         //use appropiate mutex to shared variables if necessary 
00076         //this->alg_.lock(); 
00077         //this->get_vws_mutex_.enter(); 
00078         
00079         if (this->alg_.centroids_ready_) {
00080                 ROS_DEBUG("Getting geo_vw.");
00081                 res.geo_vw_set = this->alg_.get_geo_vw_from_descriptors(req);
00082                 return true;
00083         }
00084         else {
00085                 ROS_ERROR("iri_vws: Need centroids!");
00086                 return false;
00087         }
00088 
00089         //unlock previously blocked shared variables 
00090         //this->alg_.unlock(); 
00091         //this->get_vws_mutex_.exit(); 
00092 
00093         //return true; 
00094 }
00095 
00096 /*  [action callbacks] */
00097 
00098 /*  [action requests] */
00099 
00100 void VwsAlgNode::node_config_update(Config &config, uint32_t level)
00101 {
00102   this->alg_.lock();
00103 
00104   this->alg_.unlock();
00105 }
00106 
00107 void VwsAlgNode::addNodeDiagnostics(void)
00108 {
00109 }
00110 
00111 /* main function */
00112 int main(int argc,char *argv[])
00113 {
00114   return algorithm_base::main<VwsAlgNode>(argc, argv, "vws_alg_node");
00115 }


iri_vws
Author(s): dmartinez
autogenerated on Fri Dec 6 2013 22:49:05