Go to the documentation of this file.00001 #include <ros/ros.h>
00002
00003 #include <tf/transform_broadcaster.h>
00004 #include <nav_msgs/Odometry.h>
00005 #include <string>
00006
00007 #define RATE 30
00008
00009 std::string tf_prefix;
00010 double pos_x =0;
00011 double pos_y =0;
00012 geometry_msgs::Quaternion odom_quat;
00013 ros::Time last_time;
00014 std::string odom_frame_id ="/odom";
00015 std::string odom_subcribe_topic="odom";
00016
00017
00018 void odom_cb(const nav_msgs::Odometry::ConstPtr& msg){
00019 last_time=msg->header.stamp;
00020 pos_x = msg->pose.pose.position.x;
00021 pos_y = msg->pose.pose.position.y;
00022 odom_quat = msg->pose.pose.orientation;
00023 }
00024 void time_cb(tf::TransformBroadcaster & odom_broadcast, const ros::TimerEvent& tm){
00025 geometry_msgs::TransformStamped odom_trans;
00026 odom_trans.header.stamp = last_time;
00027 odom_trans.header.frame_id = tf_prefix + odom_frame_id;
00028 odom_trans.child_frame_id = tf_prefix + "/base_footprint";
00029 odom_trans.transform.translation.x = pos_x;
00030 odom_trans.transform.translation.y = pos_y;
00031 odom_trans.transform.translation.z = 0.0;
00032 odom_trans.transform.rotation = odom_quat;
00033 odom_broadcast.sendTransform(std::move(odom_trans));
00034 }
00035
00036 int main(int argc, char ** argv){
00037
00038 ros::init(argc, argv, "odom_tf_broadcaster");
00039 ros::NodeHandle n;
00040
00041 std::string tf_prefix_path;
00042 if (n.searchParam("tf_prefix", tf_prefix_path))
00043 {
00044 n.getParam(tf_prefix_path, tf_prefix);
00045 }
00046 ros::param::get("~frameIDodom", odom_frame_id);
00047 ros::param::get("~odomSubsTopic", odom_subcribe_topic);
00048
00049 tf::TransformBroadcaster odom_broadcaster;
00050 geometry_msgs::Quaternion odom_quat = tf::createQuaternionMsgFromYaw(0);
00051 last_time = ros::Time::now();
00052
00053
00054 boost::function<void(const ros::TimerEvent&)> time_callback =
00055 std::bind(time_cb, std::ref(odom_broadcaster), std::placeholders::_1);
00056
00057
00058 ros::Timer timer = n.createTimer(ros::Duration(1.0/RATE), std::move(time_callback));
00059 ros::Subscriber subsc = n.subscribe(odom_subcribe_topic, 1000, odom_cb);
00060 ros::spin();
00061
00062 return 0;
00063 }