camera_object_learner_alg_node.cpp
Go to the documentation of this file.
00001 #include "camera_object_learner_alg_node.h"
00002 
00003 CameraObjectLearnerAlgNode::CameraObjectLearnerAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<CameraObjectLearnerAlgorithm>(),
00005   it(public_node_handle_)
00006 {
00007   //init class attributes if necessary
00008   //this->loop_rate_ = 2;//in [Hz]
00009   this->receiving_images = false;
00010   this->init_ok          = false;
00011 
00012   // [init publishers]
00013   this->image_publisher = it.advertise("image_out", 1);
00014   
00015   // [init subscribers]
00016   this->camera_subscriber = it.subscribe("image_in", 1, &CameraObjectLearnerAlgNode::image_callback, this);
00017   
00018   // [init services]
00019   
00020   // [init clients]
00021   init_client = this->public_node_handle_.serviceClient<iri_camera_object_learner_server::init>("init_client");
00022   
00023   // [init action servers]
00024   
00025   // [init action clients]
00026 }
00027 
00028 CameraObjectLearnerAlgNode::~CameraObjectLearnerAlgNode(void)
00029 {
00030   // [free dynamic memory]
00031 }
00032 
00033 void CameraObjectLearnerAlgNode::mainNodeThread(void)
00034 {
00035   this->alg_.lock();
00036   if(receiving_images)
00037   {
00038     if(!this->init_ok)
00039     {
00040       ROS_INFO("CameraObjectLearnerAlgNode::mainNodeThread: Calling init service!");
00041       if(init_client.call(init_srv))
00042       {
00043         if(init_srv.response.width >0 && init_srv.response.height >0)
00044         {
00045           this->init_rect = cv::Rect(init_srv.response.x,init_srv.response.y,init_srv.response.width,init_srv.response.height);
00046           //init alg
00047           this->alg_.unlock();
00048           this->init_ok = this->alg_.init_detector(this->input_image,this->init_rect);
00049           this->alg_.lock();
00050         }
00051         else
00052         {
00053           ROS_ERROR("CameraObjectLearnerAlgNode::mainNodeThread: Received rectangle empty or wrong!");
00054         }
00055       }
00056       else
00057       {
00058         ROS_ERROR("CameraObjectLearnerAlgNode::mainNodeThread: Failed to call init service!");
00059       }
00060     }
00061     else
00062     {
00063       ROS_DEBUG("CameraObjectLearnerAlgNode::mainNodeThread: Detect alg iteration!");
00064       this->alg_.unlock();
00065       //detect alg
00066       this->alg_.detect(this->input_image);
00067       //get image
00068       this->alg_.get_output_image(this->output_image);
00069       this->alg_.lock();
00070       //publish image
00071       this->image_publisher.publish(this->output_image);
00072     }
00073   }
00074   else
00075   {
00076     ROS_WARN("CameraObjectLearnerAlgNode::mainNodeThread: No images received!");
00077   }
00078   this->alg_.unlock();
00079   
00080   // [fill msg structures]
00081   
00082   // [fill srv structure and make request to the server]
00083   
00084   // [fill action structure and make request to the action server]
00085 
00086   // [publish messages]
00087 
00088 }
00089 
00090 /*  [subscriber callbacks] */
00091 
00092 void CameraObjectLearnerAlgNode::image_callback(const sensor_msgs::ImageConstPtr& image_msg)
00093 {
00094   static bool first=true;
00095   ROS_DEBUG("CameraObjectLearnerAlgNode::image_callback: New Message Received");
00096   this->alg_.lock();
00097   this->input_image=image_msg;
00098   if(first)
00099   {
00100     this->receiving_images = true;
00101     first=false;
00102   }
00103   this->alg_.unlock();
00104 }
00105 
00106 /*  [service callbacks] */
00107 
00108 /*  [action callbacks] */
00109 
00110 /*  [action requests] */
00111 
00112 void CameraObjectLearnerAlgNode::node_config_update(Config &config, uint32_t level)
00113 {
00114   this->alg_.lock();
00115   this->init_ok = config.init_ok;
00116   this->alg_.unlock();
00117 }
00118 
00119 void CameraObjectLearnerAlgNode::addNodeDiagnostics(void)
00120 {
00121 }
00122 
00123 /* main function */
00124 int main(int argc,char *argv[])
00125 {
00126   return algorithm_base::main<CameraObjectLearnerAlgNode>(argc, argv, "camera_object_learner_alg_node");
00127 }


iri_camera_object_learner
Author(s): fherrero
autogenerated on Fri Dec 6 2013 22:59:46