Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <tf/transform_broadcaster.h>
00003 #include <geometry_msgs/TransformStamped.h>
00004 #include <nav_msgs/Odometry.h>
00005
00006 double m_vel_x, m_vel_y, m_vel_th;
00007 geometry_msgs::TransformStamped odom_tf;
00008 nav_msgs::Odometry odom_new;
00009
00010 void callback(const nav_msgs::Odometry::ConstPtr& odom_old)
00011 {
00012 m_vel_x = odom_old->twist.twist.linear.x;
00013 m_vel_y = odom_old->twist.twist.linear.y;
00014 m_vel_th = odom_old->twist.twist.angular.z;
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 }
00025
00026 int main(int argc, char **argv)
00027 {
00028 ros::init(argc, argv, "odom_fix");
00029 ros::NodeHandle n;
00030
00031 ros::Time m_currentTime;
00032 ros::Time m_lastTime;
00033 double m_pos_x, m_pos_y, m_pos_th;
00034
00035 tf::TransformBroadcaster odom_bro;
00036
00037
00038
00039 ros::Publisher pub = n.advertise<nav_msgs::Odometry>("odom", 10);
00040 ros::Subscriber sub = n.subscribe("odom_old",10,callback);
00041 ros::Rate loop_rate(5);
00042
00043 while(ros::ok())
00044 {
00045 m_currentTime = ros::Time::now();
00046 double dt = (m_currentTime - m_lastTime).toSec();
00047 double delta_x = (m_vel_x * cos(m_pos_th) - m_vel_y * sin(m_pos_th)) * dt;
00048 double delta_y = (m_vel_x * sin(m_pos_th) + m_vel_y * cos(m_pos_th)) * dt;
00049 double delta_th = m_vel_th * dt;
00050 m_pos_x += delta_x;
00051 m_pos_y += delta_y;
00052 m_pos_th += delta_th;
00053
00054
00055 geometry_msgs::Quaternion odom_quat = tf::createQuaternionMsgFromRollPitchYaw(0,0,m_pos_th*1.01);
00056 odom_new.header.stamp = m_currentTime;
00057 odom_new.header.frame_id = "odom";
00058 odom_new.child_frame_id = "base_footprint";
00059 odom_new.pose.pose.position.x = m_pos_x*1.304;
00060 odom_new.pose.pose.position.y = m_pos_y;
00061 odom_new.pose.pose.position.z = 0.0;
00062 odom_new.twist.twist.linear.x = m_vel_x;
00063 odom_new.twist.twist.linear.y = m_vel_y;
00064 odom_new.twist.twist.linear.z = 0.0;
00065 odom_new.twist.twist.angular.x = 0.0;
00066 odom_new.twist.twist.angular.y = 0.0;
00067 odom_new.twist.twist.angular.z = m_vel_th;
00068 odom_new.pose.pose.orientation = odom_quat;
00069
00070 pub.publish(odom_new);
00071
00072 odom_tf.header.stamp = m_currentTime;
00073 odom_tf.header.frame_id = "odom";
00074 odom_tf.child_frame_id = "base_footprint";
00075 odom_tf.transform.translation.x = m_pos_x*1.304;
00076 odom_tf.transform.translation.y = m_pos_y;
00077 odom_tf.transform.translation.z = 0.0;
00078 odom_tf.transform.rotation = odom_quat;
00079 odom_bro.sendTransform(odom_tf);
00080 m_vel_x = 0;
00081 m_vel_y = 0;
00082 m_vel_th = 0;
00083 loop_rate.sleep();
00084 m_lastTime = m_currentTime;
00085 ros::spinOnce();
00086
00087 }
00088
00089 }