Laser SLAM uses ros to save point cloud maps (take A-LOAM as an example)

Laser SLAM saves the point cloud map and uses the ros tool to save without recompiling the SLAM program.

Table of contents

method

Method 1: Save the recording topic as rosbag and then convert it to pcd

Method 2 directly save the topic as pcd

View point cloud map

pcl_viewer view

cloudcompareView

Convert pcd point cloud map to ply format for viewing


Take A-LOAM to run the kitti dataset as an example

To run the A-LOAM program, open two terminals and run

roslaunch aloam_velodyne aloam_velodyne_HDL_64.launch
rosbag play  --pause xxx.bag

method

Method 1: Save the recording topic as rosbag and then convert it to pcd

Record the map point cloud topic topic to be recorded with rosbag record, save it as a bag file, and then transfer the related topics in the bag to pcd format.

Specific steps:

1. Record it when you are about to finish running, open the terminal in the folder you want to save , and run

 rosbag record /laser_cloud_map

Two INFO messages will be displayed:

[ INFO] [......]: Subscribing to /laser_cloud_map
[ INFO] [......]: Recording to 'map.bag'.

After running, ctrl+C ends the recording, and the map file.bag file is saved in the folder.
2. Convert bag to pcd file

Switch to the directory where the map.bag file is located

rosrun pcl_ros bag_to_pcd map.bag /laser_cloud_map map.pcd

map.bag is converted to map.pcd. After rosrun finishes running, you can see that a pcd folder is generated, and the files inside are sorted according to the modification time. The latest one is the final point cloud map pcd file.

If the file saved in rosbag record has a suffix of .bag.active , it needs to be restored to a normal package with a suffix of ".bag". Repair process:

rosbag reindex xxx.bag.active

rosbag fix xxx.bag.active或者rosbag fix xxx.bag result.bag

After rosbag reindex and i generate a file with the suffix of .bag.org.active, this is only an intermediate file and does not need to be processed. rosbag fix still processes xxx.bag.active, if there is result.bag behind the fix, the repair file will be saved as result.bag.

Method 2 directly save the topic as pcd

Use the rosrun pcl_ros tool to directly save the map point cloud topic topic that needs to be recorded as a pcd file with rosrun pcl_ros.

Specific steps:

 Record when you are about to finish running, open the terminal in the folder you want to save , and run

rosrun pcl_ros pointcloud_to_pcd input:=/laser_cloud_map

At this time, the following INFO information appears on the terminal

[ INFO] [1683850358.621560685]: Saving as binary PCD
[ INFO] [1683850358.625476468]: Listening for incoming data on topic /laser_cloud_surround
[ INFO] [1683850360.540955903]: Received 7650 data points in frame camera_init with the following fields: x y z intensity
[ INFO] [1683850360.540990020]: Data saved to 1317653847034159.pcd
[ INFO] [1683850361.131458068]: Received 13486 data points in frame camera_init with the following fields: x y z intensity
[ INFO] [1683850361.131489694]: Data saved to 1317653847552311.pcd

。。。。。。

 rosrun pcl_ros pointcloud_to_pcd input:=Save a series of point clouds under the /laser_cloud_map topic topic to a folder in pcd format, sort the files in the folder according to the modification time, and the latest one is the last point cloud map pcd file.


View point cloud map

pcl_viewer view

pcl_viewer xxx.pcd

If not installed, you need to install it in advance

sudo apt-get install pcl-tools

cloudcompareView

open cloud compare

cloudcompare.ccViewer

cloudcompare.CloudCompare

Convert pcd point cloud map to ply format for viewing

pcl_pcd2ply xxx.pcd xxxxxxx.ply

Third-party software such as MatLab/MeshLab needs to convert pcd to ply when processing point cloud maps, and MeshLab must use the pointcloud_to_pcd method to create a point cloud converted from pcd to ply format!

ROS instruction explanation, from GPT

rosrun pcl_ros pointcloud_to_pcd

`rosrun pcl_ros pointcloud_to_pcd` is a ROS node used to convert point cloud data in ROS to PCD file format. 

When using the `rosrun pcl_ros pointcloud_to_pcd` command, you need to specify the topic name of the input point cloud data, as well as the name and path of the output PCD file. The specific usage method is as follows:

```
rosrun pcl_ros pointcloud_to_pcd input:=<input_topic_name> output:=<output_file_path>
```

Among them, `<input_topic_name>` is the ROS topic name of the input point cloud data, and `<output_file_path>` is the path and name of the output PCD file. For example:

```
rosrun pcl_ros pointcloud_to_pcd input:=/camera/depth/points output:=/home/user/pointcloud.pcd
```

In this example, the node will receive point cloud data from `/camera/depth/points` topic, then convert it to PCD file format, and save it to `/home/user/pointcloud.pcd` file.

It should be noted that when using `rosrun pcl_ros pointcloud_to_pcd` to convert point cloud data, it is necessary to ensure that the input point cloud data has been published to the specified ROS topic. Also, you need to make sure that the `pcl_ros` package is installed, otherwise the command will not work properly.

In addition to using the command-line tool `rosrun`, you can also use the ROS launch file to start the `pointcloud_to_pcd` node. In the launch file, you need to specify input and output parameters, as well as the name of the node and other parameters. For example, the following is an example of using the ROS launch file to start the `pointcloud_to_pcd` node:

```xml
<launch>
  <node name="pointcloud_to_pcd" pkg="pcl_ros" type="pointcloud_to_pcd">
    <remap from="input" to="/camera/depth/points"/>
    <param name="filename" value="/home/user/pointcloud.pcd"/>
  </node>
</launch>
```

In this example, a node called `pointcloud_to_pcd` is first defined, using the `pointcloud_to_pcd` type from the `pcl_ros` package. Then, use the `remap` tag to remap `input` to `/camera/depth/points`, indicating the topic name of the input point cloud data. Finally, use the `param` tag to pass the `filename` parameter

Set to `/home/user/pointcloud.pcd`, indicating the path and name of the output PCD file.

After starting the launch file, the `pointcloud_to_pcd` node will be started automatically, and will receive point cloud data from `/camera/depth/points` topic, then convert it to PCD file format, and save it to `/home/user /pointcloud.pcd` file.

It should be noted that when using the ROS launch file to start the node, you need to ensure that the topic name specified in the launch file is consistent with the actual published topic name. If the topic names do not match, the node will not receive correct input data and the conversion result will be incorrect.

In addition, you need to make sure that the launch file has been saved in the path contained in the ROS environment variable `$ROS_PACKAGE_PATH`, otherwise ROS will not be able to find the launch file.

In short, using `rosrun pcl_ros pointcloud_to_pcd` or the `pointcloud_to_pcd` node in the ROS launch file, you can easily convert the point cloud data in ROS to the PCD file format, and save and post-process it.

Guess you like

Origin blog.csdn.net/weixin_56337147/article/details/130634169