my_labeler_alg_node.cpp
Go to the documentation of this file.
00001 #include "my_labeler_alg_node.h"
00002 
00003 MyLabelerAlgNode::MyLabelerAlgNode(void) :
00004   algorithm_base::IriBaseAlgorithm<MyLabelerAlgorithm>()
00005 {
00006   //init class attributes if necessary
00007   //this->loop_rate_ = 2;//in [Hz]
00008 
00009   // [init publishers]
00010   
00011   // [init subscribers]
00012   this->scan_subscriber_ = this->public_node_handle_.subscribe("scan", 100, &MyLabelerAlgNode::scan_callback, this);
00013   this->goal_subscriber_ = this->public_node_handle_.subscribe("goal", 100, &MyLabelerAlgNode::goal_callback, this);
00014   
00015   // [init services]
00016   
00017   // [init clients]
00018         std::string homepath = getenv("HOME");
00019         string fileString = homepath + "/Desktop/social_forces_data/traj.txt";
00020         file_out_ = fopen ( fileString.c_str() , "w");  
00021 
00022   
00023   // [init action servers]
00024   
00025   // [init action clients]
00026 }
00027 
00028 MyLabelerAlgNode::~MyLabelerAlgNode(void)
00029 {
00030   // [free dynamic memory]
00031         //file_out_.close();
00032         fclose(file_out_);
00033 }
00034 
00035 void MyLabelerAlgNode::mainNodeThread(void)
00036 {
00037   // [fill msg structures]
00038   
00039   // [fill srv structure and make request to the server]
00040   
00041   // [fill action structure and make request to the action server]
00042 
00043   // [publish messages]
00044 }
00045 
00046 /*  [subscriber callbacks] */
00047 void MyLabelerAlgNode::scan_callback(const sensor_msgs::LaserScan::ConstPtr& msg) 
00048 { 
00049   //ROS_INFO("MyLabelerAlgNode::scan_callback: New Message Received"); 
00050 
00051 
00052   //use appropiate mutex to shared variables if necessary 
00053         this->alg_.lock(); 
00054         this->scan_mutex_.enter(); 
00055 
00056   //std::cout << msg->data << std::endl; 
00057         bag_time_ = msg->header.stamp.toSec();
00058   //unlock previously blocked shared variables 
00059         this->alg_.unlock(); 
00060         this->scan_mutex_.exit(); 
00061 }
00062 void MyLabelerAlgNode::goal_callback(const geometry_msgs::PoseStamped::ConstPtr& msg) 
00063 { 
00064   //ROS_INFO("MyLabelerAlgNode::goal_callback: New Message Received"); 
00065 
00066   //use appropiate mutex to shared variables if necessary 
00067   //this->alg_.lock(); 
00068   //this->goal_mutex_.enter(); 
00069         ROS_INFO("x = %f , y = %f, t = %lf", msg->pose.position.x , msg->pose.position.y , bag_time_ );
00070         //file_out_ << " " <<  msg->pose.position.x << " " << msg->pose.position.y << endl;
00071         //fprintf( file_out_ , "\%  position.x  position.y time\n" );
00072         fprintf( file_out_ , " %f    %f    %lf\n", msg->pose.position.x , msg->pose.position.y , bag_time_  );
00073   //std::cout << msg->data << std::endl; 
00074 
00075   //unlock previously blocked shared variables 
00076   //this->alg_.unlock(); 
00077   //this->goal_mutex_.exit(); 
00078 }
00079 
00080 /*  [service callbacks] */
00081 
00082 /*  [action callbacks] */
00083 
00084 /*  [action requests] */
00085 
00086 void MyLabelerAlgNode::node_config_update(Config &config, uint32_t level)
00087 {
00088   this->alg_.lock();
00089 
00090   this->alg_.unlock();
00091 }
00092 
00093 void MyLabelerAlgNode::addNodeDiagnostics(void)
00094 {
00095 }
00096 
00097 /* main function */
00098 int main(int argc,char *argv[])
00099 {
00100   return algorithm_base::main<MyLabelerAlgNode>(argc, argv, "my_labeler_alg_node");
00101 }


iri_my_labeler
Author(s): Gonzalo Ferrer
autogenerated on Fri Dec 6 2013 22:25:47