Skip to main content
Version: 2.4.6

How to convert pcap into rosbag

Available List of Lidars

  • Velodyne (Veloview)
  • Hesai (Pandarview)

How to Convert

To convert the lidar packet in pcap to rostopic in rosbag, we have to check the ros driver from each lidar company if it supports to play the pcap file from their own viewer, such as Veloview from Velodyne or Pandarview from Hesai.

In this page, I’m going to describe how to convert the pcap file from Velodyne lidar to rosbag.

Activate Libraries

To use lidar drivers, we have to activate libraries.

By running the command below in your terminal, we can use our libraries.

  • if you use bash (default terminal in ubuntu) source setup.bash

  • if you use zsh source setup.zsh

Check Libraries

After running the command, let’s move to the folder share. You can see many drivers are in the folder.

folder name share

Publish topic using pcap (from Velodyne lidar)

(Reference: https://wiki.ros.org/velodyne_pointcloud?distro=melodic)

Launch rosmaster

Before running the lidar driver, we have to turn on the rosmaster by running the command below.

Type roscore at the new terminal.

Select roslaunch file

  • Go back to the first terminal that we ran source setup.bash.

  • Type the command below in your terminal and type tab key two times. Then, you can see some launch files in your terminal

    • You need to type spacebar once after typing velodyne_pointcloud before typing tab button

      $ seoulrobotics@seoulrobotics-MS-7D17:~/seoulrobotics/sensr_ws/install$ roslaunch velodyne_pointcloud 32e_points.launch laserscan_nodelet.launch VLP16_points.launch
      64e_S3.launch transform_nodelet.launch VLP-32C_points.launch

Put Arguments

Check your data and select appropriate launch file. If your pcap file contains packets from VLP-32C, type VLP-32C_points.launch behind the velodyne_pointcloud and push tab button two times. You can see many arguments that we can apply to this launch file. You can also check more information related to arguments in the reference page above.

$ seoulrobotics@seoulrobotics-MS-7D17:~/seoulrobotics/sensr_ws/install$ roslaunch velodyne_pointcloud VLP-32C_points.launch 
calibration laserscan_resolution organize_cloud repeat_delay
cut_angle laserscan_ring pcap rpm
device_ip manager port timestamp_first_packet
frame_id max_range read_fast
gps_time min_range read_once

If you want to publish packets in pcap, and also want to publish once then your command for publishing packtes in pcap is like below.

roslaunch velodyne_pointcloud VLP-32C_points.launch \
pcap:=/media/seoulrobotics/Data/2021-10-15_Unilode/pcap/2021_10_05_13_07_47_Velodyne_VLP_32C_Data_UnilodeMap.pcap \
read_once:=True
note

The one thing you have to check is when you put the value to argument in ros, you have to use add a colon before equal mark. Like := , not =.

Run the Command

After finishing to check all arguments, just type enter.

Check Pointcloud in Rviz

Rviz is a visualizer of ROS. We can check the published pointcloud in Rviz.

Turn on a new terminal, and type rviz in the terminal.

Then, you can see the window like the picture below.

rviz

You can add the pointcloud in rviz by following video below.


As you can see in the video, error is occurred and we can’t see the pointcloud in the area.

In this case, check the frame of lidar and modify the value in fixed frame like the video below.

Convert Pointcloud to Rosbag

After checking the pointcloud in rviz, it’s time to put the pointcloud into rosbag file.

Turn on a new terminal, and change directory where you want to save the rosbag file and type rosbag record.

You can add many options in here too, but it’s enough to know . and -o.

  • If you want to record all topics in the ros, then you can just put . after word record. rosbag record .

  • If you want to record certain topic, then you can put the topic name instead of . rosbag record /velodyne_points

  • And also, you can set the name of rosbag. After typing topic name, adding -o and writing the name what you want. Type this command and pushing return/enter, it will generate the rosbag file in the directory you chose above. rosbag record /velodyne_points -o pointcloud_from_velodyne_pcap

  • If you want to stop the recording, then just enter ctrl+c command in the terminal who is running rosbag record.

After finishing the recording of the topic, you can find the rosbag file in your directory.

example pcap

Conclusion

Currently, this page only handles the pcap from velodyne lidar. If you want to convert the pcap from other lidar, then check each lidar company’s ros driver first.

Logo
If you need access, please contact