Ask Your Question

Why there is no tf data and no messages in odom topic?

asked 2018-11-03 10:41:59 -0500

stevemartin gravatar image


I have created my odom topic as I want to use the simulation without the gazebo. Basically, I wrote this code using tf2, that publishes transform from odom to base_link (I do have a base_link) and also publishes 0 data to the odom topic. Everything works great if I turn on the gazebo but nothing when i try to publish odom myself without gazebo:

#include <ros/ros.h>
#include <nav_msgs/Odometry.h>
#include <tf2_ros/transform_broadcaster.h>
#include <tf2/LinearMath/Quaternion.h>
#include <geometry_msgs/TransformStamped.h>

int main(int argc, char** argv){
    ros::init(argc, argv, "odometry_publisher");

    ros::NodeHandle n;
    ros::Publisher odom_pub = n.advertise<nav_msgs::Odometry>("odom", 10);
    tf2_ros::TransformBroadcaster odom_broadcaster;

    double x = 0.0;
    double y = 0.0;
    double th = 0.0;

    double vx = 0.0;
    double vy = 0.0;
    double vth = 0.0;

    ros::Time current_time, last_time;
    current_time = ros::Time::now();
    last_time = ros::Time::now();

    ros::Rate r(50.0);


        current_time = ros::Time::now();

        double dt = (current_time-last_time).toSec();
        double delta_x = (vx * cos(th) - vy * sin(th)) * dt;
        double delta_y = (vx * sin(th) + vy * cos(th)) * dt;
        double delta_th = vth * dt;

        x += delta_x;
        y += delta_y;
        th += delta_th;

        // Setting the transform stamped messages:
        tf2::Quaternion q;
        geometry_msgs::TransformStamped odom_trans;
        odom_trans.header.stamp = current_time;
        odom_trans.header.frame_id = "odom";
        odom_trans.child_frame_id = "base_link";

        odom_trans.transform.translation.x = x;
        odom_trans.transform.translation.y = y;
        odom_trans.transform.translation.z = 0.0;
        odom_trans.transform.rotation.x = q.x();
        odom_trans.transform.rotation.y = q.y();
        odom_trans.transform.rotation.z = q.z();
        odom_trans.transform.rotation.w = q.w();

        // Send the transform:

        // Send the odometry messages to ROS:
        nav_msgs::Odometry odom;
        odom.header.stamp = current_time;
        odom.header.frame_id = "odom";
        // Here, take the positions from the wheelme backend whenever it reaches and send it to ros:
        odom.pose.pose.position.x = x;
        odom.pose.pose.position.y = y;
        odom.pose.pose.position.z = 0.0;
        odom.pose.pose.orientation.x = q.x();
        odom.pose.pose.orientation.x = q.y();
        odom.pose.pose.orientation.x = q.z();
        odom.pose.pose.orientation.x = q.w();

        // This values will be always zero until wheelme will start publishing its velocities:
        odom.child_frame_id = "base_link";
        odom.twist.twist.linear.x = vx;
        odom.twist.twist.linear.y = vy;
        odom.twist.twist.angular.z  = vth;

        // Now publish all that to odom topic:
        last_time = current_time;



When I check /odom topic nothing is there, no messages and when I do rosrun tf view_frames I get no tf data.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-11-03 10:49:01 -0500

stevemartin gravatar image

Nevermind guys, I just found my mistake. If anyone will face this problem just turn the use_sim_time to false in launch file like that:

<param name="use_sim_time" value="false" />

It actually makes sense, as gazebo publishes its simulated clock and if you turn it off, you have to use your host machine clock

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-11-03 10:41:59 -0500

Seen: 361 times

Last updated: Nov 03 '18