I have navigation Odometry, but its some how not in the robot body frame. The odometry is being published in world frame, so its not correct. So i need to transform in the robot body frame as that how should be in the correct way. So I tried to republish the linear velocity in the x axis in the robot body frame but the code is not working. Here is the ros node

#include <ros/ros.h>
#include <tf/transform_broadcaster.h>
#include <nav_msgs/Odometry.h>

float linear_x;
ros::Publisher odom_pub;

void poseCallback(const nav_msgs::OdometryConstPtr& msg){
    linear_x = (msg->twist.twist.linear.x );
    nav_msgs::Odometry pose_gt_frame;

        pose_gt_frame.header.frame_id = "world";

    //set the velocity
    pose_gt_frame.child_frame_id = "rexrov2/base_link";
    pose_gt_frame.twist.twist.linear.x = linear_x;

    //publish the message


int main(int argc, char** argv){
  ros::init(argc, argv, "my_tf_broadcaster");
  ros::NodeHandle node;
  ros::Subscriber sub = node.subscribe("/rexrov2/pose_gt", 10, &poseCallback);
  return 0;

When run the code I got error

[FATAL] [1635340917.678039503, 15.652000000]: ASSERTION FAILED
    file = /opt/ros/melodic/include/ros/publisher.h
    line = 106
    cond = false
    message = 
[FATAL] [1635340917.680256176, 15.654000000]: Call to publish() on an invalid Publisher
[FATAL] [1635340917.680299807, 15.654000000]:

What can be wrong? Any help? Thanks


1 Answer 1


It sounds like you need a static frame transform node. I suggest you look up how to launch a static frame transform in a launch file. Static frame transforms allow you to connect 2 separate frames with a constant frame in between them. Usually, odometry is with respect to the robot base_link, not the world frame. The static transform automates the frame linking such that you don't have to write any C++ or python to connect frames.


I see what you did: you forgot to initialize the ROS topic that the publisher publishes too. In other words, you never called the constructor of the publisher. I suggest you look the documentation for how to do that.

  • $\begingroup$ I done static frame transform in the launch file and still not helping. Still the velocity is not in the robot base_link, instead of that is in world frame $\endgroup$
    – bob
    Oct 27, 2021 at 13:59
  • 1
    $\begingroup$ Hi @bob please edit your question to include a full description of your error and how you're trying to do it. The above answer looks to solve the primary problem encountered above which was the failure to initialize the publisher. You might even want to consider creating a new question about the transformation as that is a completely separate problem from the first one that you encountered. Please make sure to describe both how your setting up your problem as well as how you're debugging to know what frame information is in. $\endgroup$
    – Tully
    Oct 28, 2021 at 17:46
  • $\begingroup$ ok..I fix the error but still the problem with the frames is there, I will create another question also $\endgroup$
    – bob
    Oct 31, 2021 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.