odom_to_base.cpp
Go to the documentation of this file.
00001 #include "ros/ros.h"
00002 #include "tf/transform_broadcaster.h"
00003 #include "nav_msgs/Odometry.h"
00004 #include "geometry_msgs/PoseWithCovarianceStamped.h"
00005 
00006 
00007 geometry_msgs::TransformStamped odom_trans;
00008 geometry_msgs::TransformStamped combined_odom_trans;
00009 
00010 
00011 void Callback(const nav_msgs::Odometry::ConstPtr& msg)
00012 {
00013     odom_trans.header.stamp = msg->header.stamp;//ros::Time::now();
00014     odom_trans.header.frame_id = msg->header.frame_id;
00015     odom_trans.child_frame_id = msg->child_frame_id;
00016 
00017     odom_trans.transform.translation.x = msg->pose.pose.position.x;
00018     odom_trans.transform.translation.y = msg->pose.pose.position.y;
00019     odom_trans.transform.translation.z = msg->pose.pose.position.z;
00020     odom_trans.transform.rotation = msg->pose.pose.orientation;
00021         
00022 }
00023 
00024 void CallbackCombined(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& msg)
00025 {
00026     combined_odom_trans.header.stamp = ros::Time::now();
00027     combined_odom_trans.header.frame_id = "odom_combined";
00028     combined_odom_trans.child_frame_id = "base_link";
00029 
00030     combined_odom_trans.transform.translation.x = msg->pose.pose.position.x;
00031     combined_odom_trans.transform.translation.y = msg->pose.pose.position.y;
00032     combined_odom_trans.transform.translation.z = msg->pose.pose.position.z;
00033     combined_odom_trans.transform.rotation = msg->pose.pose.orientation;
00034         
00035 }
00036 
00037 int main(int argc, char** argv){
00038   ros::init(argc, argv, "odom_to_base");
00039 
00040   ros::NodeHandle n;
00041  // ros::Publisher odom_pub = n.advertise<nav_msgs::Odometry>("odom", 50);
00042   ros::Subscriber sub_odom = n.subscribe("odom", 1, Callback);
00043   ros::Subscriber sub_odom_combined = n.subscribe("robot_pose_ekf/odom_combined", 1, CallbackCombined);
00044   
00045   tf::TransformBroadcaster odom_broadcaster;
00046         tf::TransformBroadcaster combined_odom_broadcaster;
00047   ros::Rate r(100);
00048   
00049   while(n.ok())
00050   {
00051 
00052         // check for incoming messages
00053     ros::spinOnce();               
00054     
00055     //send the transform
00056     odom_broadcaster.sendTransform(odom_trans);
00057 //   combined_odom_broadcaster.sendTransform(combined_odom_trans);
00058                 
00059    r.sleep();
00060   }
00061 }


evarobot_state_publisher
Author(s): Mehmet Akcakoca
autogenerated on Sat Jun 8 2019 20:01:22