Use of YDLIDAR G4 ROS function package

Test environment: Ubuntu 18.04 + ROS Melodic Morenia

1. Install YDLidar SDK

  • Install CMake
 sudo apt install cmake pkg-config
  • Download, compile, install
git clone https://github.com/YDLIDAR/YDLidar-SDK.git
cd YDLidar-SDK/build
cmake ..
make
sudo make install

2. Compile the ydlidar_ros_driver function package

  • create workspace
mkdir -p ~/ydlidar_ws/src
cd ~/ydlidar_ws/src
catkin_init_workspace
  • Download and compile the feature pack
git clone https://github.com/YDLIDAR/ydlidar_ros_driver.git
cd ~/ydlidar_ws
catkin_make
  • set environment variables
source ./devel/setup.sh

(Only valid in the current terminal)
or:

echo "source ~/ydlidar_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

(takes effect in any newly opened terminal)

  • Create a serial port alias (optional)
chmod 0777 src/ydlidar_ros_driver/startup/*
sudo sh src/ydlidar_ros_driver/startup/initenv.sh

Replug the radar USB_data

ls -l /dev/ydlidar 
lrwxrwxrwx 1 root root 7 923 15:19 /dev/ydlidar -> ttyUSB0

It can be seen that the alias ( /dev/ydlidar ) of the lidar has been set successfully.
If you don't want to create an alias, you can modify the port parameter in the lidar.launch file to the original port name of the radar.
before fixing:

<param name="port" type="string" value="/dev/ydlidar"/> 

After modification:

<param name="port" type="string" value="/dev/ttyUSB0"/> 

The original port name needs to be modified according to the actual situation, here is /dev/ttyUSB0.

3. Start the radar and rviz visualization nodes

roslaunch ydlidar_ros_driver lidar_view.launch 

Not surprisingly, you can see the data scanned by the lidar.
The topic for radar data is named /scan.

Guess you like

Origin blog.csdn.net/weixin_43196818/article/details/120431900