ROS와 Docker에 대한 지식 부족으로 많은 시행 착오를 겪고, 처음 환경 설정부터 데이터 취득까지의 과정을 정리한다.
lsb-release -a 로 확인 가능하다.docker run -it --gpus all --net=host --privileged --shm-size=16G --env DISPLAY=unix$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:ro --env="QT_X11_NO_MITSHM=1" --name test_ros -v $(pwd):/workspace openpcdet-docker:latestsh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'apt install curlcurl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -apt updateapt install ros-noetic-desktop-fullapt install ros-<ROS 버전>-desktop-fullecho "source /opt/ros/noetic/setup.bash" >> ~/.bashrc source ~/.bashrcapt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essentialrosdep init && rosdep updateapt-get install ros-noetic-catkinsource /opt/ros/noetic/setup.bashmkdir -p ./catkin_ws/srccd ./catkin_ws/catkin_makeapt-get install net-toolsifconfig eth0 192.168.0.70sudo route add 192.168.0.201 eth0 apt-get install ros-noetic-velodynecd ../catkin_ws/src/ && git clone https://github.com/ros-drivers/velodyne.gitcd .. && rosdep install --from-paths src --ignore-src --rosdistro noetic -ycatkin_makecd srccatkin_create_pkg vlp16 rospy sensor_msgscd .. && catkin_make. devel/setup.bashroscd vlp16mkdir scripts cd scripts #!/usr/bin/env python3
import rospy
import ros_numpy
import os
import numpy as np
from sensor_msgs.msg import PointCloud2
from time import sleep
class PointCloudSaver:
def __init__(self):
rospy.init_node('point_cloud_saver', anonymous=True)
self.subscriber = rospy.Subscriber('/velodyne_points', PointCloud2, self.point_cloud_callback)
def point_cloud_callback(self, msg):
rospy.loginfo("Received a point cloud message")
pc=ros_numpy.numpify(msg)
points=np.zeros((pc.shape[0],4))
points[:,0]=pc['x']
points[:,1]=pc['y']
points[:,2]=pc['z']
points[:,3]=pc['intensity']
np.save("/workspace/data/000000.npy", points)
if __name__ == '__main__':
try:
point_cloud_saver = PointCloudSaver()
rospy.spin()
except rospy.ROSInterruptException:
pass
pip install rosnumpychmod +x get_data.pycd ../../../catkin_makeroslaunch velodyne_pointcloud VLP16_points.launchrosrun rviz rviz -f velodyne
roslaunch velodyne_pointcloud VLP16_points.launchexport DISPLAY=:0export DISPLAY =<사용 중인 PC IP:0>rosrun rviz rviz -f velodynecd workspace/catkin_ws/source devel/setup.bashrosrun vlp16 get_data.py