image_publisher_alg_node.cpp
Go to the documentation of this file.
00001 #include "image_publisher_alg_node.h"
00002 
00003 ImagePublisherAlgNode::ImagePublisherAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<ImagePublisherAlgorithm>(), imgtransport_(public_node_handle_)
00005 {
00006   //init class attributes if necessary
00007   //this->loop_rate_ = 2;//in [Hz]
00008   image_pub_ = imgtransport_.advertise("image", 1);
00009 
00010   this->filename_ = "~/default.jpg";
00011   cv_image.header.stamp = ros::Time::now();
00012   cv_image.header.frame_id = "camera";
00013   cv_image.encoding = "bgr8";
00014 
00015   ROS_INFO("Image reading");
00016   cv_image.image = cv::imread(this->filename_);
00017   ROS_INFO("Image read");
00018 
00019   if(cv_image.image.data==NULL){
00020     ROS_ERROR("Image %s could not be read", this->filename_.c_str());
00021     image_loaded = false;
00022   }else{
00023     ROS_INFO("Image %s read", this->filename_.c_str());
00024     image_loaded = true;
00025   } 
00026 
00027   ROS_INFO("Image read");
00028 
00029   // [init publishers]
00030   
00031   // [init subscribers]
00032   
00033   // [init services]
00034   
00035   // [init clients]
00036   
00037   // [init action servers]
00038   
00039   // [init action clients]
00040 }
00041 
00042 ImagePublisherAlgNode::~ImagePublisherAlgNode(void)
00043 {
00044   // [free dynamic memory]
00045 }
00046 
00047 void ImagePublisherAlgNode::mainNodeThread(void)
00048 {
00049   this->alg_.lock();
00050   if(image_loaded){
00051   // [fill msg structures]
00052     image_pub_.publish(cv_image.toImageMsg());
00053   }else{
00054   //  ROS_WARN("Image not loaded");
00055   }
00056   this->alg_.unlock();
00057   
00058   // [fill srv structure and make request to the server]
00059   
00060   // [fill action structure and make request to the action server]
00061 
00062   // [publish messages]
00063 }
00064 
00065 /*  [subscriber callbacks] */
00066 
00067 /*  [service callbacks] */
00068 
00069 /*  [action callbacks] */
00070 
00071 /*  [action requests] */
00072 
00073 void ImagePublisherAlgNode::node_config_update(Config &config, uint32_t level)
00074 {
00075   this->alg_.lock();
00076 
00077   ROS_INFO("Image reading config");
00078   this->filename_ = config.filename;
00079 
00080   cv_image.header.stamp = ros::Time::now();
00081   cv_image.header.frame_id = "camera";
00082   cv_image.encoding = "bgr8";
00083   ROS_INFO("Image reading");
00084   cv_image.image = cv::imread(filename_, -1);
00085 
00086   if(cv_image.image.data==NULL){
00087     ROS_ERROR("Image %s could not be read", this->filename_.c_str());
00088     image_loaded = false;
00089   }else{
00090     ROS_INFO("Image %s read", this->filename_.c_str());
00091     image_loaded = true;
00092   }
00093 
00094   this->alg_.unlock();
00095 }
00096 
00097 void ImagePublisherAlgNode::addNodeDiagnostics(void)
00098 {
00099 }
00100 
00101 /* main function */
00102 int main(int argc,char *argv[])
00103 {
00104   return algorithm_base::main<ImagePublisherAlgNode>(argc, argv, "image_publisher_alg_node");
00105 }


iri_image_publisher
Author(s):
autogenerated on Fri Dec 6 2013 22:33:09