Unzip YDLidar-SDK-master.tar.xz in the source code folder to get YDLidar-SDK-master.
Input following command:
mkdir build
cd build
cmake ..
make -j4
sudo make install
Unzip ydlidar in the source folder_ ROS2_ Driver master, obtain ydlidar_ ROS2_ Driver master feature pack.
Copy ydlidar_ ROS2_ Drive master to the src directory of your own workspace
Using the workspace ydlidar_ Ws is an example, rplidar_ Ws is located in the ~ directory.
Then, go back to the workspace directory and compile it,
xxxxxxxxxx
cd ~/ydlidar_ws
colcon build --symlink-install
The above screen indicates that the compilation has passed.
Input following command to set the environment variable.
xxxxxxxxxx
echo "source ~/ydlidar_ws/install/setup.bash --extend" >> ~/.bashrc
Input the following command to bind lidar port name
xxxxxxxxxx
cd /home/yahboom/ydlidar_ws/src/ydlidar_ros2_driver-master/startup
sudo chmod 777 initenv.sh
sudo bash initenv.sh
Then, re-plug the lidar wiring and enter the command ll /dev/rplidar in the terminal.
The above content indicates that the binding is successful. The end is not necessarily 0 and changes according to the order in which the devices are inserted.
Input following command:
xxxxxxxxxx
#x3/x3pro lidar
ros2 launch ydlidar_ros2_driver x3_ydlidar_launch.py
#4ros lidar
ros2 launch ydlidar_ros2_driver 4ros_ydlidar_launch.py
View lidar data with rostopic tool.
xxxxxxxxxx
ros2 topic echo /scan
ctrl+ c closes the terminal that just drove the lidar.
Then enter the following statement in the terminal to drive the lidar, and open rviz to display the point cloud.
x
#x3/x3pro lidar
ros2 launch ydlidar_ros2_driver ydlidar_x3_view_launch.py
#4ros lidar
ros2 launch ydlidar_ros2_driver ydlidar_4ros_view_launch.py