ROS rviz数据显示错误:Transform [sender=unknown_publisher] For frame []: Frame [] does not exist

Transform [sender=unknown_publisher]    For frame []: Frame [] does not exist

注意,[]不是用来SEO的通配符,中括号内实际就是空的。

主要问题出在topic的header上,问题原因乍一想没想到,因为我实际代码更复杂一点,是大消息套小数据,小数据有header,而大消息没header,代码上下文就不赘述了。这里放开注释和不放开注释是两种结果,rviz能显示和不能显示的区别。

C++嘛,都有默认值的,主动写header赋值默认值和不赋值有区别吗?可能C++没区别,rostopic echo也没区别!!!!!

但是RVIZ有区别!!!!

放开注释,消息就能在rviz显示,即便不给topic的header写frame_id。

仔细分析一下报错信息,不知道publisher是谁!!!后边的frame[]是空!

其实就很明显了,是header有问题!把header主动赋进去就好了。

提供一个简化的测试代码,通过调整注释观测rviz显示结果复现同样的报错。

#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>

int main(int argc, char** argv) {
  ros::init(argc, argv, "pointcloud_publisher");
  ros::NodeHandle nh;

  // Create a point cloud
  pcl::PointCloud<pcl::PointXYZ> cloud;
  cloud.width = 100;
  cloud.height = 1;
  cloud.points.resize(cloud.width * cloud.height);

  // Fill the point cloud with random points in a small area
  for (size_t i = 0; i < cloud.points.size(); ++i) {
    cloud.points[i].x = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
    cloud.points[i].y = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
    cloud.points[i].z = 0.0;
  }

  // Convert the point cloud to ROS message
  sensor_msgs::PointCloud2 output;
  pcl::toROSMsg(cloud, output);

  // Publish the point cloud
  ros::Publisher pub = nh.advertise<sensor_msgs::PointCloud2>("point_cloud", 1);
  ros::Rate loop_rate(1);
  while (ros::ok()) {
    // output.header.stamp = ros::Time::now();
    // output.header.frame_id = "test_base_link_frame";
    pub.publish(output);
    ros::spinOnce();
    loop_rate.sleep();
  }

  return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值