pose2d_odom_alg_node.cpp
Go to the documentation of this file.
00001 #include "pose2d_odom_alg_node.h"
00002 
00003 Pose2dOdomAlgNode::Pose2dOdomAlgNode(void)
00004 {
00005   //init class attributes if necessary
00006   //this->loop_rate_ = 2;//in [Hz]
00007 
00008   // [init publishers]
00009   this->pose2dodom_publisher_ = this->public_node_handle_.advertise<nav_msgs::Odometry>("pose2d_odom", 100);
00010 
00011   // [init subscribers]
00012   this->pose2din_subscriber_ = this->public_node_handle_.subscribe("pose2d", 100, &Pose2dOdomAlgNode::pose2din_callback, this);
00013 
00014   // Events
00015   ES = CEventServer::instance();
00016   std::stringstream const_time;
00017   const_time << ros::Time::now();
00018   P2D_IN = "pose2d_in_" + const_time.str();
00019   ES->create_event(P2D_IN);
00020   SUBS_LIST.push_back(P2D_IN);
00021   pose2d_arrived_ = false;
00022 
00023   this->public_node_handle_.param<std::string>("parent_id", parent_id_, "odom");
00024   alg_.parent_id_ = parent_id_;
00025   this->public_node_handle_.param<std::string>("frame_id", frame_id_, "pose2d");
00026   alg_.frame_id_ = frame_id_;
00027   this->public_node_handle_.param<bool>("publish_tf", publish_tf_, true);
00028 
00029   ROS_INFO("Publish TF: %d",publish_tf_);
00030   ROS_INFO("Parent ID: %s", parent_id_.c_str());
00031   ROS_INFO("Frame ID: %s",  frame_id_.c_str());
00032 
00033 
00034   // [init services]
00035 
00036   // [init clients]
00037 
00038   // [init action servers]
00039 
00040   // [init action clients]
00041 }
00042 
00043 Pose2dOdomAlgNode::~Pose2dOdomAlgNode(void)
00044 {
00045   // [free dynamic memory]
00046 }
00047 
00048 void Pose2dOdomAlgNode::mainNodeThread(void)
00049 {
00050   // [fill msg structures]
00051   //this->Odometry_msg.data = my_var;
00052 
00053   ES->wait_all(SUBS_LIST);
00054   alg_.getOdometry(Odometry_msg_,Transform_msg_);
00055 
00056   // [fill srv structure and make request to the server]
00057 
00058   // [fill action structure and make request to the action server]
00059 
00060   // [publish messages]
00061   this->pose2dodom_publisher_.publish(this->Odometry_msg_);
00062 
00063   if(publish_tf_)
00064     pose2dodom_broadcaster_.sendTransform(Transform_msg_);
00065 
00066 }
00067 
00068 /*  [subscriber callbacks] */
00069 void Pose2dOdomAlgNode::pose2din_callback(const geometry_msgs::Pose2D& msg)
00070 {
00071   //ROS_INFO("Pose2dOdomAlgNode::pose2din_callback: New Message Received");
00072 
00073   //use appropiate mutex to shared variables if necessary
00074   //this->driver_.lock();
00075   //this->pose2din_mutex_.enter();
00076 
00077   alg_.lock();
00078     if(pose2d_arrived_){
00079       alg_.old_pose2D_ = alg_.new_pose2D_;
00080       alg_.new_pose2D_ = msg;
00081       alg_.old_time_   = alg_.new_time_;
00082       alg_.new_time_   = ros::Time::now();
00083       ES->set_event(P2D_IN);
00084     }else{
00085       alg_.new_pose2D_ = msg;
00086       alg_.new_time_   = ros::Time::now();
00087       pose2d_arrived_ = true;
00088     }
00089   alg_.unlock();
00090 
00091   //std::cout << msg->data << std::endl;
00092 
00093   //unlock previously blocked shared variables
00094   //this->driver_.unlock();
00095   //this->pose2din_mutex_.exit();
00096 }
00097 
00098 /*  [service callbacks] */
00099 
00100 /*  [action callbacks] */
00101 
00102 /*  [action requests] */
00103 
00104 void Pose2dOdomAlgNode::node_config_update(Config &config, uint32_t level)
00105 {
00106 }
00107 
00108 void Pose2dOdomAlgNode::addNodeDiagnostics(void)
00109 {
00110 }
00111 
00112 /* main function */
00113 int main(int argc,char *argv[])
00114 {
00115   return algorithm_base::main<Pose2dOdomAlgNode>(argc, argv, "pose2d_odom_alg_node");
00116 }


iri_msg_to_odom
Author(s): Marti Morta, mmorta at iri.upc.edu
autogenerated on Fri Dec 6 2013 22:08:38