rviz: Need to display two different set of data

asked 2020-01-06 00:14:53 -0600

sunkingac4 gravatar image

Hi, I have a set of data from a known topic in a bag file.

And also I have another set of point data which is published in a c++ file. The code is

ros::Publisher ros_pub = nh.advertise<sensor_msgs::PointCloud2> ("ros_output", 1);
pcl::PointCloud<pcl::PointXYZ> cloud;
cloud.width  = 1200;
cloud.height = 1;
cloud.points.resize(cloud.width * cloud.height * 1);
for ( size_t i = 0; i < cloud.points.size(); i++)
{
    cloud.points[i].x = 512 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].y = 512 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].z = 512 * rand () / (RAND_MAX + 1.0f);
}
pcl::toROSMsg(cloud, output);
output.header.frame_id = "random_data";

ros::Rate loop_rate(1);
while (ros::ok())
{
    ros_pub.publish(output);
    ros::spinOnce();
    loop_rate.sleep();
}

The bag file is executed by $ rosbag play mydata.bag

And the C++ file is build using
catkin_make -DCMAKE_BUILD_TYPE=Release and executed as $ ./random_data

How can I display both data in the rviz with two different dataset with different frame_ids?

edit retag flag offensive close merge delete

Comments

You need to have a transform between your two frames. You can add code to your random cloud generating node that would publish this transform or the easier option would be to use the static transform publisher. If your transform does not change you could just run the following command (change to frames to what ever your topic frame_id parameters are).

rosrun tf static_transform_publisher 0.0 0.0 0.0 0.0 0.0 0.0 bag_data_frame random_data 100

If you don't know the frame of the data in your bag you could run rostopic echo -n1 /point_cloud_topic/from_bag | grep frame for example while the bag is running to find out what frame the messages are in.

The easiest hack to view both messages in rviz would be to change frame_id in line output.header.frame_id = "random_data"; to the same frame_id as the data in the bag. Then you ...(more)

Reamees gravatar image Reamees  ( 2020-01-06 07:22:29 -0600 )edit