How to republish odometry in different frame?
have navigation Odometry, but its some how it is not in the robot body frame. The odometry is being published in world frame, so its not correct. So i need to transform it 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, just to check that Im on the correct way, 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
odom_pub.publish(pose_gt_frame);
}
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);
ros::spin();
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
Take a look at prior answers: https://answers.ros.org/question/2320...
ok. Thanks