Go to the documentation of this file.00001 #include "pose2d_odom_alg_node.h"
00002 
00003 Pose2dOdomAlgNode::Pose2dOdomAlgNode(void)
00004 {
00005   
00006   
00007 
00008   
00009   this->pose2dodom_publisher_ = this->public_node_handle_.advertise<nav_msgs::Odometry>("pose2d_odom", 100);
00010 
00011   
00012   this->pose2din_subscriber_ = this->public_node_handle_.subscribe("pose2d", 100, &Pose2dOdomAlgNode::pose2din_callback, this);
00013 
00014   
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   
00035 
00036   
00037 
00038   
00039 
00040   
00041 }
00042 
00043 Pose2dOdomAlgNode::~Pose2dOdomAlgNode(void)
00044 {
00045   
00046 }
00047 
00048 void Pose2dOdomAlgNode::mainNodeThread(void)
00049 {
00050   
00051   
00052 
00053   ES->wait_all(SUBS_LIST);
00054   alg_.getOdometry(Odometry_msg_,Transform_msg_);
00055 
00056   
00057 
00058   
00059 
00060   
00061   this->pose2dodom_publisher_.publish(this->Odometry_msg_);
00062 
00063   if(publish_tf_)
00064     pose2dodom_broadcaster_.sendTransform(Transform_msg_);
00065 
00066 }
00067 
00068 
00069 void Pose2dOdomAlgNode::pose2din_callback(const geometry_msgs::Pose2D& msg)
00070 {
00071   
00072 
00073   
00074   
00075   
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   
00092 
00093   
00094   
00095   
00096 }
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 void Pose2dOdomAlgNode::node_config_update(Config &config, uint32_t level)
00105 {
00106 }
00107 
00108 void Pose2dOdomAlgNode::addNodeDiagnostics(void)
00109 {
00110 }
00111 
00112 
00113 int main(int argc,char *argv[])
00114 {
00115   return algorithm_base::main<Pose2dOdomAlgNode>(argc, argv, "pose2d_odom_alg_node");
00116 }