pcd file to PointCloud visualization problem in Rviz [closed]
Hello, I have loaded a pcd file and converted it to sensor_msgs::PointCloud2 message type. When I add this point cloud to rviz screen, it needs to be rotated and translated.. my point cloud coordinate frame "pcl" and fixed frame is "map".. I dont know how to make transformation from pcl Coor. Frame to Map with tf/static_transform_publisher to visualize the point cloud properly..
this is my code:
int main(int argc, char **argv)
{
// Initialize ROS
ros::init (argc, argv, "my_pc_pub");
ros::NodeHandle nh;
ros::Rate loop_rate(0.1);
pcl::PCLPointCloud2 pcl_pc;
sensor_msgs::PointCloud2 msg;
sensor_msgs::PointCloud2 msg2;
tf::TransformListener tf_obj;
// Create a ROS publisher for the output point cloud
ros::Publisher pub = nh.advertise<pcl::PointCloud<pcl::PointXYZ>>("my_pc", 1);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile<pcl::PointXYZ> ("/home/largo/ws/table_scene_lms400_downsampled.pcd",*cloud) == -1)
{
PCL_ERROR("Could not read file");
return (-1);
}
std::cout<<"Loaded"
<<cloud->width * cloud->height
<<" data points from test_pcd.pcd with the following fields"
<<std::endl;
pcl::toPCLPointCloud2(*cloud, pcl_pc);
while (ros::ok())
{
pcl_conversions::fromPCL(pcl_pc, msg);
msg.header.frame_id="pcl";
msg.header.stamp = ros::Time::now();
pcl_ros::transformPointCloud("map",msg, msg2, tf_obj) ;
pub.publish(msg2); //my_pc topic
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
Can you please describe the behaviour your code produces? Does it compile? Does it cause a runtime error or does not perform the way you expect?
it runs and produces sensor_msgs::PointCloud2 messages, frame_id "pcl" When I visualize this message from rviz , i choose fixed_frame=pcl and rviz view type top-down Orthographic view, it is ok but i want it to be transformed according to map