有导航里程计,但它有些不在机器人身体框架中。里程计正在世界框架中发布,因此它不正确。所以我需要在机器人身体框架中对其进行转换,因为它应该以正确的方式进行。所以我试图重新发布机器人身体框架中x轴的线速度,只是为了检查我是否以正确的方式,但代码不起作用。这是ROS节点
#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;
};
运行代码时出现错误
[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]:
而且启动文件中的静态框架也没有帮助。有什么问题?有什么帮助吗?谢谢