0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RPLiDAR使い方

Last updated at Posted at 2022-02-21

RPLiDAR使い方

*推奨OS:ubuntu 18.04.5
*推奨環境:anaconda(自分の環境を作成:conda create -n 仮想環境名)
http://wiki.ros.org/melodic/Installation/Ubuntu
これを上から順に実行(*うまく動かないものがあっても構わず実行)

//Desktop上にworkspaceを作成(例:mkdir catkin_ws)
sudo mkdir catkin_ws
//gitからパクってくる
git clone https://github.com/Slamtec/rplidar_ros.git
//階層を一個上に上がり
cd ..
//catkin_makeコマンドを実行
catkin_make
//よくわからないコマンド実行
source devel/setup.bash
//LiDARを接続しpermissionの設定を行う
sudo chmod 666(or 777) /dev/ttyUSB0

ここまで出来たらターミナルをもう一個立ち上げ

//サーバの起動的なことを行う
roslaunch rplidar_ros view_rplidar.launch

こうすると点群データが可視化できる

//bagファイルに記録するには
rosbag record -a

元々取得できる点群データは,laserPointCloud型ではないためpythonで変換を行う
*以下がそのpythonのコード

main.py
import rospy
from sensor_msgs.msg import PointCloud2 as pc2
from sensor_msgs.msg import LaserScan
from laser_geometry import LaserProjection

class Laser2PC():
    def __init__(self):
        self.laserProj = LaserProjection()
        self.pcPub = rospy.Publisher("/laserPointCloud", pc2, queue_size=1)
        self.laserSub = rospy.Subscriber("/scan", LaserScan, self.laserCallback)

    def laserCallback(self, data):

        cloud_out = self.laserProj.projectLaser(data)

        self.pcPub.publish(cloud_out)

if __name__ == '__main__':
    rospy.init_node("laser2PointCloud")
    l2pc = Laser2PC()
    rospy.spin()
python3 main.py
rostoplic list -v

とコマンドを打つとtopicの内容が見れる
*環境によってlaserPointCloudだったりpointsだったり異なる

rosbag record -a

によって保存・作成されたbagファイルをpcdファイルに変換する

rosrun pcl_ros bag_to_pcd <bagfile> ./<topic> <savedirectory>

これはbagファイルからpcdファイルへの変換を行う
pcdファイルが大量に作成されるため,pcdファイル専用のフォルダの作成をした方がいいかも!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?